Fixed issue with duplicate servers on dash if role and user both had access to the server.

This commit is contained in:
Andrew 2021-08-06 13:47:06 -04:00
parent 67008f0e37
commit f957d54348
2 changed files with 40 additions and 4 deletions

View File

@ -372,6 +372,36 @@ class db_shortcuts:
return server_data
@staticmethod
def get_all_authorized_servers(user_id):
user_servers = User_Servers.select().where(User_Servers.user_id == user_id)
user_roles = User_Roles.select().where(User_Roles.user_id == user_id)
server_data = []
roles_list = []
role_server = []
server_data = []
for u in user_servers:
server_data.append(db_helper.get_server_data_by_id(u.server_id))
for u in user_roles:
roles_list.append(db_helper.get_role(u.role_id))
for r in roles_list:
role_test = Role_Servers.select().where(Role_Servers.role_id == r.get('role_id'))
for t in role_test:
role_server.append(t)
for s in role_server:
found = False
for item in user_servers:
if s.server_id == item.server_id:
found = True
if not found:
server_data.append(db_helper.get_server_data_by_id(s.server_id))
return server_data
@staticmethod
def get_authorized_servers_from_roles(user_id):
user_roles = User_Roles.select().where(User_Roles.user_id == user_id)
@ -423,9 +453,15 @@ class db_shortcuts:
role_server.append(t)
for s in role_server:
found = False
for item in user_servers:
if item.server_id != s.server_id:
authorized_servers.append(db_helper.get_server_data_by_id(s.server_id))
print("SERVER ID: "+ str(s.server_id) + "ITEM ID"+ str(item.server_id))
if s.server_id == item.server_id:
print("IN FOUND")
found = True
if not found:
print("NOT FOUND?")
authorized_servers.append(db_helper.get_server_data_by_id(s.server_id))
for s in authorized_servers:
latest = Server_Stats.select().where(Server_Stats.server_id == s.get('server_id')).order_by(

View File

@ -36,7 +36,7 @@ class PanelHandler(BaseHandler):
defined_servers = self.controller.list_defined_servers()
exec_user_role.add("Super User")
else:
defined_servers = self.controller.list_authorized_servers(exec_user_id)
defined_servers = db_helper.get_all_authorized_servers(exec_user_id)
logger.debug(exec_user['roles'])
for r in exec_user['roles']:
role = db_helper.get_role(r)
@ -53,7 +53,7 @@ class PanelHandler(BaseHandler):
'running': len(self.controller.list_running_servers()),
'stopped': (len(self.controller.list_defined_servers()) - len(self.controller.list_running_servers()))
},
'menu_servers': self.controller.list_authorized_servers(exec_user_id),
'menu_servers': defined_servers,
'hosts_data': db_helper.get_latest_hosts_stats(),
'show_contribute': helper.get_setting("show_contribute_link", True),
'error': error,