Improve server permission related functions

This commit is contained in:
luukas 2022-05-16 18:01:15 +03:00
parent cd87a63f1e
commit d83b964267

View File

@ -51,18 +51,17 @@ class PermissionsServers:
@staticmethod @staticmethod
def get_permissions_list(): def get_permissions_list():
permissions_list = [] return [
for member in EnumPermissionsServer.__members__.items(): permission for _, permission in EnumPermissionsServer.__members__.items()
permissions_list.append(member[1]) ]
return permissions_list
@staticmethod @staticmethod
def get_permissions(permissions_mask): def get_permissions(permissions_mask):
permissions_list = [] return [
for member in EnumPermissionsServer.__members__.items(): permission
if PermissionsServers.has_permission(permissions_mask, member[1]): for _, permission in EnumPermissionsServer.__members__.items()
permissions_list.append(member[1]) if PermissionsServers.has_permission(permissions_mask, permission)
return permissions_list ]
@staticmethod @staticmethod
def has_permission(permission_mask, permission_tested: EnumPermissionsServer): def has_permission(permission_mask, permission_tested: EnumPermissionsServer):
@ -147,23 +146,18 @@ class PermissionsServers:
@staticmethod @staticmethod
def get_role_permissions_list(role_id): def get_role_permissions_list(role_id):
permissions_mask = "00000000"
role_server = RoleServers.get_or_none(RoleServers.role_id == role_id) role_server = RoleServers.get_or_none(RoleServers.role_id == role_id)
if role_server is not None: permissions_mask = (
permissions_mask = role_server.permissions "00000000" if role_server is None else role_server.permissions
)
permissions_list = PermissionsServers.get_permissions(permissions_mask) permissions_list = PermissionsServers.get_permissions(permissions_mask)
return permissions_list return permissions_list
@staticmethod @staticmethod
def update_role_permission(role_id, server_id, permissions_mask): def update_role_permission(role_id, server_id, permissions_mask):
role_server = ( RoleServers.update(permissions=permissions_mask).where(
RoleServers.select() RoleServers.role_id == role_id, RoleServers.server_id == server_id
.where(RoleServers.role_id == role_id) ).execute()
.where(RoleServers.server_id == server_id)
.get()
)
role_server.permissions = permissions_mask
RoleServers.save(role_server)
@staticmethod @staticmethod
def delete_roles_permissions(role_id, removed_servers=None): def delete_roles_permissions(role_id, removed_servers=None):