Skip to content

Commit

Permalink
update Assginment mails logic [SDESK-7366] (#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro authored Aug 16, 2024
1 parent 296eadd commit 57aec53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions server/planning/assignments/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
15 changes: 12 additions & 3 deletions server/planning/planning_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 57aec53

Please sign in to comment.