]> git.ipfire.org Git - dbl.git/commitdiff
api: Don't accept any repeat reports by the same user
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 3 Mar 2026 14:35:17 +0000 (14:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 3 Mar 2026 14:35:17 +0000 (14:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dbl/api/reports.py
src/dbl/lists.py

index 57e01ef7d069fb30412b447bde0e4b0cd7e58cca..5b3e5fd2bdc95cf3a0cb9efed6194affe41ba183 100644 (file)
@@ -110,6 +110,10 @@ async def create_report(
        if not list:
                raise fastapi.HTTPException(400, "Could not find list '%s'" % report.list)
 
+       # Check if something has already been reported
+       if await list.recently_reported(name=report.name, reported_by=user, block=report.block):
+               raise fastapi.HTTPException(409, "%s has already been reported by %s" % (report.name, user))
+
        # Create the report
        return await list.report(
                name        = report.name,
index 51223b9f313aacaebae064a3c7cc17c129ebcb31..955f2759333b30e48b04a18d00b967f0057b9a95 100644 (file)
@@ -562,6 +562,29 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
        pending_reports : int = 0
 
+       # Recently Reported?
+
+       async def recently_reported(self, name, reported_by, block=None):
+               """
+                       Called to check if we have already received this report by the same user
+               """
+               # We fetch the last report of the name by the given user.
+               reports = self.backend.reports.get(
+                       list=self, name=name, reported_by=reported_by, limit=1,
+               )
+
+               # If block has been given, we also check if this matches
+               async for report in reports:
+                       # If block has not been specified, we count every match
+                       if block is None:
+                               return True
+
+                       # Otherwise the block must match
+                       return report.block == block
+
+               # Nothing found
+               return False
+
        # History
 
        def get_history(self, before=None, limit=None):