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,
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):