mirror of https://github.com/jumpserver/jumpserver
perf: 移动到信号中
parent
87c6eec619
commit
54fd1fb0c8
|
@ -320,6 +320,7 @@ class RoleMixin:
|
|||
_system_roles = None
|
||||
PERM_CACHE_KEY = 'USER_PERMS_{}_{}'
|
||||
_is_superuser = None
|
||||
_update_superuser = False
|
||||
|
||||
@lazyproperty
|
||||
def roles(self):
|
||||
|
@ -367,6 +368,8 @@ class RoleMixin:
|
|||
|
||||
@is_superuser.setter
|
||||
def is_superuser(self, value):
|
||||
self._is_superuser = value
|
||||
self._update_superuser = True
|
||||
if value:
|
||||
self.system_roles.add_role_system_admin()
|
||||
else:
|
||||
|
|
|
@ -60,9 +60,20 @@ def save_passwd_change(sender, instance: User, **kwargs):
|
|||
)
|
||||
|
||||
|
||||
def update_role_superuser_if_need(user):
|
||||
if not user._update_superuser:
|
||||
return
|
||||
value = user._is_superuser
|
||||
if value:
|
||||
user.system_roles.add_role_system_admin()
|
||||
else:
|
||||
user.system_roles.remove_role_system_admin()
|
||||
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
@on_transaction_commit
|
||||
def on_user_create_set_default_system_role(sender, instance, created, **kwargs):
|
||||
update_role_superuser_if_need(instance)
|
||||
if not created:
|
||||
return
|
||||
has_system_role = instance.system_roles.all().exists()
|
||||
|
|
Loading…
Reference in New Issue