|
1 | | -""" |
2 | | -Role management controller module. |
3 | | -
|
4 | | -This module provides CRUD operations for managing user roles |
5 | | -in the role-based access control system. |
6 | | -""" |
| 1 | +"""Role management controller module.""" |
7 | 2 |
|
8 | 3 | from typing import Any, Sequence |
9 | 4 | from uuid import UUID |
@@ -40,88 +35,62 @@ class RoleController(Controller): |
40 | 35 | dependencies = {"role_service": Provide(provide_role_service)} |
41 | 36 | exception_handlers = {NotFoundError: not_found_error_handler} |
42 | 37 |
|
43 | | - @get("/", summary="ListRoles", guards=[has_permission("roles", "list")]) |
| 38 | + @get( |
| 39 | + "/", |
| 40 | + summary="ListRoles", |
| 41 | + guards=[has_permission("roles", "list")], |
| 42 | + ) |
44 | 43 | async def list(self, role_service: RoleService) -> Sequence[Role]: |
45 | 44 | """ |
46 | | - Get all roles in the system. |
47 | | -
|
48 | | - Requires the 'roles:list' permission. |
49 | | -
|
50 | | - Args: |
51 | | - role_service: Role service for business operations |
| 45 | + List all roles in the system. |
52 | 46 |
|
53 | | - Returns: |
54 | | - List of all role objects |
55 | | -
|
56 | | - Raises: |
57 | | - PermissionDeniedException: If the user lacks 'roles:list' permission |
| 47 | + This endpoint requires the 'roles:list' permission. |
58 | 48 | """ |
59 | 49 | return await role_service.list() |
60 | 50 |
|
61 | | - @post("/", summary="CreateRole", dto=RoleCreateDTO, guards=[has_permission("roles", "create")]) |
| 51 | + @post( |
| 52 | + "/", |
| 53 | + summary="CreateRole", |
| 54 | + dto=RoleCreateDTO, |
| 55 | + guards=[has_permission("roles", "create")], |
| 56 | + ) |
62 | 57 | async def create(self, data: Role, role_service: RoleService) -> Role: |
63 | 58 | """ |
64 | | - Create a new role. |
65 | | -
|
66 | | - Requires the 'roles:create' permission. |
67 | | -
|
68 | | - Args: |
69 | | - data: Role data for creation |
70 | | - role_service: Role service for business operations |
| 59 | + Create a new role with associated permissions. |
71 | 60 |
|
72 | | - Returns: |
73 | | - The created role object |
74 | | -
|
75 | | - Raises: |
76 | | - PermissionDeniedException: If the user lacks 'roles:create' permission |
77 | | - HTTPException: If validation fails |
| 61 | + Creates a new role with the provided data and assigns any specified |
| 62 | + permissions. Requires the 'roles:create' permission. |
78 | 63 | """ |
79 | 64 | try: |
80 | 65 | return await role_service.create_role_with_permissions(data) |
81 | 66 | except ValueError as exc: |
82 | 67 | raise HTTPException(detail=str(exc), status_code=400) from exc |
83 | 68 |
|
84 | | - @get("/{role_id:uuid}", summary="FetchRole", guards=[has_permission("roles", "read")]) |
| 69 | + @get( |
| 70 | + "/{role_id:uuid}", |
| 71 | + summary="FetchRole", |
| 72 | + guards=[has_permission("roles", "read")], |
| 73 | + ) |
85 | 74 | async def fetch(self, role_id: UUID, role_service: RoleService) -> Role: |
86 | 75 | """ |
87 | | - Get a specific role by ID. |
| 76 | + Fetch a specific role by its UUID. |
88 | 77 |
|
89 | 78 | Requires the 'roles:read' permission. |
90 | | -
|
91 | | - Args: |
92 | | - role_id: UUID of the role to retrieve |
93 | | - role_service: Role service for business operations |
94 | | -
|
95 | | - Returns: |
96 | | - The requested role object |
97 | | -
|
98 | | - Raises: |
99 | | - NotFoundError: If the role is not found (handled by not_found_error_handler) |
100 | | - PermissionDeniedException: If the user lacks 'roles:read' permission |
101 | 79 | """ |
102 | 80 | return await role_service.get(role_id) |
103 | 81 |
|
104 | 82 | @patch( |
105 | | - "/{role_id:uuid}", summary="UpdateRole", dto=RoleUpdateDTO, guards=[has_permission("roles", "update")] |
| 83 | + "/{role_id:uuid}", |
| 84 | + summary="UpdateRole", |
| 85 | + dto=RoleUpdateDTO, |
| 86 | + guards=[has_permission("roles", "update")], |
106 | 87 | ) |
107 | 88 | async def update(self, role_id: UUID, data: DTOData[Role], role_service: RoleService) -> Role: |
108 | 89 | """ |
109 | | - Update an existing role. |
110 | | -
|
111 | | - Requires the 'roles:update' permission. |
112 | | -
|
113 | | - Args: |
114 | | - role_id: UUID of the role to update |
115 | | - data: Updated role data |
116 | | - role_service: Role service for business operations |
117 | | -
|
118 | | - Returns: |
119 | | - The updated role object |
| 90 | + Update an existing role's data and permissions. |
120 | 91 |
|
121 | | - Raises: |
122 | | - NotFoundError: If the role is not found (handled by not_found_error_handler) |
123 | | - PermissionDeniedException: If the user lacks 'roles:update' permission |
124 | | - HTTPException: If validation fails |
| 92 | + Updates the specified role's information and permission assignments |
| 93 | + with the provided data. Requires the 'roles:update' permission. |
125 | 94 | """ |
126 | 95 | try: |
127 | 96 | return await role_service.update_role_with_permissions(role_id, data.as_builtins()) |
|
0 commit comments