feat: add rule draft permission flow

This commit is contained in:
wren
2026-05-06 20:06:41 +08:00
parent 0b76dce2a5
commit f9de903acc
8 changed files with 412 additions and 14 deletions
@@ -11,6 +11,7 @@ from fastapi_modules.fastapi_leaudit.domian.Dto.evaluationPointGroupDto import (
EvaluationPointGroupBindingCreateDTO,
EvaluationPointGroupBindingUpdateDTO,
EvaluationPointGroupCreateDTO,
EvaluationPointGroupRuleDraftCreateDTO,
EvaluationPointGroupRebindDTO,
EvaluationPointGroupUpdateDTO,
)
@@ -160,6 +161,25 @@ class EvaluationPointGroupController(BaseController):
await self.GroupService.DeleteBinding(BindingId)
return JSONResponse(status_code=200, content={"success": True})
@self.router.get("/{GroupId}/rule-template")
async def GetEvaluationPointGroupRuleTemplate(GroupId: int, payload: dict = Depends(verify_access_token)):
if not await self._check_permission(int(payload["user_id"]), ["evaluation_group:list:read", "rules:list:read"]):
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有查看规则模板权限", "data": None})
data = await self.GroupService.GetRuleTemplate(GroupId)
return JSONResponse(status_code=200, content=data.model_dump())
@self.router.post("/{GroupId}/rule-drafts")
async def CreateEvaluationPointGroupRuleDraft(
GroupId: int,
body: EvaluationPointGroupRuleDraftCreateDTO,
payload: dict = Depends(verify_access_token),
):
if not await self._check_permission(int(payload["user_id"]), ["evaluation_group:update:write", "rules:create:write"]):
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有保存规则草稿权限", "data": None})
effective_body = body.model_copy(update={"editor_user_id": body.editor_user_id or int(payload["user_id"])})
data = await self.GroupService.CreateRuleDraft(GroupId, effective_body)
return JSONResponse(status_code=200, content=data.model_dump())
async def _check_permission(self, user_id: int, permission_keys: list[str]) -> bool:
for permission_key in permission_keys:
if await self.PermissionService.CheckPermission(user_id, permission_key):