Skip to content

Commit

Permalink
avoid extra push notifications when editing desk members (#2513)
Browse files Browse the repository at this point in the history
* avoid extra push notifications when editing desk members

- only updated visible stages for users added/removed from desk
- don't push `resource:updated` notifications when there are no fields updated.

SDANSA-526
  • Loading branch information
petrjasek authored Feb 9, 2024
1 parent 127bd73 commit 9c2957e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions apps/desks.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def __compare_members(self, original, updates):

def __send_notification(self, updates, desk):
desk_id = desk[config.ID_FIELD]
users_service = superdesk.get_resource_service("users")

if "members" in updates:
added, removed = self.__compare_members(desk.get("members", {}), updates["members"])
Expand All @@ -283,7 +284,7 @@ def __send_notification(self, updates, desk):
)

for added_user in added:
user = superdesk.get_resource_service("users").find_one(req=None, _id=added_user)
user = users_service.find_one(req=None, _id=added_user)
activity = add_activity(
ACTIVITY_UPDATE,
"user {{user}} has been added to desk {{desk}}: Please re-login.",
Expand All @@ -294,8 +295,12 @@ def __send_notification(self, updates, desk):
desk=desk.get("name"),
)
push_notification("activity", _dest=activity["recipients"])
users_service.update_stage_visibility_for_user(user)

for removed_user in removed:
user = users_service.find_one(req=None, _id=removed_user)
users_service.update_stage_visibility_for_user(user)

get_resource_service("users").update_stage_visibility_for_users()
else:
push_notification(self.notification_key, updated=1, desk_id=str(desk.get(config.ID_FIELD)))

Expand Down
6 changes: 3 additions & 3 deletions superdesk/eve_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def _change_request(self, endpoint_name, id, updates, original, change_request=F
else:
backend.update(endpoint_name, id, updates, original)
if push_notification:
self._push_resource_notification(
"updated", endpoint_name, _id=str(id), fields=get_diff_keys(updates, original)
)
updated_fields = get_diff_keys(updates, original)
if updated_fields:
self._push_resource_notification("updated", endpoint_name, _id=str(id), fields=updated_fields)
except eve.io.base.DataLayer.OriginalChangedError:
if not backend.find_one(endpoint_name, req=None, _id=id) and search_backend:
# item is in elastic, not in mongo - not good
Expand Down

0 comments on commit 9c2957e

Please sign in to comment.