Repository: fossasia/open-event-server

Issue:
Fix Notifications and automatically mark as read on performing action
- [x] When actions are performed and clicked on notifications, mark notifications automatically as read, e.g. user has clicked on "accept" or "decline" in notifications or email, then mark notification as read.

This is not happening at the moment.
![screenshot from 2016-07-25 07 42 02](https://cloud.githubusercontent.com/assets/1583873/17091538/9628cb82-523b-11e6-86b6-525737a865c5.png)
- [ ] Also change URL of notifications to `/notifications` instead of `profile/notifications`



Discussion:

Resolving patch:
diff --git a/app/helpers/helpers.py b/app/helpers/helpers.py
--- a/app/helpers/helpers.py
+++ b/app/helpers/helpers.py
@@ -322,6 +322,7 @@ def send_notif_event_role(user, role_name, event_name, accept_link, decline_link
 
 
 def send_notif_new_session_organizer(user, event_name, link):
+    print "sending"
     message_settings = MessageSettings.query.filter_by(action=NOTIF_NEW_SESSION).first()
     if not message_settings or message_settings.notif_status == 1:
         notif = NOTIFS[NOTIF_NEW_SESSION]
diff --git a/app/helpers/notification_email_triggers.py b/app/helpers/notification_email_triggers.py
--- a/app/helpers/notification_email_triggers.py
+++ b/app/helpers/notification_email_triggers.py
@@ -6,7 +6,6 @@
 
 
 def trigger_new_session_notifications(session_id, event_id=None, event=None):
-
     if not event and not event_id:
         raise Exception('event or event_id is required')
     if not event:
@@ -16,13 +15,14 @@ def trigger_new_session_notifications(session_id, event_id=None, event=None):
                    event_id=event.id, session_id=session_id, _external=True)
 
     admin_msg_setting = DataGetter.get_message_setting_by_action(NEW_SESSION)
-    organizers = DataGetter.get_user_event_roles_by_role_name(event_id, 'organizer')
+    organizers = DataGetter.get_user_event_roles_by_role_name(event.id, 'organizer')
     for organizer in organizers:
         email_notification_setting = DataGetter.get_email_notification_settings_by_event_id(organizer.user.id, event_id)
         if (email_notification_setting and email_notification_setting.new_paper == 1
                 and admin_msg_setting.user_control_status == 1) or not admin_msg_setting or admin_msg_setting.user_control_status == 0:
             send_new_session_organizer(organizer.user.email, event.name, link)
         # Send notification
+        print " notif Sending"
         send_notif_new_session_organizer(organizer.user, event.name, link)
 
 
@@ -37,7 +37,7 @@ def trigger_session_state_change_notifications(session, event_id, state=None):
                 admin_msg_setting.user_control_status == 1) or not admin_msg_setting or admin_msg_setting.user_control_status == 0:
             send_session_accept_reject(speaker.email, session.title, state, link)
             # Send notification
-            send_notif_session_accept_reject(speaker.user, session.title, state, link)
+        send_notif_session_accept_reject(speaker.user, session.title, state, link)
 
 
 def trigger_session_schedule_change_notifications(session, event_id):
@@ -49,4 +49,4 @@ def trigger_session_schedule_change_notifications(session, event_id):
                 admin_msg_setting.user_control_status == 1) or not admin_msg_setting or admin_msg_setting.user_control_status == 0:
             send_schedule_change(speaker.email, session.title, link)
             # Send notification
-            send_notif_session_schedule(speaker.user, session.title, link)
+        send_notif_session_schedule(speaker.user, session.title, link)
diff --git a/app/views/admin/models_views/profile.py b/app/views/admin/models_views/profile.py
--- a/app/views/admin/models_views/profile.py
+++ b/app/views/admin/models_views/profile.py
@@ -1,4 +1,4 @@
-from flask import request, url_for, redirect, abort, flash
+from flask import request, url_for, redirect, abort, flash, jsonify
 from flask.ext.admin import BaseView
 from flask_admin import expose
 from flask.ext import login
@@ -8,6 +8,7 @@
 from ....helpers.data_getter import DataGetter
 from app.helpers.oauth import FbOAuth, InstagramOAuth
 
+
 class ProfileView(BaseView):
 
     def is_accessible(self):
@@ -58,7 +59,7 @@ def mark_notification_as_read(self, notification_id):
 
         if notification and notification.user == user:
             DataManager.mark_user_notification_as_read(notification)
-            return redirect(url_for('.notifications_view'))
+            return jsonify({'status': 'ok'})
         else:
             abort(404)
 


Test patch: