From d8b3fd3be2fb62e8aae98095ec8d607aec97e66d Mon Sep 17 00:00:00 2001 From: Carlin MacKenzie Date: Mon, 9 Dec 2024 20:13:52 +0100 Subject: [PATCH] wip: add req --- .../members/services/request.py | 5 ++ invenio_communities/notifications/builders.py | 26 +++++--- .../comment-community-invitation.create.jinja | 61 +++++++++++++++++++ 3 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 invenio_communities/templates/semantic-ui/invenio_notifications/comment-community-invitation.create.jinja diff --git a/invenio_communities/members/services/request.py b/invenio_communities/members/services/request.py index 7d193c418..bb808c349 100644 --- a/invenio_communities/members/services/request.py +++ b/invenio_communities/members/services/request.py @@ -19,6 +19,7 @@ CommunityInvitationCancelNotificationBuilder, CommunityInvitationDeclineNotificationBuilder, CommunityInvitationExpireNotificationBuilder, + CommunityInvitationCommentNotificationBuilder, ) from ...proxies import current_communities @@ -117,6 +118,8 @@ class CommunityInvitation(RequestType): "expire": ExpireAction, } + comment_notification_builder = CommunityInvitationCommentNotificationBuilder + creator_can_be_none = False topic_can_be_none = False allowed_creator_ref_types = ["community"] @@ -158,6 +161,8 @@ class MembershipRequestRequestType(RequestType): "cancel": CancelMembershipRequestAction, } + comment_notification_builder = CommunityInvitationCommentNotificationBuilder + creator_can_be_none = False topic_can_be_none = False allowed_creator_ref_types = ["user"] diff --git a/invenio_communities/notifications/builders.py b/invenio_communities/notifications/builders.py index 0beb82a8b..03cefdf94 100644 --- a/invenio_communities/notifications/builders.py +++ b/invenio_communities/notifications/builders.py @@ -40,13 +40,15 @@ class BaseNotificationBuilder(NotificationBuilder): class CommunityInvitationNotificationBuilder(BaseNotificationBuilder): """Base notification builder for community invitation action.""" + type = "community-invitation" + class CommunityInvitationSubmittedNotificationBuilder( CommunityInvitationNotificationBuilder ): """Notification builder for community invitation submit action.""" - type = "community-invitation.submit" + type = f"{CommunityInvitationNotificationBuilder.type}.submit" @classmethod def build(cls, request, role, message=None): @@ -70,7 +72,7 @@ class CommunityInvitationAcceptNotificationBuilder( ): """Notification builder for community invitation accept action.""" - type = "community-invitation.accept" + type = f"{CommunityInvitationNotificationBuilder.type}.accept" @classmethod def build(cls, request): @@ -92,7 +94,7 @@ class CommunityInvitationCancelNotificationBuilder( ): """Notification builder for community invitation cancel action.""" - type = "community-invitation.cancel" + type = f"{CommunityInvitationNotificationBuilder.type}.cancel" @classmethod def build(cls, request): @@ -114,7 +116,7 @@ class CommunityInvitationDeclineNotificationBuilder( ): """Notification builder for community invitation decline action.""" - type = "community-invitation.decline" + type = f"{CommunityInvitationNotificationBuilder.type}.decline" @classmethod def build(cls, request): @@ -136,7 +138,7 @@ class CommunityInvitationExpireNotificationBuilder( ): """Notification builder for community invitation expire action.""" - type = "community-invitation.expire" + type = f"{CommunityInvitationNotificationBuilder.type}.expire" @classmethod def build(cls, request): @@ -292,7 +294,7 @@ class SubComInvitationExpire(SubComInvitationBuilderBase): # # Comments # -class SubComCommentNotificationBuilderBase(SubCommunityBuilderBase): +class CommunityCommentNotificationBuilderBase(SubCommunityBuilderBase): """Notification builder for comment request event creation.""" context = [ @@ -321,13 +323,21 @@ def build(cls, request, request_event): ] -class SubComReqCommentNotificationBuilder(SubComCommentNotificationBuilderBase): +class CommunityInvitationCommentNotificationBuilder( + CommunityCommentNotificationBuilderBase +): + """Notification builder for comment request event creation.""" + + type = f"comment-{CommunityInvitationNotificationBuilder.type}.create" + + +class SubComReqCommentNotificationBuilder(CommunityCommentNotificationBuilderBase): """Notification builder for comment request event creation.""" type = f"comment-{SubCommunityBuilderBase.type}.create" -class SubComInvCommentNotificationBuilder(SubComCommentNotificationBuilderBase): +class SubComInvCommentNotificationBuilder(CommunityCommentNotificationBuilderBase): """Notification builder for comment request event creation.""" type = f"comment-{SubComInvitationBuilderBase.type}.create" diff --git a/invenio_communities/templates/semantic-ui/invenio_notifications/comment-community-invitation.create.jinja b/invenio_communities/templates/semantic-ui/invenio_notifications/comment-community-invitation.create.jinja new file mode 100644 index 000000000..756968fb0 --- /dev/null +++ b/invenio_communities/templates/semantic-ui/invenio_notifications/comment-community-invitation.create.jinja @@ -0,0 +1,61 @@ +{% 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 %} +{% set parent_community = invenio_request.receiver.slug %} + +{# TODO: use request.links.self_html when issue issue is resolved: https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 #} +{% set request_link = "{ui}/communities/{parent_community}/requests/{request_id}".format( + ui=config.SITE_UI_URL, parent_community=parent_community, request_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 %}