MR comments

- fixed order of import in user_service.py
- added error handling for user delete
This commit is contained in:
Davor 2022-05-18 16:51:21 +02:00 committed by Maarten de Waard
parent 09f1d2e00a
commit 5206c78998
2 changed files with 15 additions and 13 deletions

View file

@ -1,11 +1,7 @@
import copy
from areas.apps.models import App
from database import db from database import db
from areas.apps import AppRole from areas.apps.models import App, AppRole
from helpers import KratosApi from helpers import KratosApi
class UserService: class UserService:
@staticmethod @staticmethod
def get_users(): def get_users():
@ -75,9 +71,12 @@ class UserService:
@staticmethod @staticmethod
def delete_user(id): def delete_user(id):
app_role = AppRole.query.filter_by(user_id=id).all() app_role = AppRole.query.filter_by(user_id=id).all()
for ar in app_role: try:
db.session.delete(ar) for ar in app_role:
db.session.commit() db.session.delete(ar)
db.session.commit()
except:
raise Exception('Exception during user roles deletion for userId: {}').__format__(id)
@staticmethod @staticmethod
def __insertAppRoleToUser(userId, userRes): def __insertAppRoleToUser(userId, userRes):

View file

@ -50,8 +50,11 @@ def put_user(id):
@jwt_required() @jwt_required()
@cross_origin() @cross_origin()
def delete_user(id): def delete_user(id):
res = KratosApi.delete("/identities/{}".format(id)) try:
UserService.delete_user(id) res = KratosApi.delete("/identities/{}".format(id))
if res.status_code == 204: if res.status_code == 204:
return jsonify(), res.status_code UserService.delete_user(id)
return jsonify(res.json()), res.status_code return jsonify(), res.status_code
return jsonify(res.json()), res.status_code
except:
return jsonify({"message":"There was an error deleting user"}), 404