feat: add tenant-scoped rule and permission management

This commit is contained in:
wren
2026-05-21 22:03:08 +08:00
parent a2c2bf1969
commit 1f1bccf3b3
193 changed files with 64463 additions and 1771 deletions
@@ -30,7 +30,12 @@ class RuleConfigController(BaseController):
"""列出规则配置页 pack。"""
if not await self._check_permission(int(payload["user_id"])):
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有规则配置查看权限", "data": None})
data = await (self.RuleConfigService.ListPackSummaries() if summaryOnly else self.RuleConfigService.ListPacks())
current_user_id = int(payload["user_id"])
data = await (
self.RuleConfigService.ListPackSummaries(CurrentUserId=current_user_id)
if summaryOnly
else self.RuleConfigService.ListPacks(CurrentUserId=current_user_id)
)
return JSONResponse(status_code=200, content={"code": 200, "message": "success", "data": [item.model_dump() for item in data]})
@self.router.get("/{PackId}")
@@ -38,7 +43,7 @@ class RuleConfigController(BaseController):
"""获取单个规则配置 pack。"""
if not await self._check_permission(int(payload["user_id"])):
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有规则配置查看权限", "data": None})
data = await self.RuleConfigService.GetPack(PackId)
data = await self.RuleConfigService.GetPack(PackId, CurrentUserId=int(payload["user_id"]))
return JSONResponse(status_code=200, content={"code": 200, "message": "success", "data": data.model_dump()})
async def _check_permission(self, user_id: int) -> bool: