mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 19:28:07 +00:00
Merge pull request #2294 from GNS3/list-items-closed-project
[API] Allow listing items from a closed project
This commit is contained in:
commit
b6127af067
@ -78,9 +78,16 @@ async def endpoints(
|
|||||||
for project in projects:
|
for project in projects:
|
||||||
add_to_endpoints(f"/projects/{project.id}", f'Project "{project.name}"', "project")
|
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
|
# nodes
|
||||||
add_to_endpoints(f"/projects/{project.id}/nodes", f'All nodes in project "{project.name}"', "node")
|
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(
|
add_to_endpoints(
|
||||||
f"/projects/{project.id}/nodes/{node['node_id']}",
|
f"/projects/{project.id}/nodes/{node['node_id']}",
|
||||||
f'Node "{node["name"]}" in project "{project.name}"',
|
f'Node "{node["name"]}" in project "{project.name}"',
|
||||||
@ -89,7 +96,7 @@ async def endpoints(
|
|||||||
|
|
||||||
# links
|
# links
|
||||||
add_to_endpoints(f"/projects/{project.id}/links", f'All links in project "{project.name}"', "link")
|
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_1 = link["nodes"][0]["node_id"]
|
||||||
node_id_2 = link["nodes"][1]["node_id"]
|
node_id_2 = link["nodes"][1]["node_id"]
|
||||||
node_name_1 = project.nodes[node_id_1]["name"]
|
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))
|
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()]
|
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))
|
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()]
|
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
|
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()]
|
return [v.asdict() for v in project.nodes.values()]
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,10 @@ log = logging.getLogger(__name__)
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("", dependencies=[Depends(has_privilege("Symbol.Audit"))])
|
@router.get(
|
||||||
|
"",
|
||||||
|
dependencies=[Depends(has_privilege("Symbol.Audit"))]
|
||||||
|
)
|
||||||
def get_symbols() -> List[dict]:
|
def get_symbols() -> List[dict]:
|
||||||
"""
|
"""
|
||||||
Return all symbols.
|
Return all symbols.
|
||||||
@ -54,7 +57,8 @@ def get_symbols() -> List[dict]:
|
|||||||
@router.get(
|
@router.get(
|
||||||
"/{symbol_id:path}/raw",
|
"/{symbol_id:path}/raw",
|
||||||
responses={404: {"model": schemas.ErrorMessage, "description": "Could not find symbol"}},
|
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:
|
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 response.status_code == status.HTTP_200_OK
|
||||||
assert len(response.json()) == 1
|
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:
|
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 len(response.json()) == 1
|
||||||
assert response.json()[0]["filters"] == filters
|
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:
|
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.status_code == status.HTTP_200_OK
|
||||||
assert response.json()[0]["name"] == "test"
|
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:
|
async def test_get_node(app: FastAPI, client: AsyncClient, project: Project, compute: Compute) -> None:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user