Skip to content

Commit eb9b082

Browse files
committed
feat(notifications): send notifications to admins when an event is autocancelled
- add new model for adminnotifications - setup socketio for real time notifications - add query to get all notifications - add mutation to change the status of notification [Delivers CON-71]
1 parent e5de19a commit eb9b082

27 files changed

Lines changed: 242 additions & 118 deletions

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ jobs:
191191
./cc-test-reporter before-build
192192
. venv/bin/activate
193193
coverage combine parallel-coverage/
194-
coverage xml
194+
coverage xml -i
195195
coverage report
196196
./cc-test-reporter format-coverage -o ./.coverage -t coverage.py
197197
./cc-test-reporter upload-coverage -i .coverage

.codeclimate.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ version: "2"
22
exclude_patterns:
33
- "helpers/auth/authentication.py"
44
- "helpers/calendar/events.py"
5-
- "alembic/"
5+
- "alembic/"
6+
- "admin_notifications/__init__.py"
7+
- "admin_notifications/helpers/__init__.py"
8+
- "admin_notifications/helpers/notification_templates.py"

.coveragerc

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
from flask_socketio import send, emit
21
from admin_notifications.models import AdminNotification
3-
from manage import socketio
2+
from api.location.models import Location
3+
from datetime import datetime
44
import celery
55

66

7-
@celery.task(name="create-notification")
7+
def update_notification(notification_id):
8+
notification = AdminNotification.query.filter_by(id=notification_id).first()
9+
notification.date_received = datetime.now()
10+
notification.save()
11+
12+
13+
@celery.task
814
def create_notification(title, message, location_id):
15+
"""
16+
Create notifications in the database and emit them to the client
17+
"""
18+
from manage import socketio
19+
location = Location.query.filter_by(id=location_id).first()
20+
location_name = location.name
921
notification = AdminNotification(
1022
title=title,
1123
message=message,
@@ -14,4 +26,9 @@ def create_notification(title, message, location_id):
1426
)
1527
notification.save()
1628
new_notification = {"title": title, "message": message}
17-
return socketio.emit('notification', {'notification': new_notification}, broadcast=True)
29+
return socketio.emit(
30+
f"notifications-{location_name}",
31+
{'notification': new_notification},
32+
broadcast=True,
33+
callback=update_notification(notification.id)
34+
)

admin_notifications/helpers/device_last_seen.py

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def event_auto_cancelled_notification(event_name, room_name):
2+
return {
3+
"title": "Event Auto cancelled.",
4+
"message": f"An event {event_name} in {room_name} \
5+
has been auto cancelled."
6+
}

admin_notifications/helpers/queue_manager.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

admin_notifications/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ class AdminNotification(Base, Utility):
1515
location_id = Column(
1616
Integer,
1717
ForeignKey('locations.id', ondelete="CASCADE"),
18-
nullable=True)
18+
nullable=True
19+
)

0 commit comments

Comments
 (0)