Skip to content

Commit

Permalink
fix email preferences check after core changes
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 978feca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/features/planning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ Feature: Planning
}
"""
When we get "activity"
Then we get list with 3 items
Then we get list with 4 items
"""
{"_items":[
{
Expand Down
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, "assignments")["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 978feca

Please sign in to comment.