Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Jul 23, 2024
1 parent d2ef1af commit 127c6f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions apps/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class PreferencesResource(Resource):
)

superdesk.register_default_user_preference(
"mark_for_user:notification",
"email:notification:mark_for_user",
{
"type": "bool",
"enabled": True,
Expand Down Expand Up @@ -412,22 +412,15 @@ def has_missing_privileges(prefs):

doc[_user_preferences_key] = {k: v for k, v in preferences.items() if not has_missing_privileges(v)}

def assignment_notification_is_enabled(self, user_id=None, preferences=None):
def check_preference_email_notification_is_enabled(self, preference_name, user_id=None, preferences=None):
"""
This function checks if email notification is enabled or not based on the preferences.
"""
if user_id:
preferences = self.get_user_preference(user_id)
send_email = preferences.get("assignment:notification", {}) if isinstance(preferences, dict) else {}
return send_email and send_email.get("enabled", False)

def check_notification_is_enabled(self, preference_name, user_id=None, preferences=None):
"""
This function checks if email notification is enabled or not based on the preferences.
This function checks if email notification is enabled or not based on the preference.
"""
send_email = {}
if user_id:
preferences = self.get_user_preference(user_id)
if preference_name:
send_email = preferences.get(f"{preference_name}:notification", {}) if isinstance(preferences, dict) else {}
send_email = (
preferences.get(f"email:notification:{preference_name}", {}) if isinstance(preferences, dict) else {}
)
return send_email and send_email.get("enabled", False)
2 changes: 1 addition & 1 deletion superdesk/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def get_recipients(user_list, activity_name, preference_notification_name=None):
)
and (
preference_notification_name
and get_resource_service("preferences").check_notification_is_enabled(
and get_resource_service("preferences").check_preference_email_notification_is_enabled(
preference_notification_name, preferences=user.get("user_preferences", {})
)
)
Expand Down

0 comments on commit 127c6f1

Please sign in to comment.