Repository: fossasia/open-event-server

Issue:
Event location is not being returned for some events
**Describe the bug**
In the open event android app there are some events which don't have the event location. As discussed with @mariobehling this should not happen.

**To Reproduce**
After opening the app, when we navigate to event details the location is not present for some events.




Discussion:
@dreadpool2 Are you sure it is a bug in the server ? I mean can you show an example where you have created an event with info about it's location and the server doesn't return it ? Preferrably screenshots :)
@srv-twry Like I haven't yet created an event and tested it but isn't it compulsory to specify the location while making an event ? These are some already created events 
![image](https://user-images.githubusercontent.com/28607714/41136690-0135d6c6-6af5-11e8-96de-ce054481a736.png)
![image](https://user-images.githubusercontent.com/28607714/41136697-08acc144-6af5-11e8-95e2-7a9b4fcebdbc.png)

Like we can't publish the event without the location


Yes, we can't publish the events without the location but you can definitely create them. 
You're right, It seems like we aren't actually checking this. It's possible to publish event without location right now.
@srv-twry Yeah. Please do look onto this. Thanks :+1: 

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -12,7 +12,7 @@
 from app.api.bootstrap import api
 from app.api.data_layers.EventCopyLayer import EventCopyLayer
 from app.api.helpers.db import save_to_db, safe_query
-from app.api.helpers.exceptions import ForbiddenException
+from app.api.helpers.exceptions import ForbiddenException, ConflictException
 from app.api.helpers.files import create_save_image_sizes
 from app.api.helpers.permission_manager import has_access
 from app.api.helpers.utilities import dasherize
@@ -104,6 +104,18 @@ def query(self, view_kwargs):
 
         return query_
 
+    def before_post(self, args, kwargs, data=None):
+        """
+        before post method to verify if the event location is provided before publishing the event
+        :param args:
+        :param kwargs:
+        :param data:
+        :return:
+        """
+        if data.get('state', None) == 'published' and not data.get('location_name', None):
+            raise ConflictException({'pointer': '/data/attributes/location-name'},
+                                    "Location is required to publish the event")
+
     def after_create_object(self, event, data, view_kwargs):
         """
         after create method to save roles for users and add the user as an accepted role(organizer)
@@ -385,6 +397,18 @@ def before_get_object(self, view_kwargs):
             else:
                 view_kwargs['id'] = None
 
+    def before_patch(self, args, kwargs, data=None):
+        """
+        before patch method to verify if the event location is provided before publishing the event
+        :param args:
+        :param kwargs:
+        :param data:
+        :return:
+        """
+        if data.get('state', None) == 'published' and not data.get('location_name', None):
+            raise ConflictException({'pointer': '/data/attributes/location-name'},
+                                    "Location is required to publish the event")
+
     def before_update_object(self, event, data, view_kwargs):
         """
         method to save image urls before updating event object


Test patch: