From 691345cf404a9a7ab222ca574e4438471d0291a7 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 18 Dec 2021 04:19:07 +0100 Subject: [PATCH] fix(roles): Minor fix in set_permissions --- flaschengeist/controller/roleController.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/flaschengeist/controller/roleController.py b/flaschengeist/controller/roleController.py index 86f74ab..23528ad 100644 --- a/flaschengeist/controller/roleController.py +++ b/flaschengeist/controller/roleController.py @@ -12,7 +12,7 @@ def get_all(): return Role.query.all() -def get(role_name: Union[int,str]) -> Role: +def get(role_name: Union[int, str]) -> Role: """Get role by ID or name Args: role_name: Name or ID of the role @@ -46,11 +46,10 @@ def update_role(role, new_name): def set_permissions(role, permissions): - for name in permissions: - p = Permission.query.filter(Permission.name.in_(permissions)).all() - if not p or len(p) < len(permissions): - raise BadRequest("Invalid permission name >{}<".format(name)) - role.permissions = list(p) + perms = Permission.query.filter(Permission.name.in_(permissions)).all() + if len(perms) < len(permissions): + raise BadRequest("Invalid permission name") + role.permissions = list(perms) db.session.commit()