Bläddra i källkod

refactor: updates notification toggle function name and if logic

version-14
Parth Kharwar 4 år sedan
förälder
incheckning
0f42096e87
2 ändrade filer med 8 tillägg och 8 borttagningar
  1. +5
    -6
      frappe/core/doctype/user/user.py
  2. +3
    -2
      frappe/desk/doctype/notification_settings/notification_settings.py

+ 5
- 6
frappe/core/doctype/user/user.py Visa fil

@@ -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


+ 3
- 2
frappe/desk/doctype/notification_settings/notification_settings.py Visa fil

@@ -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()


Laddar…
Avbryt
Spara