From d83b96426793175a11bbc10ad5ebfe2bf514bc5b Mon Sep 17 00:00:00 2001 From: luukas Date: Mon, 16 May 2022 18:01:15 +0300 Subject: [PATCH] Improve server permission related functions --- app/classes/models/server_permissions.py | 34 ++++++++++-------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/app/classes/models/server_permissions.py b/app/classes/models/server_permissions.py index 6b4553d2..58ce204a 100644 --- a/app/classes/models/server_permissions.py +++ b/app/classes/models/server_permissions.py @@ -51,18 +51,17 @@ class PermissionsServers: @staticmethod def get_permissions_list(): - permissions_list = [] - for member in EnumPermissionsServer.__members__.items(): - permissions_list.append(member[1]) - return permissions_list + return [ + permission for _, permission in EnumPermissionsServer.__members__.items() + ] @staticmethod def get_permissions(permissions_mask): - permissions_list = [] - for member in EnumPermissionsServer.__members__.items(): - if PermissionsServers.has_permission(permissions_mask, member[1]): - permissions_list.append(member[1]) - return permissions_list + return [ + permission + for _, permission in EnumPermissionsServer.__members__.items() + if PermissionsServers.has_permission(permissions_mask, permission) + ] @staticmethod def has_permission(permission_mask, permission_tested: EnumPermissionsServer): @@ -147,23 +146,18 @@ class PermissionsServers: @staticmethod def get_role_permissions_list(role_id): - permissions_mask = "00000000" role_server = RoleServers.get_or_none(RoleServers.role_id == role_id) - if role_server is not None: - permissions_mask = role_server.permissions + permissions_mask = ( + "00000000" if role_server is None else role_server.permissions + ) permissions_list = PermissionsServers.get_permissions(permissions_mask) return permissions_list @staticmethod def update_role_permission(role_id, server_id, permissions_mask): - role_server = ( - RoleServers.select() - .where(RoleServers.role_id == role_id) - .where(RoleServers.server_id == server_id) - .get() - ) - role_server.permissions = permissions_mask - RoleServers.save(role_server) + RoleServers.update(permissions=permissions_mask).where( + RoleServers.role_id == role_id, RoleServers.server_id == server_id + ).execute() @staticmethod def delete_roles_permissions(role_id, removed_servers=None):