From 70ef92b55f9301faf73f394ec5d19dedbc2ce04d Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Thu, 5 Nov 2026 15:42:51 +0800 Subject: [PATCH] fix: keep legacy projects visible to non-admin users Projects created before GNS3 3.1 have no created_by field. The project list filtered them out for every non-superadmin user, so all old projects disappeared from the list after an upgrade. Fall back to the pre-3.1 ACE-only visibility rule when created_by is not set. Projects owned by another user stay hidden. --- gns3server/api/routes/controller/projects.py | 4 +- tests/controller/test_rbac.py | 40 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gns3server/api/routes/controller/projects.py b/gns3server/api/routes/controller/projects.py index 17d1e36a4..69a1a7183 100644 --- a/gns3server/api/routes/controller/projects.py +++ b/gns3server/api/routes/controller/projects.py @@ -126,10 +126,12 @@ async def get_projects( # Step 2: Filter direct ACE projects by created_by # Direct project sharing is only available through resource pools + # Projects created before the created_by field existed (GNS3 < 3.1) have no + # owner: fall back to the ACE-only visibility rule instead of hiding them. for p in controller.projects.values(): if name is not None and p.name != name: continue - if p.id in direct_ace_ids and p.created_by == current_user.username: + if p.id in direct_ace_ids and (p.created_by is None or p.created_by == current_user.username): if p.id not in seen_project_ids: projects.append(p.asdict()) seen_project_ids.add(p.id) diff --git a/tests/controller/test_rbac.py b/tests/controller/test_rbac.py index 4ea0de736..501f752bc 100644 --- a/tests/controller/test_rbac.py +++ b/tests/controller/test_rbac.py @@ -221,6 +221,46 @@ class TestResourcePools: assert response.status_code == status.HTTP_200_OK assert len(response.json()) == 3 + async def test_list_projects_legacy_without_created_by( + self, app: FastAPI, controller: Controller, base_client: AsyncClient, db_session: AsyncSession, test_user: User + ) -> None: + """ + Projects created before GNS3 3.1 have no created_by field. They should + remain visible through a direct ACE (the pre-3.1 visibility rule) + instead of being hidden from every non-superadmin user. + """ + + # Clean up any existing ACEs from previous tests + await RbacRepository(db_session).delete_all_ace_starting_with_path("/projects") + await RbacRepository(db_session).delete_all_ace_starting_with_path("/pools") + + legacy_id = str(uuid.uuid4()) # created with GNS3 < 3.1, no created_by + owned_id = str(uuid.uuid4()) + other_id = str(uuid.uuid4()) + await controller.add_project(project_id=legacy_id, name="LegacyProject") + await controller.add_project(project_id=owned_id, name="OwnedProject", created_by=test_user.username) + await controller.add_project(project_id=other_id, name="OtherProject", created_by="admin") + + group_id = (await UsersRepository(db_session).get_user_group_by_name("Users")).user_group_id + role_id = (await RbacRepository(db_session).get_role_by_name("User")).role_id + ace = ACECreate( + path="/projects", ace_type="group", propagate=True, group_id=str(group_id), role_id=str(role_id) + ) + await RbacRepository(db_session).create_ace(ace) + + access_token = auth_service.create_access_token(test_user.username) + async with AsyncClient( + base_url="http://test-api", + headers={"Content-Type": "application/json", "Authorization": f"Bearer {access_token}"}, + transport=ASGIWebSocketTransport(app=app), + ) as user_client: + response = await user_client.get(app.url_path_for("get_projects")) + assert response.status_code == status.HTTP_200_OK + projects = response.json() + # the legacy project (no owner) and the user's own project are visible, + # but the project owned by another user is not + assert {p["name"] for p in projects} == {"LegacyProject", "OwnedProject"} + # class TestProjectsWithRbac: #