Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/src/accounts/services/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
send_group_deleted_notification,
send_group_updated_notification,
send_new_task_websocket,
send_removed_task_notification,
send_task_deleted_notification,
)
from src.processes.enums import (
FieldType,
Expand Down Expand Up @@ -118,7 +118,7 @@ def _send_users_notification(
)
recipients_query = list(RawSqlExecutor.fetch(*query.get_sql()))
is_removed_task = (
send_notification_task is send_removed_task_notification
send_notification_task is send_task_deleted_notification
)
notifications = defaultdict(list)
for recipient in recipients_query:
Expand Down Expand Up @@ -151,7 +151,7 @@ def _send_added_users_notifications(self, user_ids: List[int]):
def _send_removed_users_notifications(self, user_ids: List[int]):
self._send_users_notification(
user_ids=user_ids,
send_notification_task=send_removed_task_notification,
send_notification_task=send_task_deleted_notification,
)

def partial_update(
Expand Down
38 changes: 19 additions & 19 deletions backend/src/accounts/tests/services/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from src.authentication.enums import AuthTokenType
from src.notifications.tasks import (
send_new_task_websocket,
send_removed_task_notification,
send_task_deleted_notification,
)
from src.processes.enums import (
DirectlyStatus,
Expand Down Expand Up @@ -1619,19 +1619,19 @@ def test_send_removed_users_notifications__user_not_performer__send(
instance=group,
auth_type=AuthTokenType.USER,
)
send_removed_task_notification_mock = mocker.patch(
send_task_deleted_notification_mock = mocker.patch(
'src.notifications.tasks'
'.send_removed_task_notification.delay',
'.send_task_deleted_notification.delay',
)

# act
service._send_users_notification(
[user_removed.id],
send_removed_task_notification,
send_task_deleted_notification,
)

# assert
send_removed_task_notification_mock.assert_called_once_with(
send_task_deleted_notification_mock.assert_called_once_with(
logging=account.log_api_requests,
task_id=task.id,
recipients=[(user_removed.id, user_removed.email)],
Expand Down Expand Up @@ -1660,19 +1660,19 @@ def test_send_removed_users_notifications__user_in_performer__not_send(
instance=group,
auth_type=AuthTokenType.USER,
)
send_removed_task_notification_mock = mocker.patch(
send_task_deleted_notification_mock = mocker.patch(
'src.notifications.tasks'
'.send_removed_task_notification.delay',
'.send_task_deleted_notification.delay',
)

# act
service._send_users_notification(
[user.id],
send_removed_task_notification,
send_task_deleted_notification,
)

# assert
send_removed_task_notification_mock.assert_not_called()
send_task_deleted_notification_mock.assert_not_called()

def test_send_removed_users_notifications__no_tasks__not_send(
self,
Expand All @@ -1689,19 +1689,19 @@ def test_send_removed_users_notifications__no_tasks__not_send(
instance=group,
auth_type=AuthTokenType.USER,
)
send_removed_task_notification_mock = mocker.patch(
send_task_deleted_notification_mock = mocker.patch(
'src.notifications.tasks.'
'send_removed_task_notification',
'send_task_deleted_notification',
)

# act
service._send_users_notification(
[user.id],
send_removed_task_notification,
send_task_deleted_notification,
)

# assert
send_removed_task_notification_mock.assert_not_called()
send_task_deleted_notification_mock.assert_not_called()

def test_send_removed_users_notifications__single_workflow__send(
self,
Expand Down Expand Up @@ -1741,13 +1741,13 @@ def test_send_removed_users_notifications__single_workflow__send(
)
send_notification_mock = mocker.patch(
'src.notifications.tasks'
'.send_removed_task_notification.delay',
'.send_task_deleted_notification.delay',
)

# act
service._send_users_notification(
[user_to_notify.id],
send_removed_task_notification,
send_task_deleted_notification,
)

# assert
Expand Down Expand Up @@ -1796,13 +1796,13 @@ def test_send_removed_users_notifications__multiple_workflows__send(
)
send_notification_mock = mocker.patch(
'src.notifications.tasks'
'.send_removed_task_notification.delay',
'.send_task_deleted_notification.delay',
)

# act
service._send_users_notification(
[user_to_notify.id],
send_removed_task_notification,
send_task_deleted_notification,
)

# assert
Expand Down Expand Up @@ -1862,13 +1862,13 @@ def test_send_removed_users_notifications__multi_workflows_template__send(
)
send_notification_mock = mocker.patch(
'src.notifications.tasks'
'.send_removed_task_notification.delay',
'.send_task_deleted_notification.delay',
)

# act
service._send_users_notification(
[user_to_notify.id],
send_removed_task_notification,
send_task_deleted_notification,
)

# assert
Expand Down
20 changes: 0 additions & 20 deletions backend/src/notifications/consumers.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
from src.consumers import PneumaticBaseConsumer


class NotificationsConsumer(PneumaticBaseConsumer):

classname = 'notifications'


class NewTaskConsumer(PneumaticBaseConsumer):

classname = 'new_task'


class RemovedTaskConsumer(PneumaticBaseConsumer):

classname = 'removed_task'


class WorkflowEventConsumer(PneumaticBaseConsumer):

classname = 'workflow_event'


class EventsConsumer(PneumaticBaseConsumer):

classname = 'events'
13 changes: 12 additions & 1 deletion backend/src/notifications/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class NotificationMethod:
returned_task = 'returned_task'
removed_task = 'removed_task'
overdue_task = 'overdue_task'
complete_task = 'complete_task'
mention = 'mention'
comment = 'comment'
delay_workflow = 'delay_workflow'
Expand All @@ -30,6 +29,12 @@ class NotificationMethod:
user_created = 'user_created'
user_updated = 'user_updated'
user_deleted = 'user_deleted'
task_completed = 'task_completed'
task_completed_websocket = 'task_completed_websocket'
task_created = 'task_created'
task_deleted = 'task_deleted'
event_created = 'event_created'
event_updated = 'event_updated'

LITERALS = Literal[
new_task,
Expand All @@ -56,6 +61,12 @@ class NotificationMethod:
user_created,
user_updated,
user_deleted,
task_completed,
task_completed_websocket,
task_created,
task_deleted,
event_created,
event_updated,
]


Expand Down
6 changes: 3 additions & 3 deletions backend/src/notifications/services/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PushNotificationService(NotificationService):

ALLOWED_METHODS = {
NotificationMethod.new_task,
NotificationMethod.complete_task,
NotificationMethod.task_completed,
NotificationMethod.returned_task,
NotificationMethod.overdue_task,
NotificationMethod.mention,
Expand Down Expand Up @@ -263,7 +263,7 @@ def send_new_task(
user_email=user_email,
)

def send_complete_task(
def send_task_completed(
self,
task_id: int,
task_name: str,
Expand All @@ -273,7 +273,7 @@ def send_complete_task(
**kwargs,
):
self._send(
method_name=NotificationMethod.complete_task,
method_name=NotificationMethod.task_completed,
title=str(messages.MSG_NF_0012),
body=str(messages.MSG_NF_0011(workflow_name, task_name)),
extra_data={'task_id': str(task_id)},
Expand Down
Loading