refactor: permission

This commit is contained in:
tao.chen
2026-09-02 10:10:41 +08:00
committed by tao.chen
parent 1c220490cf
commit dea6b4cfcf
11 changed files with 171 additions and 1037 deletions
+5 -5
View File
@@ -58,7 +58,7 @@ Invariants
* ``DELETE /workspaces/{id}`` is allowed from any non-disabled status and
sets ``status='disabled'`` + ``is_deleted=1`` + ``deleted_at`` on the
workspace and every one of its active memberships.
* The ``admin`` role must always keep ``system.view`` + ``system.manage``
* The ``admin`` role must always keep ``system:view``.
menu permissions; non-admin roles may never hold ``system.*``
permissions. Menu permissions gate frontend rendering only — API
authorization always keys off ``role_code == 'admin'``.
@@ -1185,7 +1185,7 @@ async def patch_role_permissions(
1. Load the role. Reject 404 if it is missing or not
platform-scoped.
2. Admin role: the patched ``permission_codes`` MUST still include
both ``system.view`` and ``system.manage``. Otherwise every
``system:view``. Otherwise every
active admin loses the menu entry to this very endpoint and
the platform locks itself out. Reject with 409. (No last-admin
count is needed here — menu permissions never gate API access;
@@ -1207,12 +1207,12 @@ async def patch_role_permissions(
if role.role_code == "admin":
keeps_admin_entry = (
"system.view" in new_codes and "system.manage" in new_codes
"system:view" in new_codes
)
if not keeps_admin_entry:
raise HTTPException(
status.HTTP_409_CONFLICT,
"admin 角色必须保留 system.view 与 system.manage 权限",
"admin 角色必须保留 system:view 权限",
)
else:
# Menu permissions are a frontend-display signal only — backend
@@ -1222,7 +1222,7 @@ async def patch_role_permissions(
# /api/v1/platform/* call still returns 403. Reject with 422 so
# the failure is unambiguous about *what* the input violated.
leaked_system = [
code for code in new_codes if code.startswith("system.")
code for code in new_codes if code.startswith("system:")
]
if leaked_system:
raise HTTPException(