From 595f7337ee06a1a61ed938ca72f002e18023d0cf Mon Sep 17 00:00:00 2001 From: Maximilian Moser Date: Fri, 27 Sep 2024 11:19:15 +0200 Subject: [PATCH] actions: register notification for the 'review' action --- invenio_curations/config.py | 2 + invenio_curations/notifications/builders.py | 9 +++ invenio_curations/requests/curation.py | 19 ++++- .../curation-request.review.jinja | 76 +++++++++++++++++++ 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.review.jinja diff --git a/invenio_curations/config.py b/invenio_curations/config.py index cd83e80..52a55b3 100644 --- a/invenio_curations/config.py +++ b/invenio_curations/config.py @@ -11,6 +11,7 @@ CurationRequestAcceptNotificationBuilder, CurationRequestCritiqueNotificationBuilder, CurationRequestResubmitNotificationBuilder, + CurationRequestReviewNotificationBuilder, CurationRequestSubmitNotificationBuilder, ) from invenio_curations.services import facets @@ -68,6 +69,7 @@ CurationRequestAcceptNotificationBuilder, CurationRequestCritiqueNotificationBuilder, CurationRequestResubmitNotificationBuilder, + CurationRequestReviewNotificationBuilder, CurationRequestSubmitNotificationBuilder, ] } diff --git a/invenio_curations/notifications/builders.py b/invenio_curations/notifications/builders.py index bd1ab5c..91ae45f 100644 --- a/invenio_curations/notifications/builders.py +++ b/invenio_curations/notifications/builders.py @@ -72,6 +72,15 @@ class CurationRequestResubmitNotificationBuilder( recipients = [GroupMembersRecipient("request.receiver")] +class CurationRequestReviewNotificationBuilder( + CurationRequestActionNotificationBuilder +): + """Notification builder for review action.""" + + type = f"{CurationRequestActionNotificationBuilder.type}.review" + recipients = [UserRecipient("request.created_by")] + + class CurationRequestAcceptNotificationBuilder( CurationRequestActionNotificationBuilder ): diff --git a/invenio_curations/requests/curation.py b/invenio_curations/requests/curation.py index c673f07..fcc35dd 100644 --- a/invenio_curations/requests/curation.py +++ b/invenio_curations/requests/curation.py @@ -18,6 +18,7 @@ CurationRequestAcceptNotificationBuilder, CurationRequestCritiqueNotificationBuilder, CurationRequestResubmitNotificationBuilder, + CurationRequestReviewNotificationBuilder, CurationRequestSubmitNotificationBuilder, ) @@ -28,7 +29,7 @@ class CurationCreateAndSubmitAction(actions.CreateAndSubmitAction): """Create and submit a request.""" def execute(self, identity, uow): - """Execute the create action.""" + """Execute the create & submit action.""" receiver = self.request.receiver.resolve() record = self.request.topic.resolve() @@ -168,6 +169,18 @@ class CurationReviewAction(actions.RequestAction): status_from = ["submitted", "resubmitted"] status_to = "review" + def execute(self, identity, uow): + """Execute the review action.""" + uow.register( + NotificationOp( + CurationRequestReviewNotificationBuilder.build( + identity=identity, request=self.request + ) + ) + ) + + super().execute(identity, uow) + class CurationCritiqueAction(actions.RequestAction): """Request changes for request.""" @@ -176,7 +189,7 @@ class CurationCritiqueAction(actions.RequestAction): status_to = "critiqued" def execute(self, identity, uow): - """Execute the accept action.""" + """Execute the critique action.""" uow.register( NotificationOp( CurationRequestCritiqueNotificationBuilder.build( @@ -195,7 +208,7 @@ class CurationResubmitAction(actions.RequestAction): status_to = "resubmitted" def execute(self, identity, uow): - """Execute the submit action.""" + """Execute the resubmit action.""" uow.register( NotificationOp( CurationRequestResubmitNotificationBuilder.build( diff --git a/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.review.jinja b/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.review.jinja new file mode 100644 index 0000000..f37d713 --- /dev/null +++ b/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.review.jinja @@ -0,0 +1,76 @@ +{% set curation_request = notification.context.request %} +{% set group = curation_request.receiver %} +{% set creator = curation_request.created_by %} +{% set record = curation_request.topic %} +{% set request_id = curation_request.id %} +{% set executing_user = notification.context.executing_user %} +{% set message = notification.context.message | safe if notification.context.message else '' %} +{% set record_title = record.metadata.title %} +{% set curator_name = executing_user.username or executing_user.profile.full_name %} + +{# TODO: use request.links.self_html when issue issue is resolved: https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 #} +{% set request_link = "{ui}/me/requests/{id}".format( + ui=config.SITE_UI_URL, id=request_id + ) +%} +{% set account_settings_link = "{ui}/account/settings/notifications".format( + ui=config.SITE_UI_URL + ) +%} + +{%- block subject -%} + {{ _("👁️ Review started for '{record_title}'").format(record_title=record_title) }} +{%- endblock subject -%} + +{%- block html_body -%} + + + + + + {% if message %} + + {% endif %} + + + + + + + + + + +
{{ _("The metadata curator '@{curator_name}' started reviewing the record '{record_title}'").format(curator_name=curator_name, record_title=record_title) }} + {% if message %} + {{ _(" with the following message:")}} + {% endif %} +
{{message}}
{{ _("Check out the curation request")}}
_
{{ _("This is an auto-generated message. To manage notifications, visit your")}} {{ _("account settings")}}.
+{%- endblock html_body %} + +{%- block plain_body -%} +{{ _("The metadata curator @{curator_name} started reviewing the record '{record_title}'").format(curator_name=curator_name, record_title=record_title) }} + +{% if message %} +{{ _("with the following message:")}} +{{message}} +{% endif %} + +[{{ _("Check out the curation request") }}]({{ request_link }}) + +{{ _("This is an auto-generated message. To manage notifications, visit your account settings")}} +{%- endblock plain_body %} + +{# Markdown for Slack/Mattermost/chat #} +{%- block md_body -%} +{{ _("The metadata curator *@{curator_name}* started reviewing the record *{record_title}*").format(curator_name=curator_name, record_title=record_title) }} + +{% if message %} +{{ _("with the following message:")}} +{{message}} +{% endif %} + +[{{ _("Check out the curation request") }}]({{ request_link }}) + +{{ _("This is an auto-generated message. To manage notifications, visit your account settings")}} +{%- endblock md_body %}