Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notifications: add submission action notifications #1447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions invenio_rdm_records/notifications/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from invenio_notifications.services.generators import EntityResolve, UserEmailBackend
from invenio_requests.notifications.filters import UserRecipientFilter
from invenio_users_resources.notifications.filters import UserPreferencesRecipientFilter
from invenio_users_resources.notifications.generators import UserRecipient


class CommunityInclusionNotificationBuilder(NotificationBuilder):
Expand Down Expand Up @@ -59,3 +60,84 @@ class CommunityInclusionSubmittedNotificationBuilder(
"""Notification builder for record community inclusion submitted."""

type = "community-submission.submit"


class CommunityInclusionActionNotificationBuilder(NotificationBuilder):
"""Notification builder for inclusion actions."""

@classmethod
def build(cls, identity, request):
"""Build notification with request context."""
return Notification(
type=cls.type,
context={
"request": EntityResolverRegistry.reference_entity(request),
"executing_user": EntityResolverRegistry.reference_identity(identity),
},
)

context = [
EntityResolve(key="request"),
EntityResolve(key="request.created_by"),
EntityResolve(key="request.topic"),
EntityResolve(key="request.receiver"),
EntityResolve(key="executing_user"),
]

recipients = [
UserRecipient("request.created_by"),
]

recipient_filters = [
UserPreferencesRecipientFilter(),
UserRecipientFilter("executing_user"),
]

recipient_backends = [
UserEmailBackend(),
]


class CommunityInclusionAcceptNotificationBuilder(
CommunityInclusionActionNotificationBuilder
):
"""Notification builder for inclusion accept action."""

type = f"{CommunityInclusionNotificationBuilder.type}.accept"


class CommunityInclusionCancelNotificationBuilder(
CommunityInclusionActionNotificationBuilder
):
"""Notification builder for inclusion cancel action."""

type = f"{CommunityInclusionNotificationBuilder.type}.cancel"

recipients = [
CommunityMembersRecipient("request.receiver", roles=["curator", "owner"]),
]


class CommunityInclusionDeclineNotificationBuilder(
CommunityInclusionActionNotificationBuilder
):
"""Notification builder for inclusion decline action."""

type = f"{CommunityInclusionNotificationBuilder.type}.decline"


class CommunityInclusionExpireNotificationBuilder(
CommunityInclusionActionNotificationBuilder
):
"""Notification builder for inclusion expire action."""

type = f"{CommunityInclusionNotificationBuilder.type}.expire"

# Executing user will most probably be the system. It is not resolvable on the service level
# as of now and we do not use it in the template.
context = [
EntityResolve(key="request"),
EntityResolve(key="request.created_by"),
EntityResolve(key="request.topic"),
EntityResolve(key="request.receiver"),
]
15 changes: 14 additions & 1 deletion invenio_rdm_records/requests/community_inclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@

from invenio_drafts_resources.services.records.uow import ParentRecordCommitOp
from invenio_i18n import lazy_gettext as _
from invenio_notifications.services.uow import NotificationOp
from invenio_records_resources.services.uow import RecordIndexOp
from invenio_requests.customizations import RequestType, actions
from invenio_requests.errors import CannotExecuteActionError

from invenio_rdm_records.notifications.builders import (
CommunityInclusionAcceptNotificationBuilder,
)
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 @@ -65,7 +72,13 @@ def execute(self, identity, uow):
# not be immediately visible in the community's records, when the `all versions`
# facet is not toggled
uow.register(RecordIndexOp(record, indexer=service.indexer, index_refresh=True))

uow.register(
NotificationOp(
CommunityInclusionAcceptNotificationBuilder.build(
identity=identity, request=self.request
)
)
)
super().execute(identity, uow)


Expand Down
35 changes: 35 additions & 0 deletions invenio_rdm_records/requests/community_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

from invenio_drafts_resources.services.records.uow import ParentRecordCommitOp
from invenio_i18n import lazy_gettext as _
from invenio_notifications.services.uow import NotificationOp
from invenio_requests.customizations import actions

from ..notifications.builders import (
CommunityInclusionAcceptNotificationBuilder,
CommunityInclusionCancelNotificationBuilder,
CommunityInclusionDeclineNotificationBuilder,
CommunityInclusionExpireNotificationBuilder,
)
from ..proxies import current_rdm_records_service as service
from ..services.errors import InvalidAccessRestrictions
from .base import ReviewRequest
Expand Down Expand Up @@ -70,6 +77,13 @@ def execute(self, identity, uow):
# Publish the record
# TODO: Ensure that the accepting user has permissions to publish.
service.publish(identity, draft.pid.pid_value, uow=uow)
uow.register(
NotificationOp(
CommunityInclusionAcceptNotificationBuilder.build(
identity=identity, request=self.request
)
)
)
super().execute(identity, uow)


Expand All @@ -92,6 +106,13 @@ def execute(self, identity, uow):
uow.register(
ParentRecordCommitOp(draft.parent, indexer_context=dict(service=service))
)
uow.register(
NotificationOp(
CommunityInclusionDeclineNotificationBuilder.build(
identity=identity, request=self.request
)
)
)


class CancelAction(actions.CancelAction):
Expand All @@ -107,6 +128,13 @@ def execute(self, identity, uow):
ParentRecordCommitOp(draft.parent, indexer_context=dict(service=service))
)
super().execute(identity, uow)
uow.register(
NotificationOp(
CommunityInclusionCancelNotificationBuilder.build(
identity=identity, request=self.request
)
)
)


