Skip to content

Commit

Permalink
fix preferences check
Browse files Browse the repository at this point in the history
SDBELGA-818
  • Loading branch information
petrjasek committed Jul 31, 2024
1 parent 0158da9 commit 954058e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/planning/assignments/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 954058e

Please sign in to comment.