Repository: fossasia/open-event-server

Issue:
User can create events in past dates
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
I can create an event with the duration in the past which should be (obviously) not allowed.

**To Reproduce**
![ezgif com-video-to-gif 7](https://user-images.githubusercontent.com/21087061/53887524-7bc76980-4048-11e9-87d3-99127a603152.gif)

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
It should throw UnprocessableEntry error if event's start-date is set before current date

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu 16.04 LTS
 - Python Version [e.g. `3.5`, `3.6`] 3.5

**Additional context**
<!-- Add any other context about the problem here. -->
Working on it


Discussion:
Low priority. You may work on it but there are higher priority tasks which need to be done 
@iamareebjamal Sure, I would start working on the high priority ones first and maybe finish this one later!
@uds5501 can i try to fix this until then ?

@Haider8  go ahead

Resolving patch:
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
@@ -1,4 +1,5 @@
 import pytz
+from datetime import datetime
 from flask_rest_jsonapi.exceptions import ObjectNotFound
 from marshmallow import validates_schema, validate
 from marshmallow_jsonapi import fields
@@ -44,6 +45,10 @@ def validate_date(self, data, original_data):
             raise UnprocessableEntity({'pointer': '/data/attributes/ends-at'},
                                       "ends-at should be after starts-at")
 
+        if datetime.timestamp(data['starts_at']) <= datetime.timestamp(datetime.now()):
+            raise UnprocessableEntity({'pointer': '/data/attributes/starts-at'},
+                                      "starts-at should be after current date-time")
+
     @validates_schema(pass_original=True)
     def validate_timezone(self, data, original_data):
         if 'id' in original_data['data']:
diff --git a/app/factories/event.py b/app/factories/event.py
--- a/app/factories/event.py
+++ b/app/factories/event.py
@@ -11,8 +11,8 @@ class Meta:
 
     name = common.string_
     external_event_url = common.url_
-    starts_at = common.date_
-    ends_at = common.dateEnd_
+    starts_at = common.dateFuture_
+    ends_at = common.dateEndFuture_
     timezone = common.timezone_
     latitude = common.float_
     longitude = common.float_


Test patch:
diff --git a/tests/all/integration/api/validation/test_events.py b/tests/all/integration/api/validation/test_events.py
--- a/tests/all/integration/api/validation/test_events.py
+++ b/tests/all/integration/api/validation/test_events.py
@@ -25,8 +25,8 @@ def test_date_pass(self):
             'data': {}
         }
         data = {
-            'starts_at': datetime(2003, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
-            'ends_at': datetime(2003, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
+            'starts_at': datetime(2099, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
+            'ends_at': datetime(2099, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
         }
         EventSchema.validate_date(schema, data, original_data)
 
@@ -40,8 +40,8 @@ def test_date_start_gt_end(self):
             'data': {}
         }
         data = {
-            'starts_at': datetime(2003, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
-            'ends_at': datetime(2003, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
+            'starts_at': datetime(2099, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
+            'ends_at': datetime(2099, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
         }
         with self.assertRaises(UnprocessableEntity):
             EventSchema.validate_date(schema, data, original_data)