Repository: fossasia/open-event-server

Issue:
Email Notifications should be automatically set for a user and event when creating a event.
**Is your feature request related to a problem? Please describe.**
Currently email notifications are not automatically set when creating a new event. Hence `/settings/email-preferences` route shows nothing. Like v1 all the notifications should be enabled by-default and user should be able to update them accordingly from frontend using settings route. 

**Describe the solution you'd like**
Enable all the notifications by default as soon as event is created. Set all the relationships so that it is clearly visible in frontend.

**Describe alternatives you've considered**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->
See this Screenshot where it is not showing any event currently despite this user having around 20 created event.

![screenshot from 2018-06-18 01-54-14](https://user-images.githubusercontent.com/21259802/41511768-fb1ff87c-729a-11e8-987c-20cf11347833.png)




Discussion:
@pradeepgangwar can I work on this?

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -138,6 +138,12 @@ def after_create_object(self, event, data, view_kwargs):
         role_invite = RoleInvite(user.email, role.title_name, event.id, role.id, datetime.now(pytz.utc),
                                  status='accepted')
         save_to_db(role_invite, 'Organiser Role Invite Added')
+
+        email_notification = EmailNotification(next_event=True, new_paper=True, session_accept_reject=True,
+                                               session_schedule=True, after_ticket_purchase=True)
+        email_notification.user = user
+        email_notification.event = event
+        save_to_db(email_notification, 'Email Notification of event added to user')
         if event.state == 'published' and event.schedule_published_on:
             start_export_tasks(event)
 
diff --git a/app/api/schema/email_notifications.py b/app/api/schema/email_notifications.py
--- a/app/api/schema/email_notifications.py
+++ b/app/api/schema/email_notifications.py
@@ -21,7 +21,7 @@ class Meta:
         self_view_kwargs = {'id': '<id>'}
         inflect = dasherize
 
-    id = fields.Str(dump_only=True)
+    id = fields.Integer(dump_only=True)
     next_event = fields.Boolean(default=False, allow_none=True)
     new_paper = fields.Boolean(default=False, allow_none=True)
     session_accept_reject = fields.Boolean(default=False, allow_none=True)
diff --git a/app/models/email_notification.py b/app/models/email_notification.py
--- a/app/models/email_notification.py
+++ b/app/models/email_notification.py
@@ -5,8 +5,7 @@
 class EmailNotification(SoftDeletionModel):
     """email notifications model class"""
     __tablename__ = 'email_notifications'
-    id = db.Column(db.Integer,
-                   primary_key=True)
+    id = db.Column(db.Integer, primary_key=True)
     next_event = db.Column(db.Boolean, default=False)
     new_paper = db.Column(db.Boolean, default=False)
     session_accept_reject = db.Column(db.Boolean, default=False)


Test patch: