Working role manger super user

TODO: Remove maanger after user is deleted
This commit is contained in:
Andrew 2022-08-20 09:31:33 -04:00
parent 552a2e26c2
commit 7a68e08a64
3 changed files with 37 additions and 8 deletions

View File

@ -1277,10 +1277,14 @@ class PanelHandler(BaseHandler):
page_data["role"] = self.controller.roles.get_role_with_servers(role_id)
if exec_user["superuser"]:
defined_servers = self.controller.servers.list_defined_servers()
manager = self.get_argument("manager", None)
if manager == "":
manager = None
else:
defined_servers = self.controller.servers.get_authorized_servers(
exec_user["user_id"]
)
manager = exec_user["user_id"]
page_servers = []
for server in defined_servers:
if server not in page_servers:
@ -2315,6 +2319,12 @@ class PanelHandler(BaseHandler):
elif page == "add_role":
role_name = bleach.clean(self.get_argument("role_name", None))
if exec_user["superuser"]:
manager = self.get_argument("manager", None)
if manager == "":
manager = None
else:
manager = exec_user["user_id"]
if EnumPermissionsCrafty.ROLES_CONFIG not in exec_user_crafty_permissions:
self.redirect(
@ -2337,11 +2347,6 @@ class PanelHandler(BaseHandler):
self.redirect("/panel/error?error=Role exists")
return
manager = None
if not exec_user["superuser"]:
manager = exec_user["user_id"]
servers = self.get_role_servers()
role_id = self.controller.roles.add_role_advanced(

View File

@ -49,7 +49,7 @@
</ul>
<div class="">
<div class="">
<form class="forms-sample" method="post" action="{{ '/panel/add_role' if data['new_role'] else '/panel/edit_role' }}">
<form id="role_form" class="forms-sample" method="post" action="{{ '/panel/add_role' if data['new_role'] else '/panel/edit_role' }}">
{% raw xsrf_form_html() %}
<input type="hidden" name="id" value="{{ data['role']['role_id'] }}">
<input type="hidden" name="subpage" value="config">
@ -63,6 +63,29 @@
<label for="role_name">{{ translate('rolesConfig', 'roleName', data['lang']) }} <small class="text-muted ml-1"> - {{ translate('rolesConfig', 'roleDesc', data['lang']) }}</small> </label>
<input type="text" class="form-control" name="role_name" id="role_name" value="{{ data['role']['role_name'] }}" placeholder="Role Name" >
</div>
<br />
{% if data['superuser'] %}
<div class="form-group">
<label class="form-label" for="manager">{{ translate('rolesConfig', 'selectManager',
data['lang']) }}
</label>
<select class="form-select form-control form-control-lg select-css" id="manager" name="manager"
form="role_form">
{% if data["role_manager"]["username"] != "None" %}
<option value='{{data["role_manager"]["user_id"]}}'>{{ data["role_manager"]["username"]
}}</option>
{% end %}
<option value="">None</option>
{% for user in data['users'] %}
{% if user.user_id != data['role_manager']['user_id']
%}
<option value="{{user.user_id}}">{{user.username}}</option>
{% end %}
{% end %}
</select>
</div>
{% end %}
</div>
</div>
@ -252,7 +275,7 @@
<br />
{{ translate('rolesConfig', 'configUpdate', data['lang']) }} {{ str(data['role']['last_update']) }}
<br />
Manager: {{ data['role_manager']['username'] }}
{{ translate('userConfig', 'manager', data['lang']) }}: {{ data['role_manager']['username'] }}
<br />
</p>
</blockquote>

View File

@ -245,7 +245,8 @@
"roleUsers": "Role Users: ",
"serverAccess": "Access?",
"serverName": "Server Name",
"serversDesc": "servers this role is allowed to access"
"serversDesc": "servers this role is allowed to access",
"selectManager": "Select a manager for this Role"
},
"serverBackups": {
"backupAtMidnight": "Auto-backup at midnight?",