class ExpireAction(actions.ExpireAction):
Expand All @@ -128,6 +156,13 @@ def execute(self, identity, uow):
uow.register(
ParentRecordCommitOp(draft.parent, indexer_context=dict(service=service))
)
uow.register(
NotificationOp(
CommunityInclusionExpireNotificationBuilder.build(
identity=identity, request=self.request
)
)
)


#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% set submission_request = notification.context.request %}
{% set community = submission_request.receiver %}
{% set creator = submission_request.created_by %}
{% set record = submission_request.topic %}
{% set request_id = submission_request.id %}
{% set executing_user = notification.context.executing_user %}

{% set community_title = community.metadata.title %}
{% set record_title = record.metadata.title %}
{% set curator_name = executing_user.username %}

{# 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
)
%}

{%- block subject -%}
{{ _("The submission for your record '{record_title}' has been accepted").format(record_title=record_title) }}
{%- endblock subject -%}

{%- block html_body -%}
<p>
{{ _("Community curator '{curator_name}' accepted the record '{record_title}' in the community '{community_title}'.").format(record_title=record_title, community_title=community_title, curator_name=curator_name) }}
</p>

<a href="{{ request_link }}" class="button"> {{ _("Check out the submission request") }}</a>
{%- endblock html_body %}

{%- block plain_body -%}
{{ _("Community curator '{curator_name}' accepted the record '{record_title}' in the community '{community_title}'.").format(record_title=record_title, community_title=community_title, curator_name=curator_name) }}

{{ _("Check out the submission request: {request_link}").format(request_link=request_link) }}

{%- endblock plain_body %}

{# Markdown for Slack/Mattermost/chat #}
{%- block md_body -%}
{{ _("Community curator *{curator_name}* accepted the record *{record_title}* in the community *{community_title}*.").format(record_title=record_title, community_title=community_title, curator_name=curator_name) }}

[{{_("Check out the submission request")}}]({{request_link}})
{%- endblock md_body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% set submission_request = notification.context.request %}
{% set community = submission_request.receiver %}
{% set creator = submission_request.created_by %}
{% set record = submission_request.topic %}
{% set request_id = submission_request.id %}
{% set executing_user = notification.context.executing_user %}

{% set community_title = community.metadata.title %}
{% set record_title = record.metadata.title %}
{% set cancel_name = executing_user.username %}

{# 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
)
%}

{%- block subject -%}
{{ _("Record submission for your community '{community_title}' cancelled by '{cancel_name}'").format(community_title=community_title, cancel_name=cancel_name) }}
{%- endblock subject -%}

