From 65adf100fb9de202f0241b5d8f82e64d7137c6c5 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 21 Jan 2025 16:53:10 +0000 Subject: [PATCH] add maned update request assigned notification --- cms/data/notifications.yml | 6 ++ ...uest_maned_editor_group_assigned_notify.py | 79 +++++++++++++++++++ portality/bll/services/events.py | 2 + ...uest_maned_editor_group_assigned_notify.py | 53 +++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 doajtest/unit/event_consumers/test_update_request_maned_editor_group_assigned_notify.py create mode 100644 portality/events/consumers/update_request_maned_editor_group_assigned_notify.py diff --git a/cms/data/notifications.yml b/cms/data/notifications.yml index fecd05611..ca053b356 100644 --- a/cms/data/notifications.yml +++ b/cms/data/notifications.yml @@ -134,6 +134,12 @@ journal:editor_group:assigned:notify: short: New journal ({issns}) assigned to your group +update_request:maned:editor_group_assigned:notify: + long: | + An update request for **{journal_title}** has been assigned to you. Please review it within 1 month. + short: + New update request ({issns}) assigned to you + update_request:publisher:accepted:notify: long: | The changes which you submitted for **{application_title}** on {application_date} have been reviewed and the journal record updated. Please note that some of the changes you suggested may have been edited by our editorial team. Review the journal record here: [{publisher_dashboard_url}]({publisher_dashboard_url}). diff --git a/doajtest/unit/event_consumers/test_update_request_maned_editor_group_assigned_notify.py b/doajtest/unit/event_consumers/test_update_request_maned_editor_group_assigned_notify.py new file mode 100644 index 000000000..1b626a5d8 --- /dev/null +++ b/doajtest/unit/event_consumers/test_update_request_maned_editor_group_assigned_notify.py @@ -0,0 +1,79 @@ +from portality import models +from portality import constants +from portality.bll import exceptions +from doajtest.helpers import DoajTestCase +from portality.events.consumers.update_request_maned_editor_group_assigned_notify import UpdateRequestManedEditorGroupAssignedNotify +from doajtest.fixtures import ApplicationFixtureFactory +import time + + +class TestUpdateRequestManedEditorGroupAssignedNotify(DoajTestCase): + def setUp(self): + super(TestUpdateRequestManedEditorGroupAssignedNotify, self).setUp() + + def tearDown(self): + super(TestUpdateRequestManedEditorGroupAssignedNotify, self).tearDown() + + def test_should_consume(self): + event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application" : {}}) + assert UpdateRequestManedEditorGroupAssignedNotify.should_consume(event) + + event = models.Event("test:event", context={"application" : {}}) + assert not UpdateRequestManedEditorGroupAssignedNotify.should_consume(event) + + event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED) + assert not UpdateRequestManedEditorGroupAssignedNotify.should_consume(event) + + def test_consume_success(self): + with self._make_and_push_test_context_manager("/"): + + source = ApplicationFixtureFactory.make_application_source() + app = models.Application(**source) + app.application_type = constants.APPLICATION_TYPE_UPDATE_REQUEST + + acc = models.Account() + acc.set_id("maned") + acc.set_email("test@example.com") + acc.save() + + eg = models.EditorGroup() + eg.set_name(app.editor_group) + eg.set_maned("maned") + eg.save(blocking=True) + + event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application" : app.data}) + UpdateRequestManedEditorGroupAssignedNotify.consume(event) + + time.sleep(1) + ns = models.Notification.all() + assert len(ns) == 1 + + n = ns[0] + assert n.who == "maned" + assert n.created_by == UpdateRequestManedEditorGroupAssignedNotify.ID + assert n.classification == constants.NOTIFICATION_CLASSIFICATION_ASSIGN + assert n.long is not None + assert n.short is not None + assert n.action is not None + assert not n.is_seen() + + def test_consume_fail(self): + event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application": {"key" : "value"}}) + with self.assertRaises(exceptions.NoSuchObjectException): + UpdateRequestManedEditorGroupAssignedNotify.consume(event) + + source = ApplicationFixtureFactory.make_application_source() + app = models.Application(**source) + app.application_type = constants.APPLICATION_TYPE_NEW_APPLICATION + # app.save(blocking=True) + + eg = models.EditorGroup() + eg.set_name(app.editor_group) + eg.save(blocking=True) + + event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application": app.data}) + UpdateRequestManedEditorGroupAssignedNotify.consume(event) + + time.sleep(1) + ns = models.Notification.all() + assert len(ns) == 0 \ No newline at end of file diff --git a/portality/bll/services/events.py b/portality/bll/services/events.py index e218d2ba9..03ead4919 100644 --- a/portality/bll/services/events.py +++ b/portality/bll/services/events.py @@ -25,6 +25,7 @@ from portality.events.consumers.update_request_publisher_rejected_notify import UpdateRequestPublisherRejectedNotify from portality.events.consumers.journal_discontinuing_soon_notify import JournalDiscontinuingSoonNotify from portality.events.consumers.application_editor_acceptreject_notify import ApplicationEditorAcceptRejectNotify +from portality.events.consumers.update_request_maned_editor_group_assigned_notify import UpdateRequestManedEditorGroupAssignedNotify @@ -54,6 +55,7 @@ class EventsService(object): ApplicationPublisherQuickRejectNotify, BGJobFinishedNotify, JournalDiscontinuingSoonNotify, + UpdateRequestManedEditorGroupAssignedNotify, UpdateRequestPublisherAcceptedNotify, UpdateRequestPublisherRejectedNotify, UpdateRequestPublisherSubmittedNotify diff --git a/portality/events/consumers/update_request_maned_editor_group_assigned_notify.py b/portality/events/consumers/update_request_maned_editor_group_assigned_notify.py new file mode 100644 index 000000000..9a3e29b53 --- /dev/null +++ b/portality/events/consumers/update_request_maned_editor_group_assigned_notify.py @@ -0,0 +1,53 @@ +# ~~ ApplicatioditorGroupAssignedNotify:Consumer~~ +from portality.events import consumer_utils +from portality.util import url_for +from portality.events.consumer import EventConsumer +from portality import constants +from portality import models +from portality.bll import DOAJ +from portality.bll import exceptions + + +class UpdateRequestManedEditorGroupAssignedNotify(EventConsumer): + ID = "update_request:maned:editor_group_assigned:notify" + + @classmethod + def should_consume(cls, event): + return event.id == constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED and \ + event.context.get("application") is not None + + @classmethod + def consume(cls, event): + app_source = event.context.get("application") + + application = consumer_utils.parse_application(app_source) + + if application.application_type != constants.APPLICATION_TYPE_UPDATE_REQUEST: + return + + if not application.editor_group: + return + + editor_group = models.EditorGroup.pull_by_key("name", application.editor_group) + + if not editor_group.maned: + raise exceptions.NoSuchPropertyException("Editor Group {x} does not have property `maned`".format(x=editor_group.id)) + + # ~~-> Notifications:Service ~~ + svc = DOAJ.notificationsService() + + notification = models.Notification() + notification.who = editor_group.maned + notification.created_by = cls.ID + notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN + + notification.long = svc.long_notification(cls.ID).format( + journal_title=application.bibjson().title + ) + notification.short = svc.short_notification(cls.ID).format( + issns=application.bibjson().issns_as_text() + ) + + notification.action = url_for("editor.application", application_id=application.id) + + svc.notify(notification)