feat: 添加has_perm方法
This commit is contained in:
parent
65c6dab239
commit
e41710e438
|
@ -1,7 +1,7 @@
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from rest_framework.permissions import BasePermission
|
from rest_framework.permissions import BasePermission
|
||||||
from apps.utils.queryset import get_child_queryset2
|
from apps.utils.queryset import get_child_queryset2
|
||||||
from apps.system.models import DataFilter, Dept, Permission, PostRole, UserPost
|
from apps.system.models import DataFilter, Dept, Permission, PostRole, UserPost, User
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
|
||||||
ALL_PERMS = [
|
ALL_PERMS = [
|
||||||
|
@ -41,6 +41,16 @@ def get_user_perms_map(user):
|
||||||
return user_perms_map
|
return user_perms_map
|
||||||
|
|
||||||
|
|
||||||
|
def has_perm(user: User, perm_codes):
|
||||||
|
user_perms_map = cache.get(f'perms_{user.id}', None)
|
||||||
|
if user_perms_map is None:
|
||||||
|
user_perms_map = get_user_perms_map(user)
|
||||||
|
for item in perm_codes:
|
||||||
|
if item in user_perms_map:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class RbacPermission(BasePermission):
|
class RbacPermission(BasePermission):
|
||||||
"""
|
"""
|
||||||
基于角色的权限校验类
|
基于角色的权限校验类
|
||||||
|
|
Loading…
Reference in New Issue