Skip to content

Commit

Permalink
notifications: send notification on critique and resubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
rekt-hard committed Jul 25, 2024
1 parent b34c564 commit f0590eb
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
}
Expand Down
18 changes: 18 additions & 0 deletions invenio_curations/notifications/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,28 @@ 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
):
"""Notification builder for accept action."""

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")]
25 changes: 25 additions & 0 deletions invenio_curations/requests/curation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from invenio_curations.notifications.builders import (
CurationRequestAcceptNotificationBuilder,
CurationRequestCritiqueNotificationBuilder,
CurationRequestResubmitNotificationBuilder,
CurationRequestSubmitNotificationBuilder,
)

Expand Down Expand Up @@ -145,13 +147,36 @@ 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."""

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
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 -%}
{{ _("📝 Curation request critiqued 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}' critiqued 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} 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 %}
Original file line number Diff line number Diff line change
@@ -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 -%}
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
<tr>
<td>{{ _("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 %}
</td>
</tr>
<tr>
{% if message %}
<td><em>{{message}}</em></td>
{% endif %}
</tr>
<tr>
<td><a href="{{request_link}}" class="button">{{ _("Review 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 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 %}

0 comments on commit f0590eb

Please sign in to comment.