diff --git a/app/classes/controllers/roles_controller.py b/app/classes/controllers/roles_controller.py index 5e7925a3..d29a429d 100644 --- a/app/classes/controllers/roles_controller.py +++ b/app/classes/controllers/roles_controller.py @@ -64,8 +64,12 @@ class RolesController: HelperRoles.update_role(role_id, up_data) @staticmethod - def add_role(role_name): - return HelperRoles.add_role(role_name) + def add_role(role_name, manager): + return HelperRoles.add_role(role_name, manager) + + @staticmethod + def get_managed_roles(exec_user_id): + return HelperRoles.get_managed_roles(exec_user_id) class RoleServerJsonType(t.TypedDict): server_id: t.Union[str, int] diff --git a/app/classes/models/roles.py b/app/classes/models/roles.py index 4d61e051..7c9b98b1 100644 --- a/app/classes/models/roles.py +++ b/app/classes/models/roles.py @@ -6,6 +6,7 @@ from peewee import ( DoesNotExist, AutoField, DateTimeField, + IntegerField, ) from playhouse.shortcuts import model_to_dict @@ -22,6 +23,7 @@ class Roles(BaseModel): created = DateTimeField(default=datetime.datetime.now) last_update = DateTimeField(default=datetime.datetime.now) role_name = CharField(default="", unique=True, index=True) + manager = IntegerField(null=True) class Meta: table_name = "roles" @@ -38,6 +40,10 @@ class HelperRoles: def get_all_roles(): return Roles.select() + @staticmethod + def get_managed_roles(exec_user_id): + return Roles.select().where(Roles.manager == exec_user_id) + @staticmethod def get_all_role_ids() -> t.List[int]: return [role.role_id for role in Roles.select(Roles.role_id).execute()] @@ -71,11 +77,12 @@ class HelperRoles: ) @staticmethod - def add_role(role_name): + def add_role(role_name, manager): role_id = Roles.insert( { Roles.role_name: role_name.lower(), Roles.created: Helpers.get_time_as_string(), + Roles.manager: manager, } ).execute() return role_id diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index da5bd7b9..803be805 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -865,6 +865,13 @@ class PanelHandler(BaseHandler): page_data["managed_users"] = self.controller.users.get_managed_users( exec_user["user_id"] ) + page_data["assigned_roles"] = [] + for item in page_data["roles"]: + page_data["assigned_roles"].append(item.role_id) + + page_data["managed_roles"] = self.controller.roles.get_managed_roles( + exec_user["user_id"] + ) template = "panel/panel_config.html" @@ -1245,6 +1252,11 @@ class PanelHandler(BaseHandler): defined_servers = self.controller.servers.get_authorized_servers( exec_user["user_id"] ) + + page_data["role_manager"] = { + "user_id": -100, + "username": "None", + } page_servers = [] for server in defined_servers: if server not in page_servers: @@ -1285,6 +1297,16 @@ class PanelHandler(BaseHandler): page_data["user-roles"] = user_roles page_data["users"] = self.controller.users.get_all_users() + if page_data["role"]["manager"] is not None: + page_data["role_manager"] = self.controller.users.get_user_by_id( + page_data["role"]["manager"] + ) + else: + page_data["role_manager"] = { + "user_id": -100, + "username": "None", + } + if EnumPermissionsCrafty.ROLES_CONFIG not in exec_user_crafty_permissions: self.redirect( "/panel/error?error=Unauthorized access: not a role editor" diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py index df4ba684..b49b6410 100644 --- a/app/classes/web/server_handler.py +++ b/app/classes/web/server_handler.py @@ -283,7 +283,8 @@ class ServerHandler(BaseHandler): new_server_id ).get("server_uuid") role_id = self.controller.roles.add_role( - f"Creator of Server with uuid={new_server_uuid}" + f"Creator of Server with uuid={new_server_uuid}", + exec_user["user_id"], ) self.controller.server_perms.add_role_server( new_server_id, role_id, "11111111" @@ -420,7 +421,8 @@ class ServerHandler(BaseHandler): new_server_id ).get("server_uuid") role_id = self.controller.roles.add_role( - f"Creator of Server with uuid={new_server_uuid}" + f"Creator of Server with uuid={new_server_uuid}", + exec_user["user_id"], ) self.controller.server_perms.add_role_server( new_server_id, role_id, "11111111" @@ -545,7 +547,8 @@ class ServerHandler(BaseHandler): new_server_id ).get("server_uuid") role_id = self.controller.roles.add_role( - f"Creator of Server with uuid={new_server_uuid}" + f"Creator of Server with uuid={new_server_uuid}", + exec_user["user_id"], ) self.controller.server_perms.add_role_server( new_server_id, role_id, "11111111" diff --git a/app/frontend/templates/panel/panel_config.html b/app/frontend/templates/panel/panel_config.html index 0c89a596..d5efeac6 100644 --- a/app/frontend/templates/panel/panel_config.html +++ b/app/frontend/templates/panel/panel_config.html @@ -177,7 +177,32 @@