Skip to content

Commit fbfc2f8

Browse files
committed
cleanup: We are not using user groups, remove the code
To make code simpler remove parts that we didn't found use. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 21d55ca commit fbfc2f8

File tree

3 files changed

+1
-190
lines changed

3 files changed

+1
-190
lines changed

api/main.py

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -386,86 +386,6 @@ async def update_password(request: Request,
386386
)
387387

388388

389-
# -----------------------------------------------------------------------------
390-
# User groups
391-
392-
393-
@app.post('/group', response_model=UserGroup, response_model_by_alias=False)
394-
async def post_user_group(
395-
group: UserGroup,
396-
current_user: User = Depends(get_current_superuser)):
397-
"""Create new user group"""
398-
metrics.add('http_requests_total', 1)
399-
try:
400-
obj = await db.create(group)
401-
except DuplicateKeyError as error:
402-
raise HTTPException(
403-
status_code=status.HTTP_400_BAD_REQUEST,
404-
detail=f"Group '{group.name}' already exists. \
405-
Use a different group name."
406-
) from error
407-
await pubsub.publish_cloudevent('user_group', {'op': 'created',
408-
'id': str(obj.id)})
409-
return obj
410-
411-
412-
@app.get('/groups', response_model=PageModel)
413-
async def get_user_groups(request: Request):
414-
"""Get all the user groups if no request parameters have passed.
415-
Get all the matching user groups otherwise."""
416-
metrics.add('http_requests_total', 1)
417-
query_params = dict(request.query_params)
418-
419-
# Drop pagination parameters from query as they're already in arguments
420-
for pg_key in ['limit', 'offset']:
421-
query_params.pop(pg_key, None)
422-
423-
paginated_resp = await db.find_by_attributes(UserGroup, query_params)
424-
paginated_resp.items = serialize_paginated_data(
425-
UserGroup, paginated_resp.items)
426-
return paginated_resp
427-
428-
429-
@app.get('/group/{group_id}', response_model=Union[UserGroup, None],
430-
response_model_by_alias=False)
431-
async def get_group(group_id: str):
432-
"""Get user group information from the provided group id"""
433-
metrics.add('http_requests_total', 1)
434-
return await db.find_by_id(UserGroup, group_id)
435-
436-
437-
@app.delete('/group/{group_id}',
438-
dependencies=[Depends(pagination_ctx(PageModel))],
439-
status_code=status.HTTP_204_NO_CONTENT)
440-
async def delete_group(group_id: str,
441-
current_user: User = Depends(get_current_superuser)):
442-
"""Delete user group matching the provided group id"""
443-
metrics.add('http_requests_total', 1)
444-
group_from_id = await db.find_by_id(UserGroup, group_id)
445-
if not group_from_id:
446-
raise HTTPException(
447-
status_code=status.HTTP_404_NOT_FOUND,
448-
detail=f"Group not found with id: {group_id}"
449-
)
450-
# Remove users from the group before deleting it
451-
users = await db.find_by_attributes(
452-
User, {"groups.name": group_from_id.name})
453-
for user in users.items:
454-
user['groups'].remove(group_from_id)
455-
await db.update(User(**user))
456-
457-
# Remove group from user groups that are permitted to update node
458-
nodes = await db.find_by_attributes(
459-
Node, {"user_groups": group_from_id.name})
460-
for node in nodes.items:
461-
node['user_groups'].remove(group_from_id.name)
462-
await db.update(Node(**node))
463-
464-
await db.delete_by_id(UserGroup, group_id)
465-
466-
467-
# -----------------------------------------------------------------------------
468-
# EventHistory
469389
def _get_eventhistory(evdict):
470390
"""Get EventHistory object from dictionary"""
471391
evhist = EventHistory()
@@ -1100,7 +1020,7 @@ async def get_metrics():
11001020

11011021

11021022
@app.get('/maintenance/purge-old-nodes')
1103-
async def purge_old_nodes(current_user: User = Depends(get_current_superuser)):
1023+
async def purge_handler(current_user: User = Depends(get_current_superuser)):
11041024
"""Purge old nodes from the database
11051025
This is a maintenance operation and should be performed
11061026
only by superusers.

doc/api-details.md

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -249,54 +249,6 @@ $ curl -X 'DELETE' \
249249
-H 'Authorization: Bearer <ADMIN-USER-AUTHORIZATION-TOKEN>'
250250
```
251251

252-
253-
## User groups
254-
255-
User accounts can be added to different user groups. This section
256-
explains different API endpoints for user group management operations.
257-
258-
### Create a user group (Admin only)
259-
260-
Admin users can create user groups using `POST /group` endpoint:
261-
```
262-
$ curl -X 'POST' \
263-
'http://localhost:8001/group' \
264-
-H 'accept: application/json' \
265-
-H 'Content-Type: application/json' \
266-
-H 'Authorization: Bearer <ADMIN-USER-AUTHORIZATION-TOKEN>' \
267-
-d '{"name": "test-user-group"}'
268-
```
269-
270-
271-
### Get all existing user groups
272-
273-
Get all existing user groups using `GET /groups` endpoint:
274-
```
275-
$ curl 'http://localhost:8001/groups'
276-
{"items":[{"id":"648ff894bd39930355ed16ad","name":"kernelci"},{"id":"6704f354ffaa8f6fa017faa3","name":"test"}],"total":2,"limit":50,"offset":0}
277-
```
278-
279-
280-
### Get user group matching ID
281-
282-
To get user group by ID, use `/group` endpoint with group ID as a path parameter:
283-
```
284-
$ curl 'http://localhost:8001/group/648ff894bd39930355ed16ad'
285-
{"id":"648ff894bd39930355ed16ad","name":"kernelci"}
286-
```
287-
288-
289-
### Delete user group matching ID (Admin only)
290-
291-
Only admin users can delete existing user groups by providing group ID to
292-
`DELETE /group/<group-id>` endpoint:
293-
```
294-
$ curl -X 'DELETE' \
295-
'http://localhost:8001/group/6704f354ffaa8f6fa017faa3' \
296-
-H 'Authorization: Bearer <ADMIN-USER-AUTHORIZATION-TOKEN>'
297-
```
298-
299-
300252
## Nodes
301253

302254
`Node` objects form the basis of the API models to represent tests runs,

tests/e2e_tests/test_user_group_handler.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)