Coverage for portality / events / consumers / update_request_publisher_assigned_notify.py: 95%
42 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
1# ~~UpdateRequestPublisherAssignedNotify:Consumer~~
2from portality.events import consumer_utils
3from portality.events.consumer import EventConsumer
4from portality import constants
5from portality import models
6from portality.bll import DOAJ
7from portality.bll import exceptions
8from portality.lib import dates
9from portality.core import app
10from portality.models import Account
13class UpdateRequestPublisherAssignedNotify(EventConsumer):
14 ID = "update_request:publisher:assigned:notify"
16 @classmethod
17 def should_consume(cls, event):
18 if event.id != constants.EVENT_APPLICATION_ASSED_ASSIGNED:
19 return False
21 if not Account.is_enable_publisher_email():
22 return False
24 app_source = event.context.get("application")
25 if app_source is None:
26 return False
28 if event.context.get("old_editor") not in [None, ""]:
29 return False
31 if event.context.get("new_editor") in [None, ""]:
32 return False
34 application = consumer_utils.parse_application(app_source)
35 is_update_request = application.application_type == constants.APPLICATION_TYPE_UPDATE_REQUEST
36 return is_update_request
38 @classmethod
39 def consume(cls, event):
40 app_source = event.context.get("application")
42 application = consumer_utils.parse_application(app_source)
43 if not application.owner:
44 raise exceptions.NoSuchPropertyException("Application {x} does not have property `owner`".format(x=application.id))
46 # ~~-> Notifications:Service ~~
47 svc = DOAJ.notificationsService()
49 notification = models.Notification()
50 notification.who = application.owner
51 notification.created_by = cls.ID
52 notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN
53 notification.long = svc.long_notification(cls.ID).format(
54 application_title=application.bibjson().title,
55 application_date=dates.human_date(application.date_applied)
56 )
57 notification.short = svc.short_notification(cls.ID).format(
58 issns=application.bibjson().issns_as_text()
59 )
60 # note that there is no action url
62 svc.notify(notification)
63 return notification