]> git.ipfire.org Git - dbl.git/commitdiff
api: Implement closing reports
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 8 Feb 2026 18:32:09 +0000 (18:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 8 Feb 2026 18:32:09 +0000 (18:32 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dbl/api/reports.py
src/dbl/reports.py

index 1327e1813b5fc98cef5a4a45b82b2294741bae2a..eb241c9cb517a3794b7c362d504e4f225d52e175 100644 (file)
@@ -19,6 +19,7 @@
 ###############################################################################
 
 import fastapi
+import pydantic
 import typing
 import uuid
 
@@ -38,7 +39,14 @@ def get_report_from_path(id: uuid.UUID = fastapi.Path(...)) -> reports.Report:
        """
                Fetches a report by its ID
        """
-       return backend.reports.get_by_id(id)
+       # Fetch the report
+       report = backend.reports.get_by_id(id)
+
+       # Raise 404 if we could not find the report
+       if not report:
+               raise fastapi.HTTPException(404, "Could not find report %s" % id)
+
+       return report
 
 @router.get("")
 def get_reports() -> typing.List[reports.Report]:
@@ -46,10 +54,29 @@ def get_reports() -> typing.List[reports.Report]:
 
 @router.get("/{id}")
 def get_report(report = fastapi.Depends(get_report_from_path)) -> reports.Report:
-       if not report:
-               raise fastapi.HTTPException(404, "Could not find report")
-
        return report
 
+class CloseReport(pydantic.BaseModel):
+       # Closed By
+       closed_by: str
+
+       # Accept?
+       accept: bool = True
+
+@router.post("/{id}/close")
+def close_report(
+               data: CloseReport,
+               report: reports.Report = fastapi.Depends(get_report_from_path),
+) -> fastapi.Response:
+       # Close the report
+       with backend.db:
+               report.close(
+                       closed_by = data.closed_by,
+                       accept    = data.accept,
+               )
+
+       # Send 204
+       return fastapi.Response(status_code=fastapi.status.HTTP_204_NO_CONTENT)
+
 # Include our endpoints
 app.include_router(router)
index 1128c0e45d7f089d5fe68345f0633eaf22b03dee..aff8eb06c181f9a945c392e974171663d25f27fc 100644 (file)
@@ -236,6 +236,8 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True):
                if self.closed_by:
                        raise RuntimeError("Report %s has already been closed" % self)
 
+               # XXX Check for permissions
+
                # Mark this report as closed
                self.closed_at = sqlmodel.func.current_timestamp()
                self.closed_by = closed_by