From bac75ca582b25784125e8c651120d787473fb0ff Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 3 Dec 2021 13:13:48 +0100 Subject: [PATCH] fix(users): Fix query for active users --- flaschengeist/controller/userController.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flaschengeist/controller/userController.py b/flaschengeist/controller/userController.py index 93bd771..e5514cf 100644 --- a/flaschengeist/controller/userController.py +++ b/flaschengeist/controller/userController.py @@ -17,6 +17,11 @@ from flaschengeist.models.user import User, Role, _PasswordReset from flaschengeist.controller import imageController, messageController, sessionController +def __active_users(): + """Return query for not deleted users""" + return User.query.filter(User.deleted == False) + + def _generate_password_reset(user): """Generate a password reset link for the user""" reset = _PasswordReset.query.get(user.id_) @@ -123,7 +128,8 @@ def modify_user(user, password, new_password=None): def get_users(deleted=False): - return User.query.filter(User.deleted == deleted).all() + query = __active_users() if not deleted else User.query + return query.all() def get_user_by_role(role: Role): @@ -139,7 +145,7 @@ def get_user(uid, deleted=False): User fround Raises: NotFound if not found""" - user = User.query.filter(User.userid == uid, User.deleted == deleted).one_or_none() + user = (__active_users() if not deleted else User.query).filter(User.userid == uid).one_or_none() if not user: raise NotFound return user