refactor: updates notification toggle function name and if logic
This commit is contained in:
parent
c098ed069a
commit
0f42096e87
2 changed files with 8 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue