perf: 移动到信号中

This commit is contained in:
ibuler
2022-03-21 18:06:33 +08:00
committed by Jiangjie.Bai
parent 87c6eec619
commit 54fd1fb0c8
2 changed files with 14 additions and 0 deletions

View File

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