diff --git a/gns3server/api/routes/controller/acl.py b/gns3server/api/routes/controller/acl.py index 5ba72006..ea33d46e 100644 --- a/gns3server/api/routes/controller/acl.py +++ b/gns3server/api/routes/controller/acl.py @@ -78,9 +78,16 @@ async def endpoints( for project in projects: add_to_endpoints(f"/projects/{project.id}", f'Project "{project.name}"', "project") + if project.status == "closed": + nodes = project.nodes.values() + links = project.links.values() + else: + nodes = [v.asdict() for v in project.nodes.values()] + links = [v.asdict() for v in project.links.values()] + # nodes add_to_endpoints(f"/projects/{project.id}/nodes", f'All nodes in project "{project.name}"', "node") - for node in project.nodes.values(): + for node in nodes: add_to_endpoints( f"/projects/{project.id}/nodes/{node['node_id']}", f'Node "{node["name"]}" in project "{project.name}"', @@ -89,7 +96,7 @@ async def endpoints( # links add_to_endpoints(f"/projects/{project.id}/links", f'All links in project "{project.name}"', "link") - for link in project.links.values(): + for link in links: node_id_1 = link["nodes"][0]["node_id"] node_id_2 = link["nodes"][1]["node_id"] node_name_1 = project.nodes[node_id_1]["name"] diff --git a/gns3server/api/routes/controller/drawings.py b/gns3server/api/routes/controller/drawings.py index 22ca1b95..1d8c47f1 100644 --- a/gns3server/api/routes/controller/drawings.py +++ b/gns3server/api/routes/controller/drawings.py @@ -49,6 +49,9 @@ async def get_drawings(project_id: UUID) -> List[schemas.Drawing]: """ project = await Controller.instance().get_loaded_project(str(project_id)) + if project.status == "closed": + # allow to retrieve drawings from a closed project + return project.drawings.values() return [v.asdict() for v in project.drawings.values()] diff --git a/gns3server/api/routes/controller/links.py b/gns3server/api/routes/controller/links.py index 28743b75..618ea198 100644 --- a/gns3server/api/routes/controller/links.py +++ b/gns3server/api/routes/controller/links.py @@ -70,6 +70,9 @@ async def get_links(project_id: UUID) -> List[schemas.Link]: """ project = await Controller.instance().get_loaded_project(str(project_id)) + if project.status == "closed": + # allow to retrieve links from a closed project + return project.links.values() return [v.asdict() for v in project.links.values()] diff --git a/gns3server/api/routes/controller/nodes.py b/gns3server/api/routes/controller/nodes.py index b096b634..865ad683 100644 --- a/gns3server/api/routes/controller/nodes.py +++ b/gns3server/api/routes/controller/nodes.py @@ -141,6 +141,9 @@ def get_nodes(project: Project = Depends(dep_project)) -> List[schemas.Node]: Required privilege: Node.Audit """ + if project.status == "closed": + # allow to retrieve nodes from a closed project + return project.nodes.values() return [v.asdict() for v in project.nodes.values()] diff --git a/gns3server/api/routes/controller/symbols.py b/gns3server/api/routes/controller/symbols.py index 6d73c623..c6dee131 100644 --- a/gns3server/api/routes/controller/symbols.py +++ b/gns3server/api/routes/controller/symbols.py @@ -39,7 +39,10 @@ log = logging.getLogger(__name__) router = APIRouter() -@router.get("", dependencies=[Depends(has_privilege("Symbol.Audit"))]) +@router.get( + "", + dependencies=[Depends(has_privilege("Symbol.Audit"))] +) def get_symbols() -> List[dict]: """ Return all symbols. @@ -54,7 +57,8 @@ def get_symbols() -> List[dict]: @router.get( "/{symbol_id:path}/raw", responses={404: {"model": schemas.ErrorMessage, "description": "Could not find symbol"}}, - dependencies=[Depends(has_privilege("Symbol.Audit"))] + # FIXME: this is a temporary workaround due to a bug in the web-ui: https://github.com/GNS3/gns3-web-ui/issues/1466 + # dependencies=[Depends(has_privilege("Symbol.Audit"))] ) async def get_symbol(symbol_id: str) -> FileResponse: """ diff --git a/tests/api/routes/controller/test_drawings.py b/tests/api/routes/controller/test_drawings.py index 4bbb20d2..c5fcec38 100644 --- a/tests/api/routes/controller/test_drawings.py +++ b/tests/api/routes/controller/test_drawings.py @@ -94,6 +94,12 @@ async def test_all_drawings(app: FastAPI, client: AsyncClient, project: Project) assert response.status_code == status.HTTP_200_OK assert len(response.json()) == 1 + # test listing links from a closed project + await project.close(ignore_notification=True) + response = await client.get(app.url_path_for("get_drawings", project_id=project.id)) + assert response.status_code == status.HTTP_200_OK + assert len(response.json()) == 1 + async def test_delete_drawing(app: FastAPI, client: AsyncClient, project: Project) -> None: diff --git a/tests/api/routes/controller/test_links.py b/tests/api/routes/controller/test_links.py index 139fb3ff..ab6bf476 100644 --- a/tests/api/routes/controller/test_links.py +++ b/tests/api/routes/controller/test_links.py @@ -305,6 +305,13 @@ async def test_list_link(app: FastAPI, client: AsyncClient, project: Project, no assert len(response.json()) == 1 assert response.json()[0]["filters"] == filters + # test listing links from a closed project + await project.close(ignore_notification=True) + response = await client.get(app.url_path_for("get_links", project_id=project.id)) + assert response.status_code == status.HTTP_200_OK + assert len(response.json()) == 1 + assert response.json()[0]["filters"] == filters + async def test_reset_link(app: FastAPI, client: AsyncClient, project: Project) -> None: diff --git a/tests/api/routes/controller/test_nodes.py b/tests/api/routes/controller/test_nodes.py index 5e57f6fa..534fe136 100644 --- a/tests/api/routes/controller/test_nodes.py +++ b/tests/api/routes/controller/test_nodes.py @@ -78,6 +78,12 @@ async def test_list_node(app: FastAPI, client: AsyncClient, project: Project, co assert response.status_code == status.HTTP_200_OK assert response.json()[0]["name"] == "test" + # test listing nodes from a closed project + await project.close(ignore_notification=True) + response = await client.get(app.url_path_for("get_nodes", project_id=project.id)) + assert response.status_code == status.HTTP_200_OK + assert response.json()[0]["name"] == "test" + async def test_get_node(app: FastAPI, client: AsyncClient, project: Project, compute: Compute) -> None: