diff --git a/app/classes/controllers/users_controller.py b/app/classes/controllers/users_controller.py index 12bb4c2c..fc5b8492 100644 --- a/app/classes/controllers/users_controller.py +++ b/app/classes/controllers/users_controller.py @@ -30,6 +30,14 @@ class Users_Controller: def get_user_by_id(user_id): return users_helper.get_user(user_id) + @staticmethod + def update_server_order(user_id, user_server_order): + users_helper.update_server_order(user_id, user_server_order) + + @staticmethod + def get_server_order(user_id): + return users_helper.get_server_order(user_id) + @staticmethod def user_query(user_id): return users_helper.user_query(user_id) diff --git a/app/classes/models/server_permissions.py b/app/classes/models/server_permissions.py index b666deba..fcf966ef 100644 --- a/app/classes/models/server_permissions.py +++ b/app/classes/models/server_permissions.py @@ -173,7 +173,10 @@ class Permissions_Servers: else: roles_list = users_helper.get_user_roles_id(user.user_id) role_server = Role_Servers.select().where(Role_Servers.role_id.in_(roles_list)).where(Role_Servers.server_id == server_id).execute() - permissions_mask = role_server[0].permissions + try: + permissions_mask = role_server[0].permissions + except IndexError: + permissions_mask = '0' * len(server_permissions.get_permissions_list()) return permissions_mask @staticmethod diff --git a/app/classes/models/users.py b/app/classes/models/users.py index e154e885..2c4c7d06 100644 --- a/app/classes/models/users.py +++ b/app/classes/models/users.py @@ -1,3 +1,5 @@ +from email.policy import default +from http import server import sys import logging import datetime @@ -42,6 +44,7 @@ class Users(Model): lang = CharField(default="en_EN") support_logs = CharField(default = '') valid_tokens_from = DateTimeField(default=datetime.datetime.now) + server_order = CharField(default="") class Meta: table_name = "users" @@ -173,6 +176,14 @@ class helper_users: if up_data: Users.update(up_data).where(Users.user_id == user_id).execute() + @staticmethod + def update_server_order(user_id, user_server_order): + Users.update(server_order = user_server_order).where(Users.user_id == user_id).execute() + + @staticmethod + def get_server_order(user_id): + return Users.select().where(Users.user_id == user_id) + @staticmethod def get_super_user_list(): final_users = [] diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index bcf6060b..5d739c9a 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -258,6 +258,10 @@ class AjaxHandler(BaseHandler): # Create the directory os.mkdir(dir_path) + elif page == "send_order": + self.controller.users.update_server_order(exec_user['user_id'], bleach.clean(self.get_argument('order'))) + return + elif page == "unzip_file": if not permissions['Files'] in user_perms: if not superuser: diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index c20fdd91..e5b23549 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -307,6 +307,29 @@ class PanelHandler(BaseHandler): list(filter(lambda x: x['stats']['running'], page_data['servers']))) page_data['server_stats']['stopped'] = len(page_data['servers']) - page_data['server_stats']['running'] + #set user server order + user_order = self.controller.users.get_user_by_id(exec_user['user_id']) + user_order = user_order['server_order'].split(',') + page_servers = [] + server_ids = [] + + for server_id in user_order: + for server in page_data['servers']: + if str(server['server_data']['server_id']) == str(server_id): + page_servers.append(server) + + + for server in page_data['servers']: + server_ids.append(str(server['server_data']['server_id'])) + if server not in page_servers: + page_servers.append(server) + for server_id in user_order: + #remove IDs in list that user no longer has access to + if str(server_id) not in server_ids: + user_order.remove(server_id) + page_data['servers'] = page_servers + + for data in page_data['servers']: data['stats']['crashed'] = self.controller.servers.is_crashed( str(data['stats']['server_id']['server_id'])) diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index 2bdc2d43..7f15c1c4 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -123,7 +123,7 @@
{% for server in data['servers'] %} -