diff --git a/geo_rdm_records/modules/requests/community/submission.py b/geo_rdm_records/modules/requests/community/submission.py index d67eec5..1dc0a00 100644 --- a/geo_rdm_records/modules/requests/community/submission.py +++ b/geo_rdm_records/modules/requests/community/submission.py @@ -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: @@ -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"] @@ -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 @@ -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: @@ -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) @@ -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) @@ -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): @@ -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): @@ -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 + )