feat: 工单权限过滤+仪表盘优化+LDAP登录+审批流程+待处理工单
后端: - ticket_statistics/list_tickets 按用户身份过滤(admin全部, dba/auditor审批相关, developer自己的) - 新增 /dashboard/my-tickets 接口(按角色返回待处理工单) - auth.py 本地优先+LDAP fallback 登录认证 - ldap_config.py LDAPS 证书验证修复 - instance_detail.py developer/auditor 权限修复 前端: - Dashboard 仪表盘: 3核心大数字指标+公告+我的待处理工单 - 删除 ECharts 趋势图(无真实数据) - TicketDetailPage 审批流程时间线展示 - TicketsPage 工单统计按用户过滤+关联列(我提交的/待我审批) - types 新增 TicketApproval 等类型定义
This commit is contained in:
1 parent
be2d6f3894
commit
43d1f3a234
10 files changed
+587
-440
No files matched your search
@@ -131,3 +131,94 @@ async def get_trend(
|
||||
items.append(TrendPoint(date=label, **d))
|
||||
|
||||
return TrendData(items=items)
|
||||
|
||||
|
||||
@router.get("/my-tickets")
|
||||
async def my_pending_tickets(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""返回当前用户关联的待处理工单:
|
||||
- admin: 所有 pending/reviewing/executing
|
||||
- dba: 自己需要审批的 + 自己提交的
|
||||
- developer/auditor: 自己提交的
|
||||
"""
|
||||
from app.models.workflow import TicketApproval, WorkflowStep
|
||||
from sqlalchemy import or_
|
||||
import json as _json
|
||||
|
||||
user_id = current_user.id
|
||||
role = current_user.role
|
||||
|
||||
if role == "admin":
|
||||
# admin 看所有待处理
|
||||
rows = (await db.execute(
|
||||
select(Ticket).where(
|
||||
Ticket.status.in_(["pending", "reviewing", "executing"])
|
||||
).order_by(Ticket.create_time.desc()).limit(10)
|
||||
)).scalars().all()
|
||||
else:
|
||||
# 非admin: 找"和我有关"的工单
|
||||
# 1) 我提交的
|
||||
my_submitted = set((await db.execute(
|
||||
select(Ticket.id).where(
|
||||
Ticket.status.in_(["pending", "reviewing", "executing"]),
|
||||
Ticket.applicant_id == user_id,
|
||||
)
|
||||
)).scalars().all())
|
||||
|
||||
# 2) ticket_approvals 中 action=pending 且 approver_id = me
|
||||
my_approvals = set((await db.execute(
|
||||
select(TicketApproval.ticket_id).where(
|
||||
TicketApproval.action == "pending",
|
||||
TicketApproval.approver_id == user_id,
|
||||
)
|
||||
)).scalars().all())
|
||||
|
||||
# 3) 通过角色匹配: approver_role == my role
|
||||
my_role_approvals = set((await db.execute(
|
||||
select(TicketApproval.ticket_id).where(
|
||||
TicketApproval.action == "pending",
|
||||
TicketApproval.approver_role == role,
|
||||
)
|
||||
)).scalars().all())
|
||||
|
||||
all_ids = my_submitted | my_approvals | my_role_approvals
|
||||
if not all_ids:
|
||||
return []
|
||||
rows = (await db.execute(
|
||||
select(Ticket).where(Ticket.id.in_(all_ids)).order_by(Ticket.create_time.desc()).limit(10)
|
||||
)).scalars().all()
|
||||
|
||||
# 用户名映射
|
||||
all_users = (await db.execute(select(User))).scalars().all()
|
||||
user_map = {u.id: u.username for u in all_users}
|
||||
|
||||
result = []
|
||||
for t in rows:
|
||||
pending_approvals = (await db.execute(
|
||||
select(TicketApproval).where(
|
||||
TicketApproval.ticket_id == t.id,
|
||||
TicketApproval.action == "pending",
|
||||
)
|
||||
)).scalars().all()
|
||||
|
||||
pending_info = []
|
||||
for pa in pending_approvals:
|
||||
approver_name = user_map.get(pa.approver_id, "")
|
||||
label = pa.step_name or ""
|
||||
if approver_name:
|
||||
pending_info.append(f"{label}: {approver_name}" if label else approver_name)
|
||||
|
||||
is_mine = t.applicant_id == user_id
|
||||
result.append({
|
||||
"id": t.id,
|
||||
"title": t.title or "",
|
||||
"status": t.status,
|
||||
"db_type": t.db_type or "",
|
||||
"applicant": user_map.get(t.applicant_id, ""),
|
||||
"create_time": t.create_time.strftime("%m-%d %H:%M") if t.create_time else "",
|
||||
"pending_info": ", ".join(filter(None, pending_info)),
|
||||
"relation": "我提交的" if is_mine else "待我审批",
|
||||
})
|
||||
return result
|
||||
Reference in new issue
Block a user