From 0f42096e87fde34497c7802910a709e255c2a5aa Mon Sep 17 00:00:00 2001 From: Parth Kharwar Date: Fri, 5 Mar 2021 13:13:03 +0530 Subject: [PATCH] refactor: updates notification toggle function name and if logic --- frappe/core/doctype/user/user.py | 11 +++++------ .../notification_settings/notification_settings.py | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index 1e3a25678f..23ebe7d6b1 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -8,7 +8,7 @@ from frappe.utils import cint, flt, has_gravatar, escape_html, format_datetime, from frappe import throw, msgprint, _ from frappe.utils.password import update_password as _update_password, check_password from frappe.desk.notifications import clear_notifications -from frappe.desk.doctype.notification_settings.notification_settings import create_notification_settings, enable_disable_notifications +from frappe.desk.doctype.notification_settings.notification_settings import create_notification_settings, toggle_notifications from frappe.utils.user import get_system_managers from bs4 import BeautifulSoup import frappe.permissions @@ -142,16 +142,15 @@ class User(Document): if not cint(self.enabled): self.a_system_manager_should_exist() # disable notifications if the user has been disabled - enable_disable_notifications(self.name, enabled=False) + toggle_notifications(self.name, enable=False) + else: + # enable notifications if the user has been enabled + toggle_notifications(self.name, enable=True) # clear sessions if disabled if not cint(self.enabled) and getattr(frappe.local, "login_manager", None): frappe.local.login_manager.logout(user=self.name) - # enable notifications if the user has been enabled - if cint(self.enabled): - enable_disable_notifications(self.name, enabled=True) - def add_system_manager_role(self): # if adding system manager, do nothing if not cint(self.enabled) or ("System Manager" in [user_role.role for user_role in diff --git a/frappe/desk/doctype/notification_settings/notification_settings.py b/frappe/desk/doctype/notification_settings/notification_settings.py index 0831f4683d..4ab40bffe9 100644 --- a/frappe/desk/doctype/notification_settings/notification_settings.py +++ b/frappe/desk/doctype/notification_settings/notification_settings.py @@ -43,9 +43,10 @@ def create_notification_settings(user): _doc.name = user _doc.insert(ignore_permissions=True) -def enable_disable_notifications(user, enabled): + +def toggle_notifications(user, enable=False): if frappe.db.exists("Notification Settings", user): - frappe.db.set_value("Notification Settings", user, 'enabled', enabled) + frappe.db.set_value("Notification Settings", user, 'enabled', enable) @frappe.whitelist()