Skip to content

Commit

Permalink
bug: add custom comment notification for record/draft requests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed Dec 11, 2024
1 parent 7e17fad commit 27f4a44
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
19 changes: 18 additions & 1 deletion invenio_rdm_records/notifications/builders.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 CERN.
# Copyright (C) 2023-2024 CERN.
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Notification related utils for notifications."""

from invenio_communities.notifications.builders import (
CommunityCommentNotificationBuilderBase,
)
from invenio_communities.notifications.generators import CommunityMembersRecipient
from invenio_notifications.models import Notification
from invenio_notifications.registry import EntityResolverRegistry
from invenio_notifications.services.builders import NotificationBuilder
from invenio_notifications.services.generators import EntityResolve, UserEmailBackend
from invenio_requests.notifications.filters import UserRecipientFilter
from invenio_requests.notifications.generators import RequestParticipantsRecipient
from invenio_users_resources.notifications.filters import UserPreferencesRecipientFilter
from invenio_users_resources.notifications.generators import (
EmailRecipient,
Expand Down Expand Up @@ -68,6 +72,19 @@ class CommunityInclusionSubmittedNotificationBuilder(
type = "community-submission.submit"


class CommunityInclusionCommentNotificationBuilder(
CommunityCommentNotificationBuilderBase
):
"""Notification builder for draft/record request comment notifications."""

type = f"comment-{CommunityInclusionNotificationBuilder.type}.create"

recipients = [
RequestParticipantsRecipient(key="request"),
CommunityMembersRecipient("request.receiver", roles=["owner", "manager"]),
]


class GuestAccessRequestTokenCreateNotificationBuilder(NotificationBuilder):
"""Notification builder for user access requests."""

Expand Down
7 changes: 4 additions & 3 deletions invenio_rdm_records/requests/community_inclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -109,6 +108,8 @@ class CommunityInclusion(RequestType):
"community_roles": ["owner", "manager", "curator"],
}

comment_notification_builder = CommunityInclusionCommentNotificationBuilder

available_actions = {
"create": actions.CreateAction,
"submit": SubmitAction,
Expand Down
3 changes: 3 additions & 0 deletions invenio_rdm_records/requests/community_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..notifications.builders import (
CommunityInclusionAcceptNotificationBuilder,
CommunityInclusionCancelNotificationBuilder,
CommunityInclusionCommentNotificationBuilder,
CommunityInclusionDeclineNotificationBuilder,
CommunityInclusionExpireNotificationBuilder,
)
Expand Down Expand Up @@ -193,6 +194,8 @@ class CommunitySubmission(ReviewRequest):
"community_roles": ["owner", "manager", "curator"],
}

comment_notification_builder = CommunityInclusionCommentNotificationBuilder

available_actions = {
"create": actions.CreateAction,
"submit": SubmitAction,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 -%}
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
<tr>
<td>{{ _("'@{user_name}' commented on '{request_title}':").format(user_name=event_creator_name, request_title=request_title) }}</td>
</tr>
<tr>
<td><em>{{ request_event_content }}</em></td>
</tr>
<tr>
<td><a href="{{ request_link }}" class="button">{{ _("Check out the 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 -%}
{{ _("@{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 %}

0 comments on commit 27f4a44

Please sign in to comment.