From 5b3f63cd0ad9f980a51ae011d714bae559170035 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 5 Dec 2021 20:50:57 +0100 Subject: [PATCH] fix(roles): Return conflict if role should be deleted but is still in use --- flaschengeist/controller/roleController.py | 4 ++-- flaschengeist/plugins/roles/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flaschengeist/controller/roleController.py b/flaschengeist/controller/roleController.py index 9d214b0..c8b0cb2 100644 --- a/flaschengeist/controller/roleController.py +++ b/flaschengeist/controller/roleController.py @@ -1,5 +1,5 @@ from sqlalchemy.exc import IntegrityError -from werkzeug.exceptions import BadRequest, NotFound +from werkzeug.exceptions import BadRequest, Conflict, NotFound from flaschengeist.models.user import Role, Permission from flaschengeist.database import db, case_sensitive @@ -71,4 +71,4 @@ def delete(role): db.session.commit() except IntegrityError: logger.debug("IntegrityError: Role might still be in use", exc_info=True) - raise BadRequest("Role still in use") + raise Conflict("Role still in use") diff --git a/flaschengeist/plugins/roles/__init__.py b/flaschengeist/plugins/roles/__init__.py index 80deca7..954ba21 100644 --- a/flaschengeist/plugins/roles/__init__.py +++ b/flaschengeist/plugins/roles/__init__.py @@ -134,7 +134,7 @@ def delete_role(role_id, current_session): current_session: Session sent with Authorization Header Returns: - HTTP-204 or HTTP error + HTTP-204 or HTTP error (HTTP-409 Conflict if role still in use) """ role = roleController.get(role_id) roleController.delete(role)