Skip to content

Commit

Permalink
add maned update request assigned notification
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-jones committed Jan 21, 2025
1 parent 04e708d commit 65adf10
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cms/data/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}).
Expand Down
Original file line number Diff line number Diff line change
@@ -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("[email protected]")
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
2 changes: 2 additions & 0 deletions portality/bll/services/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down Expand Up @@ -54,6 +55,7 @@ class EventsService(object):
ApplicationPublisherQuickRejectNotify,
BGJobFinishedNotify,
JournalDiscontinuingSoonNotify,
UpdateRequestManedEditorGroupAssignedNotify,
UpdateRequestPublisherAcceptedNotify,
UpdateRequestPublisherRejectedNotify,
UpdateRequestPublisherSubmittedNotify
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 65adf10

Please sign in to comment.