6cefa620e4
重新设计权限系统所有 UI 组件的视觉风格,统一配色、圆角、阴影和交互动效: - 实时概览:统计卡片加图标和渐变色条,健康评分改为环形进度,告警改为卡片式 - 趋势分析:图表卡片加彩色图标标识,ECharts 配色升级为渐变面积填充 - 访问日志:指标卡片带图标,日志审计改为卡片式入口,IP排行前三高亮 - IP属地:工具栏重设计,排行列表前三渐变高亮,指标卡片统一新风格 - 系统级权限:从 el-table 改为自定义卡片列表,模块块独立圆角卡片 - 项目权限配置:空状态引导优化,成员表格加头像,工具栏加背景容器 - 角色概览卡片:加进度条可视化,hover 微动效 - 接口权限矩阵:工具栏分离布局,表格圆角包裹 - 角色管理抽屉:侧边栏选中态渐变,操作行 hover 高亮 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
"""项目角色生效管理API"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.deps import get_db_session, require_study_roles
|
|
from app.models.study import Study
|
|
|
|
router = APIRouter(prefix="/active-roles", tags=["active-roles"])
|
|
|
|
|
|
def _normalize_active_roles(value: object) -> list[str]:
|
|
if not isinstance(value, list):
|
|
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="active_roles 必须是数组")
|
|
roles: list[str] = []
|
|
for item in value:
|
|
role = str(item or "").strip()
|
|
if not role:
|
|
continue
|
|
if role == "ADMIN":
|
|
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="ADMIN 不能作为项目角色")
|
|
if len(role) > 20:
|
|
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="项目角色长度不能超过20个字符")
|
|
if role not in roles:
|
|
roles.append(role)
|
|
return roles
|
|
|
|
|
|
@router.get("", summary="获取项目已生效角色列表")
|
|
async def get_active_roles(
|
|
study_id: uuid.UUID,
|
|
_=Depends(require_study_roles(["PM"])),
|
|
db: Annotated[AsyncSession, Depends(get_db_session)] = None,
|
|
) -> dict:
|
|
result = await db.execute(select(Study).where(Study.id == study_id))
|
|
study = result.scalar_one_or_none()
|
|
if not study:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="项目不存在")
|
|
return {"active_roles": study.active_roles or []}
|
|
|
|
|
|
@router.put("", summary="更新项目已生效角色列表")
|
|
async def update_active_roles(
|
|
study_id: uuid.UUID,
|
|
payload: dict,
|
|
_=Depends(require_study_roles(["PM"])),
|
|
db: Annotated[AsyncSession, Depends(get_db_session)] = None,
|
|
) -> dict:
|
|
result = await db.execute(select(Study).where(Study.id == study_id))
|
|
study = result.scalar_one_or_none()
|
|
if not study:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="项目不存在")
|
|
study.active_roles = _normalize_active_roles(payload.get("active_roles", []))
|
|
await db.commit()
|
|
return {"active_roles": study.active_roles}
|