Skip to content

Commit

Permalink
Handle Desktop notifications based on user preferences [SDBELGA-818] (#…
Browse files Browse the repository at this point in the history
…2056)

* handle desktop notifications based on user prefrences

* minor change
  • Loading branch information
devketanpro authored Aug 9, 2024
1 parent 52427fa commit 27b0602
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/planning/planning_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from apps.archive.common import get_user
from eve.utils import config
from planning.common import get_assginment_name
from superdesk.preferences import get_user_notification_preferences

try:
from slackclient import SlackClient
Expand Down Expand Up @@ -64,7 +65,6 @@ def notify_assignment(
# if the coverage is in 'draft' state, no notifications
if coverage_status == WORKFLOW_STATE.DRAFT:
return

# Attempt to load the template file, if that fails, just use the message
try:
(source, filename, uptodate) = app.jinja_loader.get_source(
Expand All @@ -74,10 +74,15 @@ def notify_assignment(
logger.warn("Failed to load the planning notification template {}.txt".format(message))
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"]

if target_desk is None and target_user is not None:
add_activity(
ACTIVITY_UPDATE,
can_push_notification=True,
can_push_notification=can_push_notification,
resource="assignments",
msg=source,
notify=[target_user],
Expand All @@ -98,7 +103,7 @@ def notify_assignment(
continue
add_activity(
ACTIVITY_UPDATE,
can_push_notification=True,
can_push_notification=can_push_notification,
resource="assignments",
msg=source,
notify=[member.get("user")],
Expand Down

0 comments on commit 27b0602

Please sign in to comment.