后端:User.is_platform_admin + migration;权限类 IsPlatformAdmin;管理命令建 admin/admin123(幂等); AdminAuditLog 模型 + log_admin_action() helper;me/login 对无团队超管优雅返回 team=null;UserSerializer 暴露标志。 前端:routes/admin 后台外壳(分组侧栏 + 概览 + 占位)、/admin 路由解析与 gating(超管直落、非超管纠回)、 侧栏平台入口、admin-page.css(仅 token)、IconKitSvg 补图标。 测试:accounts 11/11 单测过;无头 e2e _admin-p0.mjs 全断言过 + 0 console error;tsc+build 绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
22 lines
792 B
Python
22 lines
792 B
Python
"""平台级权限类。团队级权限仍走 apps.common.api.can_manage_team(owner/admin)。
|
|
|
|
平台超管(User.is_platform_admin)= 跨团队后台权限,凌驾团队 owner 之上;所有 /api/admin/*
|
|
端点统一挂 IsPlatformAdmin,非超管一律 403。"""
|
|
|
|
from rest_framework.permissions import BasePermission
|
|
|
|
|
|
class IsPlatformAdmin(BasePermission):
|
|
"""仅平台超级管理员放行。被停用账号即便有标志也拒绝。"""
|
|
|
|
message = "需要平台超级管理员权限"
|
|
|
|
def has_permission(self, request, view) -> bool:
|
|
user = getattr(request, "user", None)
|
|
return bool(
|
|
user
|
|
and user.is_authenticated
|
|
and getattr(user, "is_platform_admin", False)
|
|
and not getattr(user, "is_disabled", False)
|
|
)
|