Added server/role lists to panel config

This commit is contained in:
Andrew 2021-08-08 16:43:04 -04:00
parent e4db76e4b9
commit debabfc045
3 changed files with 55 additions and 3 deletions

View File

@ -466,7 +466,15 @@ class db_shortcuts:
server_data.append({'server_data': s, "stats": db_helper.return_rows(latest)[0]}) server_data.append({'server_data': s, "stats": db_helper.return_rows(latest)[0]})
return server_data 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 @staticmethod
def get_authorized_servers_stats_from_roles(user_id): def get_authorized_servers_stats_from_roles(user_id):
user_roles = User_Roles.select().where(User_Roles.user_id == user_id) user_roles = User_Roles.select().where(User_Roles.user_id == user_id)

View File

@ -7,6 +7,8 @@ import time
import datetime import datetime
import os import os
from tornado import iostream
from app.classes.shared.console import console from app.classes.shared.console import console
from app.classes.shared.models import Users, installer from app.classes.shared.models import Users, installer
from app.classes.web.base_handler import BaseHandler 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)) self.redirect("/panel/server_detail?id={}&subpage=backup".format(server_id))
elif page == 'panel_config': 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: if exec_user['superuser'] == 1:
page_data['users'] = db_helper.get_all_users() page_data['users'] = db_helper.get_all_users()
page_data['roles'] = db_helper.get_all_roles() page_data['roles'] = db_helper.get_all_roles()
else: else:
page_data['users'] = db_helper.user_query(exec_user['user_id']) page_data['users'] = db_helper.user_query(exec_user['user_id'])
page_data['roles'] = db_helper.user_role_query(exec_user['user_id']) page_data['roles'] = db_helper.user_role_query(exec_user['user_id'])
for user in page_data['users']: for user in page_data['users']:
if user.user_id != exec_user['user_id']: if user.user_id != exec_user['user_id']:
user.api_token = "********" user.api_token = "********"
@ -297,6 +326,7 @@ class PanelHandler(BaseHandler):
page_data['new_user'] = False page_data['new_user'] = False
page_data['user'] = db_helper.get_user(user_id) page_data['user'] = db_helper.get_user(user_id)
page_data['servers'] = servers page_data['servers'] = servers
page_data['role-servers'] = db_helper.get_authorized_servers_from_roles(exec_user_id)
page_data['roles_all'] = db_helper.get_all_roles() page_data['roles_all'] = db_helper.get_all_roles()
page_data['servers_all'] = self.controller.list_defined_servers() page_data['servers_all'] = self.controller.list_defined_servers()

View File

@ -45,6 +45,7 @@
<th>Enabled</th> <th>Enabled</th>
<th>API Token</th> <th>API Token</th>
<th>Allowed Servers</th> <th>Allowed Servers</th>
<th>Assigned Roles</th>
<th>Edit</th> <th>Edit</th>
</tr> </tr>
</thead> </thead>
@ -66,7 +67,16 @@
</td> </td>
<td>{{ user.api_token }}</td> <td>{{ user.api_token }}</td>
<td>{{ [] }}</td> <td class="server_list_{{user.user_id}}"><ul id="{{user.user_id}}">
{% for item in data['auth-servers'][user.user_id] %}
<li>{{item}}</li>
{% end %}
</ul></td>
<td class="role_list_{{user.user_id}}"><ul>
{% for item in data['user-roles'][user.user_id] %}
<li>{{item}}</li>
{% end %}
<td><a href="/panel/edit_user?id={{user.user_id}}"><i class="fas fa-pencil-alt"></i></a></td> <td><a href="/panel/edit_user?id={{user.user_id}}"><i class="fas fa-pencil-alt"></i></a></td>
</tr> </tr>
{% end %} {% end %}
@ -102,7 +112,11 @@
{% for role in data['roles'] %} {% for role in data['roles'] %}
<tr> <tr>
<td>{{ role.role_name }}</td> <td>{{ role.role_name }}</td>
<td>{{ [] }}</td> <td class="role_list_{{role.role_id}}"><ul id="{{role.role_id}}">
{% for item in data['role-servers'][role.role_id] %}
<li>{{item}}</li>
{% end %}
</ul></td>
<td><a href="/panel/edit_role?id={{role.role_id}}"><i class="fas fa-pencil-alt"></i></a></td> <td><a href="/panel/edit_role?id={{role.role_id}}"><i class="fas fa-pencil-alt"></i></a></td>
</tr> </tr>
{% end %} {% end %}