fix(users): Fix query for active users

This commit is contained in:
Ferdinand Thiessen 2021-12-03 13:13:48 +01:00
parent 47400f02e9
commit bac75ca582
1 changed files with 8 additions and 2 deletions

View File

@ -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