From 954058e5618448bbf456026214d6d34eec9a1c8a Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Wed, 31 Jul 2024 09:44:04 +0200 Subject: [PATCH] fix preferences check SDBELGA-818 --- server/planning/assignments/assignments.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/planning/assignments/assignments.py b/server/planning/assignments/assignments.py index e3e730b89..f7f5ac655 100644 --- a/server/planning/assignments/assignments.py +++ b/server/planning/assignments/assignments.py @@ -68,6 +68,7 @@ from apps.content import push_content_notification from .assignments_history import ASSIGNMENT_HISTORY_ACTIONS from planning.utils import get_event_formatted_dates, get_formatted_contacts +from superdesk.preferences import get_user_notification_preferences logger = logging.getLogger(__name__) planning_type = deepcopy(superdesk.Resource.rel("planning", type="string")) @@ -345,12 +346,15 @@ def send_assignment_notification(self, updates, original=None, force=False): return assigned_to = updates.get("assigned_to", {}) + assigned_to_user = None + + 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.get("user") and not superdesk.get_resource_service( - "preferences" - ).check_preference_email_notification_is_enabled("assignments", user_id=assigned_to.get("user")): + if assigned_to_user and get_user_notification_preferences(assigned_to_user)["email"] is False: return + assignment_id = updates.get("_id") or assigned_to.get("assignment_id", "Unknown") if not original: original = {} @@ -378,7 +382,6 @@ def send_assignment_notification(self, updates, original=None, force=False): ) if assignee is None and assigned_to.get("user"): - assigned_to_user = get_resource_service("users").find_one(req=None, _id=assigned_to.get("user")) if assigned_to_user and assigned_to_user.get("slack_username"): assignee = "@" + assigned_to_user.get("slack_username") else: