feat(role): add role_code across schema and APIs

This commit is contained in:
Chris
2026-04-03 15:49:22 +08:00
parent 94cec746cb
commit 405000ded5
15 changed files with 91 additions and 6 deletions

View File

@@ -250,6 +250,7 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
role_key = _generate_unique_key("RL", lambda key: roles_repo.get_by_key(key) is not None)
roles_repo.create(
role_key=role_key,
role_code=role_name,
system_id=system.id,
name=role_name,
description=role_desc,
@@ -259,6 +260,7 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
else:
roles_repo.update(
role,
role_code=role.role_code or role_name,
name=role_name,
description=role_desc,
status=role_status,
@@ -373,6 +375,7 @@ def sync_systems_from_provider(db: Session, *, force: bool = False) -> dict[str,
role_key = _generate_unique_key("RL", lambda key: roles_repo.get_by_key(key) is not None)
roles_repo.create(
role_key=role_key,
role_code=role_name,
system_id=system.id,
name=role_name,
description=role_desc,
@@ -382,6 +385,7 @@ def sync_systems_from_provider(db: Session, *, force: bool = False) -> dict[str,
else:
roles_repo.update(
role,
role_code=role.role_code or role_name,
name=role_name,
description=role_desc,
status=role_status,

View File

@@ -3,7 +3,7 @@ from app.schemas.permissions import RoleSnapshotItem, RoleSnapshotResponse
class PermissionService:
@staticmethod
def build_role_snapshot(user_sub: str, rows: list[tuple[str, str, str, str, str, str, str, str]]) -> RoleSnapshotResponse:
def build_role_snapshot(user_sub: str, rows: list[tuple[str, str, str, str, str, str, str, str, str]]) -> RoleSnapshotResponse:
return RoleSnapshotResponse(
user_sub=user_sub,
roles=[
@@ -15,6 +15,7 @@ class PermissionService:
system_key=system_key,
system_name=system_name,
role_key=role_key,
role_code=role_code,
role_name=role_name,
)
for (
@@ -25,6 +26,7 @@ class PermissionService:
system_key,
system_name,
role_key,
role_code,
role_name,
) in rows
],