feat: 工单列表重设计+权限组实例过滤+通知修复
后端: - Ticket model 新增 ticket_no 字段(格式: YYYYMMDDHHmmss+ms+seq, 如20260522160543841) - create_ticket 自动生成工单编号(flush后生成) - _enrich_ticket 新增 instance_name, current_approver_name 字段 - current_approver: 从 ticket_approvals 查询第一个 pending 状态的审批步骤获取审核人 - TicketResponse schema 新增 ticket_no, instance_name, current_approver_name - 新增 /instances/accessible endpoint(按用户权限组过滤实例, 无admin bypass) - instance_group response_model 改为 InstanceGroupDetailResponse(含readonly/write实例) - instance_group_members 脏数据清理, 重建 group_id=2 正确数据 - notification 模板修复: \n→\n 换行, 钉钉 \n→\n\n 双换行 - test_notification endpoint 改为真正调用 NotificationSender.send() - auditor 角色添加到 audit_rule/ticket 只读端点 - seed_data() 创建4个默认用户(admin/zhangsan/laoliu/lurenjia) - SQLite ALTER TABLE 添加 ticket_no 列, 迁移现有6条工单数据 前端: - TicketsPage 完全重设计: 工单编号/实例名称/提交人/当前审核人/状态/操作 - 状态映射简化: pending/reviewing/approved→审核中, success→完成, failed→失败 - 执行详情弹框: 解析 execute_result JSON 展示状态/影响行数/耗时/验证/原始输出/错误信息 - 状态流程可视化(提交→审批→通过→执行→完成) - 快速筛选: 全部/待审批/执行中/完成/失败 (合并 pending+reviewing+approved 统计) - TicketCreatePage: 去掉数据库类型选择器, 用 accessible(write) 过滤变更实例 - QueriesPage: 用 accessible(readonly) 过滤查询实例 - instance.ts 新增 accessible 方法 - 分页优化: 动态计算页码范围(总页>5时中间滚动)
This commit is contained in:
1 parent
88d064ea95
commit
08f0f88cf1
20 files changed
+1672
-944
No files matched your search
@@ -53,6 +53,49 @@ async def _get_workflow_names(db: AsyncSession, instances: list) -> dict:
|
||||
return {w.id: w.name for w in result.scalars().all()}
|
||||
|
||||
|
||||
@router.get("/accessible", response_model=List[InstanceResponse])
|
||||
async def list_accessible_instances(
|
||||
access_type: str = "readonly",
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""返回当前用户有权访问的实例列表(按权限组的 access_type 过滤)。
|
||||
|
||||
所有用户(包括 admin)统一按权限组关联过滤:
|
||||
user_groups → instance_group_members(access_type) → 返回对应实例
|
||||
access_type: readonly=查询授权, write=变更授权
|
||||
"""
|
||||
from app.models.instance_group import instance_group_members, user_groups as ug_table
|
||||
|
||||
# 查用户关联的所有权限组
|
||||
grp_result = await db.execute(
|
||||
select(ug_table.c.group_id).where(ug_table.c.user_id == current_user.id)
|
||||
)
|
||||
group_ids = [row[0] for row in grp_result.all()]
|
||||
if not group_ids:
|
||||
return []
|
||||
|
||||
# 从 instance_group_members 中获取指定 access_type 的 instance_id
|
||||
mem_result = await db.execute(
|
||||
select(instance_group_members.c.instance_id)
|
||||
.where(
|
||||
instance_group_members.c.group_id.in_(group_ids),
|
||||
instance_group_members.c.access_type == access_type,
|
||||
)
|
||||
.distinct()
|
||||
)
|
||||
instance_ids = [row[0] for row in mem_result.all()]
|
||||
if not instance_ids:
|
||||
return []
|
||||
|
||||
# 查实例详情
|
||||
stmt = select(Instance).where(Instance.id.in_(instance_ids)).order_by(Instance.id)
|
||||
result = await db.execute(stmt)
|
||||
instances = result.scalars().all()
|
||||
wnames = await _get_workflow_names(db, instances)
|
||||
return [_serialize_json_fields(i, wnames.get(i.workflow_id)) for i in instances]
|
||||
|
||||
|
||||
@router.get("", response_model=List[InstanceResponse])
|
||||
async def list_instances(
|
||||
db_type: Optional[str] = None,
|
||||
|
||||
Reference in new issue
Block a user