API endpoint to get the locked status of a project

This commit is contained in:
grossmj committed 2022-09-03 22:58:44 +02:00
1 parent 3014bd0216
commit 27debfff8d
3 files changed
+29 -1

No files matched your search

+10 -1
View File
@@ -30,7 +30,7 @@ import logging
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.responses import StreamingResponse, FileResponse
from websockets.exceptions import ConnectionClosed, WebSocketException
@@ -395,6 +395,15 @@ async def duplicate_project(
return new_project.asdict()
@router.get("/{project_id}/locked")
async def locked_project(project: Project = Depends(dep_project)) -> dict:
"""
Returns whether a project is locked or not
"""
return {"result": project.locked}
@router.post("/{project_id}/lock", status_code=status.HTTP_204_NO_CONTENT)
async def lock_project(project: Project = Depends(dep_project)) -> None:
"""
+15
View File
@@ -1144,6 +1144,21 @@ class Project:
self.emit_notification("node.updated", node.asdict())
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):
"""
Dump topology to disk