feat: base perm变动时出发get_alld_perms

This commit is contained in:
caoqianming 2024-10-09 13:56:20 +08:00
parent 552055e6c5
commit bc77137093
1 changed files with 15 additions and 3 deletions

View File

@ -24,7 +24,7 @@ from apps.system.filters import DeptFilterSet, UserFilterSet
# from django_q.models import Task as QTask, Schedule as QSchedule
from apps.utils.mixins import (CustomCreateModelMixin, MyLoggingMixin)
from django.conf import settings
from apps.utils.permission import ALL_PERMS, get_user_perms_map
from apps.utils.permission import ALL_PERMS, get_user_perms_map, get_alld_perms
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
from server.celery import app as celery_app
from .models import (Dept, Dictionary, DictType, File, Permission, Post, PostRole, Role, User,
@ -44,6 +44,7 @@ import locale
from drf_yasg.utils import swagger_auto_schema
from server.settings import get_sysconfig, update_sysconfig, update_dict
from apps.utils.constants import DEFAULT_PWD
from apps.utils.thread import MyThread
# logger.info('请求成功! response_code:{}response_headers:{}
# response_body:{}'.format(response_code, response_headers, response_body[:251]))
@ -317,7 +318,18 @@ class PermissionViewSet(CustomModelViewSet):
"""
ALL_PERMS.sort()
return Response(ALL_PERMS)
def perform_create(self, serializer):
super().perform_create(serializer)
MyThread(target=get_alld_perms, args=()).start_p()
def perform_update(self, serializer):
super().perform_update(serializer)
MyThread(target=get_alld_perms, args=()).start_p()
def perform_destroy(self, instance):
super().perform_destroy(instance)
MyThread(target=get_alld_perms, args=()).start_p()
class DeptViewSet(CustomModelViewSet):
"""部门-增删改查
@ -531,7 +543,7 @@ class UserViewSet(CustomModelViewSet):
获取登录用户信息
"""
user = request.user
perms = get_user_perms_map(user)
perms = get_user_perms_map(user, update_cache=True)
data = {
'id': user.id,
'username': user.username,