Fix exception with endpoints returning HTTP status code 204. Fixes #1891

This commit is contained in:
grossmj
2021-08-10 21:53:21 +09:30
parent 36b9f8bdfd
commit ce55ec73a4
29 changed files with 337 additions and 192 deletions

View File

@ -19,7 +19,7 @@
API routes for roles.
"""
from fastapi import APIRouter, Depends, status
from fastapi import APIRouter, Depends, Response, status
from uuid import UUID
from typing import List
@ -105,7 +105,7 @@ async def update_role(
async def delete_role(
role_id: UUID,
rbac_repo: RbacRepository = Depends(get_repository(RbacRepository)),
) -> None:
) -> Response:
"""
Delete a role.
"""
@ -121,6 +121,8 @@ async def delete_role(
if not success:
raise ControllerNotFoundError(f"Role '{role_id}' could not be deleted")
return Response(status_code=status.HTTP_204_NO_CONTENT)
@router.get("/{role_id}/permissions", response_model=List[schemas.Permission])
async def get_role_permissions(
@ -142,7 +144,7 @@ async def add_permission_to_role(
role_id: UUID,
permission_id: UUID,
rbac_repo: RbacRepository = Depends(get_repository(RbacRepository))
) -> None:
) -> Response:
"""
Add a permission to a role.
"""
@ -155,6 +157,8 @@ async def add_permission_to_role(
if not role:
raise ControllerNotFoundError(f"Role '{role_id}' not found")
return Response(status_code=status.HTTP_204_NO_CONTENT)
@router.delete(
"/{role_id}/permissions/{permission_id}",
@ -164,7 +168,7 @@ async def remove_permission_from_role(
role_id: UUID,
permission_id: UUID,
rbac_repo: RbacRepository = Depends(get_repository(RbacRepository)),
) -> None:
) -> Response:
"""
Remove member from an user group.
"""
@ -176,3 +180,5 @@ async def remove_permission_from_role(
role = await rbac_repo.remove_permission_from_role(role_id, permission)
if not role:
raise ControllerNotFoundError(f"Role '{role_id}' not found")
return Response(status_code=status.HTTP_204_NO_CONTENT)