rtc_backend/apps/admins/permissions.py
2026-01-29 10:02:15 +08:00

47 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
管理员模块权限
"""
from rest_framework.permissions import BasePermission
class IsAdminUser(BasePermission):
"""
验证是否为管理员用户来自AdminUser模型
"""
def has_permission(self, request, view):
from apps.admins.models import AdminUser
return (
request.user and
request.user.is_authenticated and
isinstance(request.user, AdminUser) and
request.user.is_active
)
class IsSuperAdmin(BasePermission):
"""
验证是否为超级管理员
"""
def has_permission(self, request, view):
from apps.admins.models import AdminUser
return (
request.user and
request.user.is_authenticated and
isinstance(request.user, AdminUser) and
request.user.role == 'super_admin'
)
class IsAdminOrOperator(BasePermission):
"""
验证是否为管理员或操作员
"""
def has_permission(self, request, view):
from apps.admins.models import AdminUser
return (
request.user and
request.user.is_authenticated and
isinstance(request.user, AdminUser) and
request.user.role in ['super_admin', 'admin', 'operator']
)