fix: Force system admin role only if active
This commit is contained in:
parent
c157564281
commit
792c1451e7
1 changed files with 9 additions and 0 deletions
|
|
@ -163,6 +163,9 @@ class User(Document):
|
|||
toggle_notifications(self.name, enable=cint(self.enabled))
|
||||
|
||||
def add_system_manager_role(self):
|
||||
if self.is_system_manager_disabled():
|
||||
return
|
||||
|
||||
# if adding system manager, do nothing
|
||||
if not cint(self.enabled) or (
|
||||
"System Manager" in [user_role.role for user_role in self.get("roles")]
|
||||
|
|
@ -189,6 +192,9 @@ class User(Document):
|
|||
],
|
||||
)
|
||||
|
||||
def is_system_manager_disabled(self):
|
||||
return frappe.db.get_value("Role", {"name": "System Manager"}, ["disabled"])
|
||||
|
||||
def email_new_password(self, new_password=None):
|
||||
if new_password and not self.flags.in_insert:
|
||||
_update_password(user=self.name, pwd=new_password, logout_all_sessions=self.logout_all_sessions)
|
||||
|
|
@ -372,6 +378,9 @@ class User(Document):
|
|||
)
|
||||
|
||||
def a_system_manager_should_exist(self):
|
||||
if self.is_system_manager_disabled():
|
||||
return
|
||||
|
||||
if not self.get_other_system_managers():
|
||||
throw(_("There should remain at least one System Manager"))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue