From f0590eb905e0cb8af9c1b13a9dff2e7f5bea8f71 Mon Sep 17 00:00:00 2001 From: David Eckhard Date: Wed, 24 Jul 2024 14:21:33 +0200 Subject: [PATCH] notifications: send notification on critique and resubmit --- README.rst | 6 ++ invenio_curations/notifications/builders.py | 18 +++++ invenio_curations/requests/curation.py | 25 ++++++ .../curation-request.critique.jinja | 76 +++++++++++++++++++ .../curation-request.resubmit.jinja | 75 ++++++++++++++++++ 5 files changed, 200 insertions(+) create mode 100644 invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.critique.jinja create mode 100644 invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.resubmit.jinja diff --git a/README.rst b/README.rst index fa23569..94e1885 100644 --- a/README.rst +++ b/README.rst @@ -25,6 +25,8 @@ Invenio-Curations Invenio module for generic and customizable curations. +Requires InvenioRDM v12 or higher + TODO: Please provide feature overview of module Further documentation is available on @@ -49,6 +51,8 @@ Additionally, notification builders have to be configured so that notifications from invenio_curations.notifications.builders import ( CurationRequestAcceptNotificationBuilder, + CurationRequestCritiqueNotificationBuilder, + CurationRequestResubmitNotificationBuilder, CurationRequestSubmitNotificationBuilder, ) from invenio_records_resources.references.entity_resolvers import ServiceResultResolver @@ -59,6 +63,8 @@ Additionally, notification builders have to be configured so that notifications **NOTIFICATIONS_BUILDERS, # Curation request CurationRequestAcceptNotificationBuilder.type: CurationRequestAcceptNotificationBuilder, + CurationRequestCritiqueNotificationBuilder.type: CurationRequestCritiqueNotificationBuilder, + CurationRequestResubmitNotificationBuilder.type: CurationRequestResubmitNotificationBuilder, CurationRequestSubmitNotificationBuilder.type: CurationRequestSubmitNotificationBuilder, } diff --git a/invenio_curations/notifications/builders.py b/invenio_curations/notifications/builders.py index 0d17a16..bd1ab5c 100644 --- a/invenio_curations/notifications/builders.py +++ b/invenio_curations/notifications/builders.py @@ -63,6 +63,15 @@ class CurationRequestSubmitNotificationBuilder( recipients = [GroupMembersRecipient("request.receiver")] +class CurationRequestResubmitNotificationBuilder( + CurationRequestActionNotificationBuilder +): + """Notification builder for resubmit action.""" + + type = f"{CurationRequestActionNotificationBuilder.type}.resubmit" + recipients = [GroupMembersRecipient("request.receiver")] + + class CurationRequestAcceptNotificationBuilder( CurationRequestActionNotificationBuilder ): @@ -70,3 +79,12 @@ class CurationRequestAcceptNotificationBuilder( type = f"{CurationRequestActionNotificationBuilder.type}.accept" recipients = [UserRecipient("request.created_by")] + + +class CurationRequestCritiqueNotificationBuilder( + CurationRequestActionNotificationBuilder +): + """Notification builder for critique action.""" + + type = f"{CurationRequestActionNotificationBuilder.type}.critique" + recipients = [UserRecipient("request.created_by")] diff --git a/invenio_curations/requests/curation.py b/invenio_curations/requests/curation.py index 1b1660f..18027f4 100644 --- a/invenio_curations/requests/curation.py +++ b/invenio_curations/requests/curation.py @@ -15,6 +15,8 @@ from invenio_curations.notifications.builders import ( CurationRequestAcceptNotificationBuilder, + CurationRequestCritiqueNotificationBuilder, + CurationRequestResubmitNotificationBuilder, CurationRequestSubmitNotificationBuilder, ) @@ -145,6 +147,18 @@ class CurationCritiqueAction(actions.RequestAction): status_from = ["review"] status_to = "critiqued" + def execute(self, identity, uow): + """Execute the accept action.""" + uow.register( + NotificationOp( + CurationRequestCritiqueNotificationBuilder.build( + identity=identity, request=self.request + ) + ) + ) + + super().execute(identity, uow) + class CurationResubmitAction(actions.RequestAction): """Mark request as ready for review.""" @@ -152,6 +166,17 @@ class CurationResubmitAction(actions.RequestAction): status_from = ["critiqued", "accepted", "cancelled", "declined"] status_to = "resubmitted" + def execute(self, identity, uow): + """Execute the submit action.""" + uow.register( + NotificationOp( + CurationRequestResubmitNotificationBuilder.build( + identity=identity, request=self.request + ) + ) + ) + super().execute(identity, uow) + # # Request diff --git a/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.critique.jinja b/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.critique.jinja new file mode 100644 index 0000000..3ac090b --- /dev/null +++ b/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.critique.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 -%} + {{ _("📝 Curation request critiqued for '{record_title}'").format(record_title=record_title) }} +{%- endblock subject -%} + +{%- block html_body -%} + + + + + + {% if message %} + + {% endif %} + + + + + + + + + + +
{{ _("The metadata curator '@{curator_name}' critiqued 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} critiqued 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}* critiqued 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 %} diff --git a/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.resubmit.jinja b/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.resubmit.jinja new file mode 100644 index 0000000..741d048 --- /dev/null +++ b/invenio_curations/templates/semantic-ui/invenio_notifications/curation-request.resubmit.jinja @@ -0,0 +1,75 @@ +{% 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 creator_name = creator.username or creator.profile.full_name %} +{% set record_title = record.metadata.title %} +{% set message = notification.context.message | safe if notification.context.message else '' %} + +{# 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 -%} + {{ _("📥 Curation request resubmitted") }} +{%- endblock subject -%} + +{%- block html_body -%} + + + + + + {% if message %} + + {% endif %} + + + + + + + + + + +
{{ _("The record '{record_title}' was resubmitted for curation by '@{creator_name}'").format(record_title=record_title, creator_name=creator_name) }} + {% if message %} + {{ _(" with the following message:")}} + {% endif %} +
{{message}}
{{ _("Review the curation request")}}
_
{{ _("This is an auto-generated message. To manage notifications, visit your")}} {{ _("account settings")}}.
+{%- endblock html_body %} + +{%- block plain_body -%} + {{ _("The record '{record_title}' was resubmitted for curation by @'{creator_name}'.").format(record_title=record_title, creator_name=creator_name) }} + +{% if message %} +{{ _("with the following message:")}} +{{message}} +{% endif %} + +[{{ _("Review 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 record *'{record_title}'* was resubmitted for curation by *@'{creator_name}'*.").format(record_title=record_title, creator_name=creator_name) }} + +{% if message %} +{{ _("with the following message:")}} +{{message}} +{% endif %} + +[{{ _("Review the curation request") }}]({{ request_link }}) + +{{ _("This is an auto-generated message. To manage notifications, visit your account settings")}} +{%- endblock md_body %}