Repository: fossasia/open-event-server

Issue:
Add validation for is_event_online
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Add validation for is_event_online
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->

**Stacktrace**
<!-- If applicable, add stacktrace to help explain your problem. -->

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS]
 - Python Version [e.g. `3.5`, `3.6`]
 - `HEAD` Commit hash [e.g. `4629c62`]

**Additional context**
<!-- Add any other context about the problem here. -->
**Wanna work on this issue**


Discussion:

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -121,11 +121,20 @@ def before_post(self, args, kwargs, data=None):
         if data.get('state', None) == 'published' and not is_verified:
             raise ForbiddenException({'source': ''},
                                      "Only verified accounts can publish events")
+
         if not data.get('is_event_online') and 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")
 
+        if data.get('location_name', None) and data.get('is_event_online'):
+            raise ConflictException({'pointer': '/data/attributes/location-name'},
+                                    "Online Event does not have any locaton")
+
+        if data.get('searchable_location_name') and data.get('is_event_online'):
+            raise ConflictException({'pointer': '/data/attributes/searchable-location-name'},
+                                    "Online Event does not have any locaton")
+
     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)
@@ -441,6 +450,19 @@ def before_patch(self, args, kwargs, data=None):
             raise ForbiddenException({'source': ''},
                                      "Only verified accounts can publish events")
 
+        if data.get('state', None) == 'published' and not data.get('location_name', None) and \
+                not data.get('is_event_online'):
+            raise ConflictException({'pointer': '/data/attributes/location-name'},
+                                    "Location is required to publish the event")
+
+        if data.get('location_name') and data.get('is_event_online'):
+            raise ConflictException({'pointer': '/data/attributes/location-name'},
+                                    "Online Event does not have any locaton")
+
+        if data.get('searchable_location_name') and data.get('is_event_online'):
+            raise ConflictException({'pointer': '/data/attributes/searchable-location-name'},
+                                    "Online Event does not have any locaton")
+
     def before_update_object(self, event, data, view_kwargs):
         """
         method to save image urls before updating event object
diff --git a/app/api/schema/events.py b/app/api/schema/events.py
--- a/app/api/schema/events.py
+++ b/app/api/schema/events.py
@@ -68,7 +68,7 @@ def validate_timezone(self, data, original_data):
     starts_at = fields.DateTime(required=True, timezone=True)
     ends_at = fields.DateTime(required=True, timezone=True)
     timezone = fields.Str(required=True)
-    is_event_online = fields.Bool(default=False)
+    is_event_online = fields.Boolean(default=False)
     latitude = fields.Float(validate=lambda n: -90 <= n <= 90, allow_none=True)
     longitude = fields.Float(validate=lambda n: -180 <= n <= 180, allow_none=True)
     logo_url = fields.Url(allow_none=True)
diff --git a/app/models/event.py b/app/models/event.py
--- a/app/models/event.py
+++ b/app/models/event.py
@@ -43,7 +43,7 @@ class Event(SoftDeletionModel):
     starts_at = db.Column(db.DateTime(timezone=True), nullable=False)
     ends_at = db.Column(db.DateTime(timezone=True), nullable=False)
     timezone = db.Column(db.String, nullable=False, default="UTC")
-    is_event_online = db.Column(db.Boolean)
+    is_event_online = db.Column(db.Boolean, default=False)
     latitude = db.Column(db.Float)
     longitude = db.Column(db.Float)
     location_name = db.Column(db.String)


Test patch: