From 1eca8c5c94b5b5777d1b1072ef0e49f33c2a4ca0 Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Wed, 27 May 2026 10:47:36 +0800 Subject: [PATCH] fix: prevent duplicate projects when user projects are in resource pools Fixed a bug where projects created by a user that are also in a resource pool the user has access to would appear twice in the GET /projects response. Changes: - Add seen_project_ids set to track already added projects - Check for duplicates before adding projects in Step 2 (user projects) - Check for duplicates before adding projects in Step 3 (resource pool projects) This ensures each project appears only once regardless of whether it's user-created or shared via resource pool. --- gns3server/api/routes/controller/projects.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gns3server/api/routes/controller/projects.py b/gns3server/api/routes/controller/projects.py index 27a59041d..40e594d9c 100644 --- a/gns3server/api/routes/controller/projects.py +++ b/gns3server/api/routes/controller/projects.py @@ -86,6 +86,7 @@ async def get_projects( controller = Controller.instance() projects = [] + seen_project_ids = set() # track seen projects to avoid duplicates if current_user.is_superadmin: # super admin sees all projects @@ -102,14 +103,20 @@ async def get_projects( # Step 2: Filter ace_projects by created_by - user's own projects # Project sharing is only available through resource pools user_projects = [p.asdict() for p in ace_projects if p.created_by == current_user.username] - projects.extend(user_projects) + for project in user_projects: + if project['project_id'] not in seen_project_ids: + projects.append(project) + seen_project_ids.add(project['project_id']) # Step 3: Resource pool projects # Projects shared through resource pools user_pool_resources = await rbac_repo.get_user_pool_resources(current_user.user_id, "Project.Audit") project_ids_in_pools = [str(r.resource_id) for r in user_pool_resources if r.resource_type == "project"] pool_projects = [p.asdict() for p in controller.projects.values() if p.id in project_ids_in_pools] - projects.extend(pool_projects) + for project in pool_projects: + if project['project_id'] not in seen_project_ids: + projects.append(project) + seen_project_ids.add(project['project_id']) return projects