{%- block html_body -%}
<p>
{{ _("The record submission for the record '{record_title}' for your community '{community_title}' was cancelled by '{cancel_name}'.").format(record_title=record_title, community_title=community_title, cancel_name=cancel_name) }}
</p>

<a href="{{ request_link }}" class="button"> {{ _("Check out the submission request") }}</a>
{%- endblock html_body -%}

{%- block plain_body -%}
{{ _("The record submission for the record '{record_title}' for your community '{community_title}' was cancelled by '{cancel_name}'.").format(record_title=record_title, community_title=community_title, cancel_name=cancel_name) }}

{{ _("Check out the submission request: {request_link}").format(request_link=request_link) }}
{%- endblock plain_body -%}

{# Markdown for Slack/Mattermost/chat #}
{%- block md_body -%}
{{ _("The record submission for the record '{record_title}' for your community '{community_title}' was cancelled by '{cancel_name}'.").format(record_title=record_title, community_title=community_title, cancel_name=cancel_name) }}

[{{ _("Check out the submission request") }}]({{ request_link }})
{%- endblock md_body -%}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% set submission_request = notification.context.request %}
{% set community = submission_request.receiver %}
{% set creator = submission_request.created_by %}
{% set record = submission_request.topic %}
{% set request_id = submission_request.id %}
{% set executing_user = notification.context.executing_user %}

{% set community_title = community.metadata.title %}
{% set record_title = record.metadata.title %}
{% set curator_name = executing_user.username %}

{# 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
)
%}

{%- block subject -%}
{{ _("The submission for your record '{record_title}' has been declined").format(record_title=record_title) }}
{%- endblock subject -%}

{%- block html_body -%}
<p>
{{ _("Community curator '{curator_name}' declined the record '{record_title}' in the community '{community_title}'.").format(record_title=record_title, community_title=community_title, curator_name=curator_name) }}
</p>

<a href="{{ request_link }}" class="button"> {{ _("Check out the submission request") }}</a>
{%- endblock html_body %}

{%- block plain_body -%}
{{ _("Community curator '{curator_name}' declined the record '{record_title}' in the community '{community_title}'.").format(record_title=record_title, community_title=community_title, curator_name=curator_name) }}

{{ _("Check out the submission request: {request_link}").format(request_link=request_link) }}

{%- endblock plain_body %}

{# Markdown for Slack/Mattermost/chat #}
{%- block md_body -%}
{{ _("Community curator *{curator_name}* declined the record *{record_title}* in the community *{community_title}*.").format(record_title=record_title, community_title=community_title, curator_name=curator_name) }}

[{{_("Check out the submission request")}}]({{request_link}})
{%- endblock md_body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% set submission_request = notification.context.request %}
{% set community = submission_request.receiver %}
{% set creator = submission_request.created_by %}
{% set record = submission_request.topic %}
{% set request_id = submission_request.id %}

{% set community_title = community.metadata.title %}
{% set record_title = record.metadata.title %}

{# 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
)
%}

{%- block subject -%}
{{ _("The submission for your record '{record_title}' has been expired").format(record_title=record_title) }}
{%- endblock subject -%}

{%- block html_body -%}
<p>
{{ _("The record submission for the record '{record_title}' for the community '{community_title}' has expired'.").format(record_title=record_title, community_title=community_title) }}
</p>

<a href="{{ request_link }}" class="button"> {{ _("Check out the submission request") }}</a>
{%- endblock html_body %}

{%- block plain_body -%}
{{ _("The record submission for the record '{record_title}' for the community '{community_title}' has expired'.").format(record_title=record_title, community_title=community_title) }}

{{ _("Check out the submission request: {request_link}").format(request_link=request_link) }}

{%- endblock plain_body %}

{# Markdown for Slack/Mattermost/chat #}
{%- block md_body -%}
{{ _("The record submission for the record '{record_title}' for the community '{community_title}' has expired'.").format(record_title=record_title, community_title=community_title) }}

[{{_("Check out the submission request")}}]({{request_link}})
{%- endblock md_body %}
Loading