diff --git a/app/classes/shared/models.py b/app/classes/shared/models.py index 76ecd615..7f7461d4 100644 --- a/app/classes/shared/models.py +++ b/app/classes/shared/models.py @@ -466,7 +466,15 @@ class db_shortcuts: server_data.append({'server_data': s, "stats": db_helper.return_rows(latest)[0]}) return server_data - + @staticmethod + def get_user_roles_names(user_id): + roles_list = [] + roles = User_Roles.select().where(User_Roles.user_id == user_id) + for r in roles: + roles_list.append(db_helper.get_role(r.role_id)['role_name']) + return roles_list + + @staticmethod def get_authorized_servers_stats_from_roles(user_id): user_roles = User_Roles.select().where(User_Roles.user_id == user_id) @@ -619,7 +627,6 @@ class db_shortcuts: query = Roles.select().where(Roles.role_id == -1) for u in user_query: query = Roles.select().where(Roles.role_id == u.role_id) - print(query) return query @staticmethod diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 9d9536b6..53eeb226 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -7,6 +7,8 @@ import time import datetime import os +from tornado import iostream + from app.classes.shared.console import console from app.classes.shared.models import Users, installer from app.classes.web.base_handler import BaseHandler @@ -254,12 +256,39 @@ class PanelHandler(BaseHandler): self.redirect("/panel/server_detail?id={}&subpage=backup".format(server_id)) elif page == 'panel_config': + auth_servers = {} + auth_role_servers = {} + roles = db_helper.get_all_roles() + role_servers = [] + user_roles = {} + for user in db_helper.get_all_users(): + user_roles_list = db_helper.get_user_roles_names(user.user_id) + user_servers = db_helper.get_all_authorized_servers(user.user_id) + servers = [] + for server in user_servers: + servers.append(server['server_name']) + new_item = {user.user_id: servers} + auth_servers.update(new_item) + data = {user.user_id: user_roles_list} + user_roles.update(data) + for role in roles: + role = db_helper.get_role(role.role_id) + for serv_id in role['servers']: + role_servers.append(db_helper.get_server_data_by_id(serv_id)['server_name']) + data = {role['role_id']: role_servers} + auth_role_servers.update(data) + + page_data['auth-servers'] = auth_servers + page_data['role-servers'] = auth_role_servers + page_data['user-roles'] = user_roles + if exec_user['superuser'] == 1: page_data['users'] = db_helper.get_all_users() page_data['roles'] = db_helper.get_all_roles() else: page_data['users'] = db_helper.user_query(exec_user['user_id']) page_data['roles'] = db_helper.user_role_query(exec_user['user_id']) + for user in page_data['users']: if user.user_id != exec_user['user_id']: user.api_token = "********" @@ -291,12 +320,22 @@ class PanelHandler(BaseHandler): elif page == "edit_user": user_id = self.get_argument('id', None) user_servers = db_helper.get_authorized_servers(user_id) + role_servers = db_helper.get_authorized_servers_from_roles(user_id) + page_role_servers = [] servers = set() for server in user_servers: - servers.add(server['server_id']) + flag = False + for rserver in role_servers: + if rserver['server_id'] == server['server_id']: + flag = True + if not flag: + servers.add(server['server_id']) + for server in role_servers: + page_role_servers.append(server['server_id']) page_data['new_user'] = False page_data['user'] = db_helper.get_user(user_id) page_data['servers'] = servers + page_data['role-servers'] = page_role_servers page_data['roles_all'] = db_helper.get_all_roles() page_data['servers_all'] = self.controller.list_defined_servers() diff --git a/app/frontend/templates/panel/panel_config.html b/app/frontend/templates/panel/panel_config.html index 37153ed2..cb5b1c7d 100644 --- a/app/frontend/templates/panel/panel_config.html +++ b/app/frontend/templates/panel/panel_config.html @@ -45,6 +45,7 @@