Merge branch 'pretzel-unstable' into 'pretzel'

Added user list with users attached to role on role config page.

See merge request crafty-controller/crafty-commander!42
This commit is contained in:
Andrew 2021-08-09 21:19:17 +00:00
commit e62b24fdb8
3 changed files with 54 additions and 10 deletions

View File

@ -258,6 +258,8 @@ class PanelHandler(BaseHandler):
elif page == 'panel_config':
auth_servers = {}
auth_role_servers = {}
users_list = []
role_users = {}
roles = db_helper.get_all_roles()
role_servers = []
user_roles = {}
@ -279,6 +281,7 @@ class PanelHandler(BaseHandler):
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
@ -341,14 +344,14 @@ class PanelHandler(BaseHandler):
page_data['roles_all'] = db_helper.get_all_roles()
page_data['servers_all'] = self.controller.list_defined_servers()
if not exec_user['superuser']:
if user_id is None:
self.redirect("/panel/error?error=Invalid User ID")
return
elif not exec_user['superuser']:
page_data['servers'] = []
page_data['role-servers'] = []
page_data['roles_all'] = []
page_data['servers_all'] = []
elif user_id is None:
self.redirect("/panel/error?error=Invalid User ID")
return
if exec_user['user_id'] != page_data['user']['user_id']:
page_data['user']['api_token'] = "********"
@ -382,6 +385,12 @@ class PanelHandler(BaseHandler):
self.redirect("/panel/panel_config")
elif page == "add_role":
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)
data = {user.user_id: user_roles_list}
user_roles.update(data)
page_data['new_role'] = True
page_data['role'] = {}
page_data['role']['role_name'] = ""
@ -389,6 +398,8 @@ class PanelHandler(BaseHandler):
page_data['role']['created'] = "N/A"
page_data['role']['last_update'] = "N/A"
page_data['role']['servers'] = set()
page_data['user-roles'] = user_roles
page_data['users'] = db_helper.get_all_users()
if not exec_user['superuser']:
self.redirect("/panel/error?error=Unauthorized access: not superuser")
@ -398,10 +409,20 @@ class PanelHandler(BaseHandler):
template = "panel/panel_edit_role.html"
elif page == "edit_role":
auth_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)
data = {user.user_id: user_roles_list}
user_roles.update(data)
page_data['new_role'] = False
role_id = self.get_argument('id', None)
page_data['role'] = db_helper.get_role(role_id)
page_data['servers_all'] = self.controller.list_defined_servers()
page_data['user-roles'] = user_roles
page_data['users'] = db_helper.get_all_users()
if not exec_user['superuser']:
self.redirect("/panel/error?error=Unauthorized access: not superuser")

View File

@ -105,6 +105,7 @@
<tr class="rounded">
<th>Role</th>
<th>Allowed Servers</th>
<th>Role Users</th>
<th>Edit</th>
</tr>
</thead>
@ -117,6 +118,16 @@
<li>{{item}}</li>
{% end %}
</ul></td>
<td><ul>
{% for user in data['users'] %}
{% for ruser in data['user-roles'][user.user_id] %}
{% if ruser == role.role_name %}
<li>{{ user.username }}</li>
{% end %}
{% end %}
{% 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

@ -48,7 +48,6 @@
<i class="fas fa-folder-tree"></i>Other</a>
</li>
</ul>
<div class="row">
<div class="col-md-6 col-sm-12">
{% if data['new_role'] %}
@ -97,9 +96,22 @@
<button type="submit" class="btn btn-success mr-2">Save</button>
<button type="reset" onclick="location.href='/panel/panel_config'" class="btn btn-light">Cancel</button>
</form>
</div>
<div class="col-md-6 col-sm-12">
</div>
<div class="col-md-3 col-sm-12">
<h6>Users Assigned to Role:</h6>
<ul>
{% for user in data['users'] %}
{% for ruser in data['user-roles'][user.user_id] %}
{% if ruser == data['role']['role_name'] %}
<li>{{ user.username }}</li>
{% end %}
{% end %}
{% end %}
</ul>
<br>
</div>
<div class="col-md-3 col-sm-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Role Config Area</h4>
@ -114,7 +126,9 @@
</blockquote>
</div>
</div>
<div class="text-center">
</div>
</div>
<div class="text-center">
{% if data['new_role'] %}
<a class="btn btn-sm btn-danger disabled">Delete Role</a><br />
<small>You cannot delete something that does not yet exist</small>
@ -123,8 +137,6 @@
{% end %}
</div>
</div>
</div>
</div>
</div>