diff --git a/invenio_communities/notifications/builders.py b/invenio_communities/notifications/builders.py
index 4e5a293f3..0beb82a8b 100644
--- a/invenio_communities/notifications/builders.py
+++ b/invenio_communities/notifications/builders.py
@@ -231,11 +231,6 @@ class SubComInvitationBuilderBase(SubCommunityBuilderBase):
EntityResolve("executing_user"),
]
- recipients = [
- CommunityMembersRecipient("request.created_by", roles=["owner", "manager"]),
- CommunityMembersRecipient("request.receiver", roles=["owner", "manager"]),
- ]
-
class SubComInvitationCreate(SubComInvitationBuilderBase):
"""Notification builder for subcommunity request creation."""
@@ -292,3 +287,47 @@ class SubComInvitationExpire(SubComInvitationBuilderBase):
recipients = [
CommunityMembersRecipient("request.receiver", roles=["owner", "manager"]),
]
+
+
+#
+# Comments
+#
+class SubComCommentNotificationBuilderBase(SubCommunityBuilderBase):
+ """Notification builder for comment request event creation."""
+
+ context = [
+ EntityResolve(key="request"),
+ EntityResolve(key="request.created_by"),
+ EntityResolve(key="request.receiver"),
+ EntityResolve(key="request_event"),
+ EntityResolve(key="request_event.created_by"),
+ ]
+
+ @classmethod
+ def build(cls, request, request_event):
+ """Build notification with request context."""
+ return Notification(
+ type=cls.type,
+ context={
+ "request": EntityResolverRegistry.reference_entity(request),
+ "request_event": EntityResolverRegistry.reference_entity(request_event),
+ },
+ )
+
+ recipient_filters = [
+ # do not send notification to user creating the comment
+ UserRecipientFilter(key="request_event.created_by"),
+ UserPreferencesRecipientFilter(),
+ ]
+
+
+class SubComReqCommentNotificationBuilder(SubComCommentNotificationBuilderBase):
+ """Notification builder for comment request event creation."""
+
+ type = f"comment-{SubCommunityBuilderBase.type}.create"
+
+
+class SubComInvCommentNotificationBuilder(SubComCommentNotificationBuilderBase):
+ """Notification builder for comment request event creation."""
+
+ type = f"comment-{SubComInvitationBuilderBase.type}.create"
diff --git a/invenio_communities/subcommunities/services/request.py b/invenio_communities/subcommunities/services/request.py
index c4ed86bf2..1577ac9b2 100644
--- a/invenio_communities/subcommunities/services/request.py
+++ b/invenio_communities/subcommunities/services/request.py
@@ -15,6 +15,11 @@
import invenio_communities.notifications.builders as notifications
from invenio_communities.proxies import current_communities
+from ...notifications.builders import (
+ SubComInvCommentNotificationBuilder,
+ SubComReqCommentNotificationBuilder,
+)
+
class AcceptSubcommunity(actions.AcceptAction):
"""Represents an accept action used to accept a subcommunity."""
@@ -64,6 +69,8 @@ class SubCommunityRequest(RequestType):
allowed_receiver_ref_types = ["community"]
allowed_topic_ref_types = ["community"]
+ comment_notification_builder = SubComReqCommentNotificationBuilder
+
available_actions = {
"delete": actions.DeleteAction,
"create": actions.CreateAndSubmitAction,
@@ -149,6 +156,8 @@ class SubCommunityInvitationRequest(RequestType):
allowed_receiver_ref_types = ["community"]
allowed_topic_ref_types = ["community"]
+ comment_notification_builder = SubComInvCommentNotificationBuilder
+
available_actions = {
"delete": actions.DeleteAction,
"cancel": actions.CancelAction,
diff --git a/invenio_communities/templates/semantic-ui/invenio_communities/details/new_subcommunity.html b/invenio_communities/templates/semantic-ui/invenio_communities/details/new_subcommunity.html
index ff748404e..3d5afbd27 100644
--- a/invenio_communities/templates/semantic-ui/invenio_communities/details/new_subcommunity.html
+++ b/invenio_communities/templates/semantic-ui/invenio_communities/details/new_subcommunity.html
@@ -9,7 +9,7 @@
{% extends "invenio_communities/details/base.html" %}
-{%- set title = _("New community") -%}
+{%- set title = _("New subcommunity") -%}
{%- block javascript %}
{{ super() }}
diff --git a/invenio_communities/templates/semantic-ui/invenio_notifications/comment-subcommunity-invitation-request.create.jinja b/invenio_communities/templates/semantic-ui/invenio_notifications/comment-subcommunity-invitation-request.create.jinja
new file mode 100644
index 000000000..4a2b75a8e
--- /dev/null
+++ b/invenio_communities/templates/semantic-ui/invenio_notifications/comment-subcommunity-invitation-request.create.jinja
@@ -0,0 +1,62 @@
+{% 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 %}
+{# It would be more natural to send to receiver, but for now we send to parent #}
+{% set parent_community = invenio_request.created_by.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 %}
diff --git a/invenio_communities/templates/semantic-ui/invenio_notifications/comment-subcommunity-request.create.jinja b/invenio_communities/templates/semantic-ui/invenio_notifications/comment-subcommunity-request.create.jinja
new file mode 100644
index 000000000..756968fb0
--- /dev/null
+++ b/invenio_communities/templates/semantic-ui/invenio_notifications/comment-subcommunity-request.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 %}