Merge branch 'pretzel-unstable' into 'pretzel'

Added server lists to config page

See merge request crafty-controller/crafty-commander!37
This commit is contained in:
Andrew 2021-08-08 22:29:18 +00:00
commit 79f9fd0990
4 changed files with 67 additions and 5 deletions

View File

@ -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

View File

@ -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()

View File

@ -45,6 +45,7 @@
<th>Enabled</th>
<th>API Token</th>
<th>Allowed Servers</th>
<th>Assigned Roles</th>
<th>Edit</th>
</tr>
</thead>
@ -66,7 +67,16 @@
</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>
</tr>
{% end %}
@ -102,7 +112,11 @@
{% for role in data['roles'] %}
<tr>
<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>
</tr>
{% end %}

View File

@ -124,6 +124,8 @@
<td>
{% if server['server_id'] in data['servers'] %}
<input type="checkbox" class="form-check-input" id="server_{{ server['server_id'] }}_access" name="server_{{ server['server_id'] }}_access" checked="" value="1">
{% elif server['server_id'] in data['role-servers'] %}
<input type="checkbox" class="form-check-input" id="server_{{ server['server_id'] }}_access" name="server_{{ server['server_id'] }}_access" checked="" value="" disabled>
{% else %}
<input type="checkbox" class="form-check-input" id="server_{{ server['server_id'] }}_access" name="server_{{ server['server_id'] }}_access" value="1">
{% end %}