权限管理界面重构:角色概览、生效管理与编辑权限整合

【界面优化】
- 移除权限模板列表和角色概览卡片上的"系统预设"标签,视觉上减少噪音
- 将 PermissionTemplateSelector 改为纯展示组件,重命名为"角色权限概览"
- 移除"应用此模板"按钮及预览面板,卡片仅展示各角色权限统计
- 角色描述改为鼠标悬浮 tooltip 显示,节省卡片空间
- 未生效角色以虚线边框 + 降低透明度区分,悬浮提示状态说明

【生效管理】
- Study 模型新增 active_roles JSON 字段,记录项目已生效角色列表
- 新增 /studies/{study_id}/active-roles GET/PUT 接口
- 数据库迁移 20260518_01:studies 表添加 active_roles 列
- 成员管理的项目角色下拉列表仅显示已生效角色,未生效角色不可分配

【模板管理抽屉重构】
- 抽屉改为三标签页:模板列表 / 生效管理 / 编辑权限
- 生效管理:开关控制各角色生效状态,保存后同步后端
- 编辑权限:左右分栏设计,左侧角色列表点击选中,右侧实时展示权限勾选
- 原独立的角色权限编辑抽屉合并至此,角色概览卡片"编辑权限"直接跳转对应标签页

【操作类型标签统一】
- 系统级权限和编辑权限界面的操作类型标签统一使用细分类型
- 操作类型从粗粒度 read/write 细化为 read/create/update/delete/export
- 颜色规范:读取灰色、创建绿色、更新黄色、删除红色、导出无色
- 权限模板管理接口限制为 ADMIN 角色,修复原先权限过宽的问题

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cheng Zhou
2026-05-19 08:48:07 +08:00
parent 20ce6bccef
commit f8a959b801
15 changed files with 1650 additions and 268 deletions
+8 -7
View File
@@ -165,16 +165,17 @@ async def get_study_api_permissions(
"""
permissions = await get_api_endpoint_permissions(db, study_id)
# 构建返回格式
# 构建返回格式get_api_endpoint_permissions 已返回 {role: {key: {"allowed": bool}}}
result: dict[str, dict[str, dict[str, bool]]] = {}
for role in PROJECT_PERMISSION_ROLES:
if role == "ADMIN":
continue
result[role] = {}
for endpoint_key in API_ENDPOINT_PERMISSIONS.keys():
result[role][endpoint_key] = {
"allowed": permissions.get(role, {}).get(endpoint_key, False)
}
perm = permissions.get(role, {}).get(endpoint_key, {"allowed": False})
# perm 已经是 {"allowed": bool},直接使用
allowed = perm["allowed"] if isinstance(perm, dict) else bool(perm)
result[role][endpoint_key] = {"allowed": allowed}
return result
@@ -220,8 +221,8 @@ async def update_study_api_permissions(
continue
result[role] = {}
for endpoint_key in API_ENDPOINT_PERMISSIONS.keys():
result[role][endpoint_key] = {
"allowed": permissions.get(role, {}).get(endpoint_key, False)
}
perm = permissions.get(role, {}).get(endpoint_key, {"allowed": False})
allowed = perm["allowed"] if isinstance(perm, dict) else bool(perm)
result[role][endpoint_key] = {"allowed": allowed}
return result