mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-28 01:38:08 +00:00
Merge pull request #2110 from GNS3/locked-project
API endpoint to get the locked status of a project
This commit is contained in:
commit
0f4c98c7e4
@ -30,7 +30,7 @@ import logging
|
|||||||
|
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, Request, Response, Body, HTTPException, status, WebSocket, WebSocketDisconnect
|
from fastapi import APIRouter, Depends, Request, Body, HTTPException, status, WebSocket, WebSocketDisconnect
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import StreamingResponse, FileResponse
|
from fastapi.responses import StreamingResponse, FileResponse
|
||||||
from websockets.exceptions import ConnectionClosed, WebSocketException
|
from websockets.exceptions import ConnectionClosed, WebSocketException
|
||||||
@ -395,6 +395,15 @@ async def duplicate_project(
|
|||||||
return new_project.asdict()
|
return new_project.asdict()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{project_id}/locked")
|
||||||
|
async def locked_project(project: Project = Depends(dep_project)) -> bool:
|
||||||
|
"""
|
||||||
|
Returns whether a project is locked or not
|
||||||
|
"""
|
||||||
|
|
||||||
|
return project.locked
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{project_id}/lock", status_code=status.HTTP_204_NO_CONTENT)
|
@router.post("/{project_id}/lock", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
async def lock_project(project: Project = Depends(dep_project)) -> None:
|
async def lock_project(project: Project = Depends(dep_project)) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -1144,6 +1144,21 @@ class Project:
|
|||||||
self.emit_notification("node.updated", node.asdict())
|
self.emit_notification("node.updated", node.asdict())
|
||||||
self.dump()
|
self.dump()
|
||||||
|
|
||||||
|
@property
|
||||||
|
@open_required
|
||||||
|
def locked(self):
|
||||||
|
"""
|
||||||
|
Check if all items in a project are locked and not
|
||||||
|
"""
|
||||||
|
|
||||||
|
for drawing in self._drawings.values():
|
||||||
|
if not drawing.locked:
|
||||||
|
return False
|
||||||
|
for node in self.nodes.values():
|
||||||
|
if not node.locked:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
"""
|
"""
|
||||||
Dump topology to disk
|
Dump topology to disk
|
||||||
|
@ -511,6 +511,10 @@ async def test_lock_unlock(app: FastAPI, client: AsyncClient, project: Project,
|
|||||||
for node in project.nodes.values():
|
for node in project.nodes.values():
|
||||||
assert node.locked is True
|
assert node.locked is True
|
||||||
|
|
||||||
|
response = await client.get(app.url_path_for("locked_project", project_id=project.id))
|
||||||
|
assert response.status_code == status.HTTP_200_OK
|
||||||
|
assert response.json() is True
|
||||||
|
|
||||||
response = await client.post(app.url_path_for("unlock_project", project_id=project.id))
|
response = await client.post(app.url_path_for("unlock_project", project_id=project.id))
|
||||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user