@@ -37,8 +37,47 @@ def model_to_schema(
3737@management_read_only_api
3838@wrap_api_exception ("permissions fetching failed" )
3939def fetch_all ():
40- """Fetch all permissions
41- """
40+ """Fetch all permissions
41+
42+ :status 200: no error
43+ :status 401: user did not provide authorization data,
44+ or the authorization has expired
45+ :status 403: user was authorized, but did not have permission
46+ to read permissions
47+
48+ :>jsonarr string created: UTC creation date (RFC822)
49+ :>jsonarr integer id: permission identifier
50+ :>jsonarr str permission: permission type (read/update/delete)
51+ :>jsonarr str resource: type of resource (group/device/package)
52+ :>jsonarr str user_id: id of the user to whom this permission applies
53+ :>jsonarr integer resource_id: id of the resource to which this permission applies
54+
55+ **Example Request**
56+
57+ .. sourcecode:: http
58+
59+ GET /api/v1/permissions HTTP/1.1
60+ Accept: application/json
61+
62+ **Example Response**
63+
64+ .. sourcecode:: http
65+
66+ HTTP/1.1 200 OK
67+ Content-Type: application/json
68+
69+ [
70+ {
71+ "created": "Thu, 16 Jan 2025 13:31:53 -0000",
72+ "id": 1,
73+ "permission": "read",
74+ "resource": "group",
75+ "resource_id": 2,
76+ "user_id": "095e4160-9017-4868-82a5-fe0a0c44d34c"
77+ }
78+ ]
79+ """ # noqa: E501
80+
4281 permissions : List [
4382 models .permission .
4483 Permission ] = server .instance ._permissions_db .fetch_all (
@@ -54,7 +93,46 @@ def fetch_all():
5493@deserialize_schema (schema_dataclass = Permission , key = "perm" )
5594def create (perm : Permission ):
5695 """Create a new permission
57- """
96+
97+ :status 200: no error
98+ :status 401: user did not provide authorization data,
99+ or the authorization has expired
100+ :status 403: user was authorized, but did not have permission
101+ to create permissions
102+
103+ **Example Request**
104+
105+ .. sourcecode:: http
106+
107+ POST /api/v1/permissions HTTP/1.1
108+ Content-Type: application/json
109+ Accept: application/json
110+
111+ {
112+ "resource": "group",
113+ "resource_id": 5,
114+ "user_id": "095e4160-9017-4868-82a5-fe0a0c44d34c",
115+ "permission": "read"
116+ }
117+
118+ **Example Response**
119+
120+ .. sourcecode:: http
121+
122+ HTTP/1.1 200 OK
123+ Content-Type: application/json
124+
125+ {
126+ "created": "Thu, 23 Jan 2025 13:03:44 -0000",
127+ "id": 26,
128+ "permission": "read",
129+ "resource": "group",
130+ "resource_id": 5,
131+ "user_id": "095e4160-9017-4868-82a5-fe0a0c44d34c"
132+ }
133+
134+ """ # noqa: E501
135+
58136 permission = models .permission .Permission ()
59137 permission .created = datetime .datetime .utcnow ()
60138 permission .resource = perm .resource
@@ -76,7 +154,37 @@ def create(perm: Permission):
76154@wrap_api_exception ("permission fetching failed" )
77155def fetch_one (identifier : int ):
78156 """Fetch permission
79- """
157+
158+ :status 200: no error
159+ :status 401: user did not provide authorization data,
160+ or the authorization has expired
161+ :status 403: user was authorized, but did not have permission
162+ to read permissions
163+
164+ **Example Request**
165+
166+ .. sourcecode:: http
167+
168+ GET /api/v1/permissions/26 HTTP/1.1
169+ Accept: application/json
170+
171+ **Example Response**
172+
173+ .. sourcecode:: http
174+
175+ HTTP/1.1 200 OK
176+ Content-Type: application/json
177+
178+ {
179+ "created": "Thu, 23 Jan 2025 13:03:44 -0000",
180+ "id": 26,
181+ "permission": "read",
182+ "resource": "group",
183+ "resource_id": 5,
184+ "user_id": "095e4160-9017-4868-82a5-fe0a0c44d34c"
185+ }
186+ """ # noqa: E501
187+
80188 permission : Optional [
81189 models .permission .Permission
82190 ] = server .instance ._permissions_db .fetch_one (identifier )
@@ -92,7 +200,29 @@ def fetch_one(identifier: int):
92200@wrap_api_exception ("permission deletion failed" )
93201def delete_one (identifier : int ):
94202 """Delete permission
203+
204+ :status 200: no error
205+ :status 401: user did not provide authorization data,
206+ or the authorization has expired
207+ :status 403: user was authorized, but did not have permission
208+ to delete permissions
209+
210+ **Example Request**
211+
212+ .. sourcecode:: http
213+
214+ DELETE /api/v1/permissions/26 HTTP/1.1
215+
216+ **Example Response**
217+
218+ .. sourcecode:: http
219+
220+ HTTP/1.1 200 OK
221+ Content-Type: application/json
222+
223+ {}
95224 """
225+
96226 permission : Optional [
97227 models .permission .Permission
98228 ] = server .instance ._permissions_db .fetch_one (identifier )
0 commit comments