fix: 修复更新角色权限、更新角色、用户绑定时,用户权限没有即使更新的问题

pull/9499/head
Bai 2023-02-10 11:57:58 +08:00 committed by Jiangjie.Bai
parent 4c96d6935a
commit fcf20335e8
2 changed files with 35 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from django.db import models
from django.db.models import Q
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db.models.signals import post_save
from rest_framework.serializers import ValidationError
from common.db.models import JMSBaseModel, CASCADE_SIGNAL_SKIP
@ -15,6 +16,13 @@ __all__ = ['RoleBinding', 'SystemRoleBinding', 'OrgRoleBinding']
class RoleBindingManager(models.Manager):
def bulk_create(self, objs, batch_size=None, ignore_conflicts=False):
objs = super().bulk_create(objs, batch_size=batch_size, ignore_conflicts=ignore_conflicts)
for i in objs:
post_save.send(i.__class__, instance=i, created=True)
return objs
def get_queryset(self):
queryset = super(RoleBindingManager, self).get_queryset()
q = Q(scope=Scope.system, org__isnull=True)

View File

@ -1,8 +1,8 @@
from django.dispatch import receiver
from django.db.models.signals import post_migrate, post_save
from django.db.models.signals import post_migrate, post_save, m2m_changed, post_delete
from django.apps import apps
from .models import SystemRole, OrgRole
from .models import SystemRole, OrgRole, OrgRoleBinding, SystemRoleBinding
from .builtin import BuiltinRole
@ -21,7 +21,32 @@ def on_system_role_update(sender, instance, created, **kwargs):
User.expire_users_rbac_perms_cache()
@receiver(m2m_changed, sender=SystemRole.permissions.through)
def on_system_role_permission_changed(sender, instance, action, **kwargs):
from users.models import User
User.expire_users_rbac_perms_cache()
@receiver([post_save, post_delete], sender=SystemRoleBinding)
def on_system_role_binding_update(sender, instance, created, **kwargs):
from users.models import User
User.expire_users_rbac_perms_cache()
@receiver(post_save, sender=OrgRole)
def on_org_role_update(sender, instance, created, **kwargs):
from users.models import User
User.expire_users_rbac_perms_cache()
@receiver(m2m_changed, sender=OrgRole.permissions.through)
def on_org_role_permission_changed(sender, instance, action, **kwargs):
from users.models import User
User.expire_users_rbac_perms_cache()
@receiver([post_save, post_delete], sender=OrgRoleBinding)
def on_org_role_binding_update(sender, instance, **kwargs):
print('>>>>>>>>>>>')
from users.models import User
User.expire_users_rbac_perms_cache()