mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-13 20:08:55 +00:00
List elements when a project is closed
This commit is contained in:
parent
a27db6b4eb
commit
5092bd2fdf
@ -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"]
|
||||
|
@ -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()]
|
||||
|
||||
|
||||
|
@ -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()]
|
||||
|
||||
|
||||
|
@ -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()]
|
||||
|
||||
|
||||
|
@ -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:
|
||||
"""
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user