From 5807dd068e8f707474673f973fab497fb996768c Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 20 Sep 2021 10:36:56 +0930 Subject: [PATCH] Revert "No need to add permissions when the super admin creates templates or projects" This reverts commit 3d1c3303f9451cf39bb09cb7d5bf0281d5afe52a. --- gns3server/api/routes/controller/projects.py | 6 ++---- gns3server/api/routes/controller/templates.py | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/gns3server/api/routes/controller/projects.py b/gns3server/api/routes/controller/projects.py index 56ea3dc0..757faf6f 100644 --- a/gns3server/api/routes/controller/projects.py +++ b/gns3server/api/routes/controller/projects.py @@ -111,8 +111,7 @@ async def create_project( controller = Controller.instance() project = await controller.add_project(**jsonable_encoder(project_data, exclude_unset=True)) - if not current_user.is_superadmin: - await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/projects/{project.id}/*") + await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/projects/{project.id}/*") return project.asdict() @@ -393,8 +392,7 @@ async def duplicate_project( new_project = await project.duplicate( name=project_data.name, location=location, reset_mac_addresses=reset_mac_addresses ) - if not current_user.is_superadmin: - await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/projects/{new_project.id}/*") + await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/projects/{new_project.id}/*") return new_project.asdict() diff --git a/gns3server/api/routes/controller/templates.py b/gns3server/api/routes/controller/templates.py index 8a47b8c4..4f1914b5 100644 --- a/gns3server/api/routes/controller/templates.py +++ b/gns3server/api/routes/controller/templates.py @@ -25,7 +25,7 @@ import logging log = logging.getLogger(__name__) -from fastapi import APIRouter, Request, HTTPException, Depends, Response, status +from fastapi import APIRouter, Request, Response, HTTPException, Depends, Response, status from typing import List from uuid import UUID @@ -55,8 +55,7 @@ async def create_template( template = await TemplatesService(templates_repo).create_template(template_create) template_id = template.get("template_id") - if not current_user.is_superadmin: - await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/templates/{template_id}/*") + await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/templates/{template_id}/*") return template @@ -151,6 +150,5 @@ async def duplicate_template( """ template = await TemplatesService(templates_repo).duplicate_template(template_id) - if not current_user.is_superadmin: - await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/templates/{template_id}/*") + await rbac_repo.add_permission_to_user_with_path(current_user.user_id, f"/templates/{template_id}/*") return template