From 552a2e26c2cd14fe2c4037d1e1d780e7dcee70a4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 20 Aug 2022 08:49:38 -0400 Subject: [PATCH] Working role managers. TODO: Add super user select option --- app/classes/controllers/roles_controller.py | 3 +- app/classes/web/panel_handler.py | 20 +- app/classes/web/routes/api/roles/index.py | 4 +- .../templates/panel/panel_config.html | 5 +- .../templates/panel/panel_edit_role.html | 190 ++++++++---------- 5 files changed, 109 insertions(+), 113 deletions(-) diff --git a/app/classes/controllers/roles_controller.py b/app/classes/controllers/roles_controller.py index d29a429d..647902a3 100644 --- a/app/classes/controllers/roles_controller.py +++ b/app/classes/controllers/roles_controller.py @@ -96,6 +96,7 @@ class RolesController: def add_role_advanced( name: str, servers: t.Iterable[RoleServerJsonType], + manager: int, ) -> int: """Add a role with a name and a list of servers @@ -106,7 +107,7 @@ class RolesController: Returns: int: The new role's ID """ - role_id: t.Final[int] = HelperRoles.add_role(name) + role_id: t.Final[int] = HelperRoles.add_role(name, manager) for server in servers: PermissionsServers.get_or_create( role_id, server["server_id"], server["permissions"] diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 803be805..e619f73d 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -1321,8 +1321,15 @@ class PanelHandler(BaseHandler): elif page == "remove_role": role_id = bleach.clean(self.get_argument("id", None)) - if not superuser: - self.redirect("/panel/error?error=Unauthorized access: not superuser") + if ( + not superuser + and self.controller.roles.get_role(role_id)["manager"] + != exec_user["user_id"] + ): + self.redirect( + "/panel/error?error=Unauthorized access: not superuser not" + " role manager" + ) return if role_id is None: self.redirect("/panel/error?error=Invalid Role ID") @@ -2330,9 +2337,16 @@ 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(role_name, servers) + role_id = self.controller.roles.add_role_advanced( + role_name, servers, manager + ) self.controller.management.add_to_audit_log( exec_user["user_id"], diff --git a/app/classes/web/routes/api/roles/index.py b/app/classes/web/routes/api/roles/index.py index 2ca1baf3..150bff0c 100644 --- a/app/classes/web/routes/api/roles/index.py +++ b/app/classes/web/routes/api/roles/index.py @@ -116,7 +116,9 @@ class ApiRolesIndexHandler(BaseApiHandler): 400, {"status": "error", "error": "ROLE_NAME_ALREADY_EXISTS"} ) - role_id = self.controller.roles.add_role_advanced(role_name, servers) + role_id = self.controller.roles.add_role_advanced( + role_name, servers, user["user_id"] + ) self.controller.management.add_to_audit_log( user["user_id"], diff --git a/app/frontend/templates/panel/panel_config.html b/app/frontend/templates/panel/panel_config.html index d5efeac6..b344f1c9 100644 --- a/app/frontend/templates/panel/panel_config.html +++ b/app/frontend/templates/panel/panel_config.html @@ -177,6 +177,8 @@ {% end %} + + {% if not data['superuser'] %} {% for role in data['managed_roles'] %} {% if role.role_id not in data['assigned_roles'] %} @@ -201,7 +203,8 @@ - {& end %} + {% end %} + {% end %} {% end %} diff --git a/app/frontend/templates/panel/panel_edit_role.html b/app/frontend/templates/panel/panel_edit_role.html index fd29d0d4..d39f9453 100644 --- a/app/frontend/templates/panel/panel_edit_role.html +++ b/app/frontend/templates/panel/panel_edit_role.html @@ -9,22 +9,22 @@
- +
@@ -39,8 +39,7 @@ + - {% end %} +{% end %} - {% block js %} - + - {% end %} \ No newline at end of file +{% end %}