Skip to content

Commit

Permalink
Merge pull request #247 from M3nin0/dev
Browse files Browse the repository at this point in the history
requests: fix record handling
  • Loading branch information
M3nin0 authored Dec 11, 2024
2 parents 46cae79 + 7ecedea commit c5a97c5
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions geo_rdm_records/modules/requests/community/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def _recipients(self, identity=None, **kwargs):
# remove duplicates
return py_.uniq_by(community_user_emails, "email")

def _build_messages(self, identity=None, notification_type=None, **kwargs):
def _build_messages(
self, identity=None, notification_type=None, is_draft=False, **kwargs
):
"""Message factory.
Args:
Expand All @@ -135,7 +137,6 @@ def _build_messages(self, identity=None, notification_type=None, **kwargs):
Returns:
list: List with messages metadata.
"""
"""Build notification message."""
# ToDo: Inject this configuration using the service configuration.
_ui_url = current_app.config["SITE_UI_URL"]

Expand All @@ -145,7 +146,7 @@ def _build_messages(self, identity=None, notification_type=None, **kwargs):

# define method
read_method_fnc = service.read
if record.is_draft:
if is_draft:
read_method_fnc = service.read_draft

# get information from the record
Expand Down Expand Up @@ -198,11 +199,14 @@ def _build_messages(self, identity=None, notification_type=None, **kwargs):
#
# High-level API
#
def notify(self, identity, uow, notification_type, **kwargs):
def notify(self, identity, uow, notification_type, is_draft=False, **kwargs):
"""Notify users with a given message."""
try:
messages = self._build_messages(
identity, notification_type=notification_type
identity,
notification_type=notification_type,
is_draft=is_draft,
**kwargs,
)
super().notify(identity, messages, uow)
except NoResultFound:
Expand Down Expand Up @@ -239,7 +243,9 @@ def execute(self, identity, uow):
self.request["title"] = draft.metadata["title"]

# Send notification
self.notify(identity, uow, notification_type=self.notification_name)
self.notify(
identity, uow, notification_type=self.notification_name, is_draft=True
)

# execute!
super().execute(identity, uow)
Expand Down Expand Up @@ -291,7 +297,9 @@ def execute(self, identity, uow):
service.publish(identity, draft.pid.pid_value, uow=uow)

# Send notification
self.notify(identity, uow, notification_type=self.notification_name)
self.notify(
identity, uow, notification_type=self.notification_name, is_draft=False
)

super().execute(identity, uow)

Expand Down Expand Up @@ -332,7 +340,9 @@ def execute(self, identity, uow):
uow.register(RecordIndexOp(draft, indexer=service.indexer))

# Send notification
self.notify(identity, uow, notification_type=self.notification_name)
self.notify(
identity, uow, notification_type=self.notification_name, is_draft=True
)


class CancelAction(SubmissionNotificationHandler, actions.CancelAction):
Expand Down Expand Up @@ -364,7 +374,9 @@ def execute(self, identity, uow):
super().execute(identity, uow)

# Send notification
self.notify(identity, uow, notification_type=self.notification_name)
self.notify(
identity, uow, notification_type=self.notification_name, is_draft=True
)


class ExpireAction(SubmissionNotificationHandler, actions.CancelAction):
Expand Down Expand Up @@ -400,4 +412,6 @@ def execute(self, identity, uow):
# update draft to reflect the new status
uow.register(RecordIndexOp(draft, indexer=service.indexer))

self.notify(identity, uow, notification_type=self.notification_name)
self.notify(
identity, uow, notification_type=self.notification_name, is_draft=True
)

0 comments on commit c5a97c5

Please sign in to comment.