Browse Source

fix: Root 组织用户从用户组移除报错

pull/5791/head
xinwen 4 years ago committed by Jiangjie.Bai
parent
commit
a47a9c0345
  1. 12
      apps/perms/signals_handler/refresh_perms.py

12
apps/perms/signals_handler/refresh_perms.py

@ -3,7 +3,7 @@
from django.db.models.signals import m2m_changed, pre_delete, pre_save, post_save from django.db.models.signals import m2m_changed, pre_delete, pre_save, post_save
from django.dispatch import receiver from django.dispatch import receiver
from users.models import User from users.models import User, UserGroup
from assets.models import Asset from assets.models import Asset
from orgs.utils import current_org, tmp_to_org from orgs.utils import current_org, tmp_to_org
from common.utils import get_logger from common.utils import get_logger
@ -23,16 +23,20 @@ def on_user_groups_change(sender, instance, action, reverse, pk_set, **kwargs):
if reverse: if reverse:
group_ids = [instance.id] group_ids = [instance.id]
user_ids = pk_set user_ids = pk_set
org_id = instance.org_id
else: else:
group_ids = pk_set group_ids = pk_set
user_ids = [instance.id] user_ids = [instance.id]
group = UserGroup.objects.get(id=group_ids[0])
org_id = group.org_id
exists = AssetPermission.user_groups.through.objects.filter(usergroup_id__in=group_ids).exists() exists = AssetPermission.user_groups.through.objects.filter(usergroup_id__in=group_ids).exists()
if not exists: if not exists:
return return
with tmp_to_org(instance.org):
org_ids = [current_org.id] org_ids = [org_id]
UserGrantedTreeRefreshController.add_need_refresh_orgs_for_users(org_ids, user_ids) UserGrantedTreeRefreshController.add_need_refresh_orgs_for_users(org_ids, user_ids)
@receiver([pre_delete], sender=AssetPermission) @receiver([pre_delete], sender=AssetPermission)

Loading…
Cancel
Save