From 57aec53a43cf462873d2fefdddb4fbb8e1225446 Mon Sep 17 00:00:00 2001 From: Ketan <73937490+devketanpro@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:33:27 +0530 Subject: [PATCH] update Assginment mails logic [SDESK-7366] (#2063) --- server/planning/assignments/assignments.py | 4 ---- server/planning/planning_notifications.py | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/server/planning/assignments/assignments.py b/server/planning/assignments/assignments.py index 29fff708e..9a8889704 100644 --- a/server/planning/assignments/assignments.py +++ b/server/planning/assignments/assignments.py @@ -351,10 +351,6 @@ def send_assignment_notification(self, updates, original=None, force=False): if assigned_to.get("user"): assigned_to_user = get_resource_service("users").find_one(req=None, _id=assigned_to.get("user")) - # No assignment notification sent, if user is not enabled assignment notification - if assigned_to_user and get_user_notification_preferences(assigned_to_user, "assignments")["email"] is False: - return - assignment_id = updates.get("_id") or assigned_to.get("assignment_id", "Unknown") if not original: original = {} diff --git a/server/planning/planning_notifications.py b/server/planning/planning_notifications.py index f983cf717..5a68d004e 100644 --- a/server/planning/planning_notifications.py +++ b/server/planning/planning_notifications.py @@ -75,9 +75,14 @@ def notify_assignment( return can_push_notification = True - if target_user: - user = superdesk.get_resource_service("users").find_one(req=None, _id=target_user) - can_push_notification = True if user is None else get_user_notification_preferences(user)["desktop"] + + assigned_user = ( + superdesk.get_resource_service("users").find_one(req=None, _id=target_user) if target_user else {} + ) + + can_push_notification = ( + True if assigned_user is None else get_user_notification_preferences(assigned_user)["desktop"] + ) if target_desk is None and target_user is not None: add_activity( @@ -121,6 +126,10 @@ def notify_assignment( } self._notify_slack.apply_async(kwargs=args, serializer="eve/json") + # No assignment notification sent, if user is not enabled assignment notification + if assigned_user and get_user_notification_preferences(assigned_user, "assignments")["email"] is False: + return + # send email notification to user if (target_user or contact_id) and not data.get("no_email", False): args = {