Skip to content

Commit

Permalink
actions: register notification for the 'review' action
Browse files Browse the repository at this point in the history
  • Loading branch information
max-moser authored and rekt-hard committed Sep 27, 2024
1 parent 3584917 commit 595f733
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
2 changes: 2 additions & 0 deletions invenio_curations/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CurationRequestAcceptNotificationBuilder,
CurationRequestCritiqueNotificationBuilder,
CurationRequestResubmitNotificationBuilder,
CurationRequestReviewNotificationBuilder,
CurationRequestSubmitNotificationBuilder,
)
from invenio_curations.services import facets
Expand Down Expand Up @@ -68,6 +69,7 @@
CurationRequestAcceptNotificationBuilder,
CurationRequestCritiqueNotificationBuilder,
CurationRequestResubmitNotificationBuilder,
CurationRequestReviewNotificationBuilder,
CurationRequestSubmitNotificationBuilder,
]
}
Expand Down
9 changes: 9 additions & 0 deletions invenio_curations/notifications/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
19 changes: 16 additions & 3 deletions invenio_curations/requests/curation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CurationRequestAcceptNotificationBuilder,
CurationRequestCritiqueNotificationBuilder,
CurationRequestResubmitNotificationBuilder,
CurationRequestReviewNotificationBuilder,
CurationRequestSubmitNotificationBuilder,
)

Expand All @@ -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()

Expand Down Expand Up @@ -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."""
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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 -%}
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
<tr>
<td>{{ _("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 %}
</td>
</tr>
<tr>
{% if message %}
<td><em>{{message}}</em></td>
{% endif %}
</tr>
<tr>
<td><a href="{{ request_link }}" class="button">{{ _("Check out the curation request")}}</a></td>
</tr>
<tr>
<td><strong>_</strong></td>
</tr>
<tr>
<td style="font-size:smaller">{{ _("This is an auto-generated message. To manage notifications, visit your")}} <a href="{{account_settings_link}}">{{ _("account settings")}}</a>.</td>
</tr>
</table>
{%- 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 %}

0 comments on commit 595f733

Please sign in to comment.