From b2c229d085fed825be4f71d6aeb19da726be4a5b Mon Sep 17 00:00:00 2001 From: Carlin MacKenzie Date: Mon, 9 Dec 2024 20:14:42 +0100 Subject: [PATCH] wip: add req --- invenio_rdm_records/notifications/builders.py | 9 +++ .../requests/community_inclusion.py | 7 ++- .../requests/community_submission.py | 3 + .../comment-community-submission.create.jinja | 60 +++++++++++++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 invenio_rdm_records/templates/semantic-ui/invenio_notifications/comment-community-submission.create.jinja diff --git a/invenio_rdm_records/notifications/builders.py b/invenio_rdm_records/notifications/builders.py index 1179f5a08..9d400d9c7 100644 --- a/invenio_rdm_records/notifications/builders.py +++ b/invenio_rdm_records/notifications/builders.py @@ -9,6 +9,7 @@ """Notification related utils for notifications.""" from invenio_communities.notifications.generators import CommunityMembersRecipient +from invenio_communities.notifications.builders import CommunityCommentNotificationBuilderBase from invenio_notifications.models import Notification from invenio_notifications.registry import EntityResolverRegistry from invenio_notifications.services.builders import NotificationBuilder @@ -68,6 +69,14 @@ class CommunityInclusionSubmittedNotificationBuilder( type = "community-submission.submit" +class CommunityInclusionCommentNotificationBuilder( + CommunityCommentNotificationBuilderBase +): + """Notification builder for comment request event creation.""" + + type = f"comment-{CommunityInclusionNotificationBuilder.type}.create" + + class GuestAccessRequestTokenCreateNotificationBuilder(NotificationBuilder): """Notification builder for user access requests.""" diff --git a/invenio_rdm_records/requests/community_inclusion.py b/invenio_rdm_records/requests/community_inclusion.py index b9f32adc0..e03e928c4 100644 --- a/invenio_rdm_records/requests/community_inclusion.py +++ b/invenio_rdm_records/requests/community_inclusion.py @@ -14,11 +14,10 @@ from invenio_requests.customizations import RequestType, actions from invenio_requests.errors import CannotExecuteActionError -from invenio_rdm_records.notifications.builders import ( +from ..notifications.builders import ( CommunityInclusionAcceptNotificationBuilder, + CommunityInclusionCommentNotificationBuilder, ) -from invenio_rdm_records.services.errors import InvalidAccessRestrictions - from ..proxies import current_rdm_records_service as service from ..services.errors import InvalidAccessRestrictions @@ -109,6 +108,8 @@ class CommunityInclusion(RequestType): "community_roles": ["owner", "manager", "curator"], } + comment_notification_builder = CommunityInclusionCommentNotificationBuilder + available_actions = { "create": actions.CreateAction, "submit": SubmitAction, diff --git a/invenio_rdm_records/requests/community_submission.py b/invenio_rdm_records/requests/community_submission.py index fb3d1444d..90e4fa24b 100644 --- a/invenio_rdm_records/requests/community_submission.py +++ b/invenio_rdm_records/requests/community_submission.py @@ -18,6 +18,7 @@ CommunityInclusionCancelNotificationBuilder, CommunityInclusionDeclineNotificationBuilder, CommunityInclusionExpireNotificationBuilder, + CommunityInclusionCommentNotificationBuilder, ) from ..proxies import current_rdm_records_service as service from ..services.errors import InvalidAccessRestrictions @@ -193,6 +194,8 @@ class CommunitySubmission(ReviewRequest): "community_roles": ["owner", "manager", "curator"], } + comment_notification_builder = CommunityInclusionCommentNotificationBuilder + available_actions = { "create": actions.CreateAction, "submit": SubmitAction, diff --git a/invenio_rdm_records/templates/semantic-ui/invenio_notifications/comment-community-submission.create.jinja b/invenio_rdm_records/templates/semantic-ui/invenio_notifications/comment-community-submission.create.jinja new file mode 100644 index 000000000..90c14bf03 --- /dev/null +++ b/invenio_rdm_records/templates/semantic-ui/invenio_notifications/comment-community-submission.create.jinja @@ -0,0 +1,60 @@ +{% set invenio_request = notification.context.request %} +{% set invenio_request_event = notification.context.request_event %} + +{# created_by is either a resolved user or an email (for guests) #} +{% set event_creator_name = invenio_request_event.created_by.username or invenio_request_event.created_by %} +{% set request_id = invenio_request.id %} +{% set request_event_content = invenio_request_event.payload.content | safe %} +{% set request_title = invenio_request.title | safe %} + +{# 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 -%} +{{ _("💬 New comment on '{request_title}'").format(request_title=request_title) }} +{%- endblock subject -%} + +{%- block html_body -%} + + + + + + + + + + + + + + + + +
{{ _("'@{user_name}' commented on '{request_title}':").format(user_name=event_creator_name, request_title=request_title) }}
{{ request_event_content }}
{{ _("Check out the request")}}
_
{{ _("This is an auto-generated message. To manage notifications, visit your")}} {{ _("account settings")}}.
+{%- endblock html_body %} + +{%- block plain_body -%} +{{ _("@{user_name} commented on '{request_title}'").format(user_name=event_creator_name, request_title=request_title) }}. + +{{ request_event_content }} + +{{ _("Check out the request: {request_link}").format(request_link=request_link) }} + +{%- endblock plain_body %} + +{# Markdown for Slack/Mattermost/chat #} +{%- block md_body -%} +{{ _("*@{user_name}* commented on *{request_title}*").format(user_name=event_creator_name, request_title=request_title) }}. + +{{ request_event_content }} + +[{{_("Check out the request")}}]({{request_link}}) +{%- endblock md_body %}