Skip to content

Commit

Permalink
requests: manage sending notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova authored and slint committed Nov 21, 2024
1 parent 6dd6d99 commit 8d2823f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
14 changes: 8 additions & 6 deletions invenio_rdm_records/requests/community_inclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def execute(self, identity, uow):
class AcceptAction(actions.AcceptAction):
"""Accept action."""

def execute(self, identity, uow):
def execute(self, identity, uow, **kwargs):
"""Include record into community."""
# Resolve the topic and community - the request type only allow for
# community receivers and record topics.
Expand Down Expand Up @@ -79,13 +79,15 @@ 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

if kwargs.get("send_notification", True):
uow.register(
NotificationOp(
CommunityInclusionAcceptNotificationBuilder.build(
identity=identity, request=self.request
)
)
)
)
super().execute(identity, uow)


Expand Down
7 changes: 3 additions & 4 deletions invenio_rdm_records/requests/community_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

"""Community submission request."""

from invenio_access.permissions import system_identity
from invenio_drafts_resources.services.records.uow import ParentRecordCommitOp
from invenio_i18n import lazy_gettext as _
from invenio_notifications.services.uow import NotificationOp
Expand Down Expand Up @@ -44,7 +43,7 @@ def execute(self, identity, uow):
class AcceptAction(actions.AcceptAction):
"""Accept action."""

def execute(self, identity, uow):
def execute(self, identity, uow, **kwargs):
"""Accept record into community."""
# Resolve the topic and community - the request type only allow for
# community receivers and record topics.
Expand Down Expand Up @@ -83,15 +82,15 @@ def execute(self, identity, uow):
# TODO: Ensure that the accepting user has permissions to publish.
service.publish(identity, draft.pid.pid_value, uow=uow)

# don't send notification about request auto-accept
if identity != system_identity:
if kwargs.get("send_notification", True):
uow.register(
NotificationOp(
CommunityInclusionAcceptNotificationBuilder.build(
identity=identity, request=self.request
)
)
)

super().execute(identity, uow)


Expand Down
7 changes: 6 additions & 1 deletion invenio_rdm_records/services/community_inclusion/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ def include(self, identity, community, request, uow):

if can_include_directly:
request_item = current_requests_service.execute_action(
system_identity, request.id, "accept", data=None, uow=uow
system_identity,
request.id,
"accept",
data=None,
uow=uow,
send_notification=False,
)

data = {
Expand Down

0 comments on commit 8d2823f

Please sign in to comment.