]> git.ipfire.org Git - dbl.git/commitdiff
reports: Send an email to the reporter when a report is being opened
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jan 2026 16:34:08 +0000 (16:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jan 2026 16:34:08 +0000 (16:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/reports.py

index 2c68a111921398007ce94636b47061f00e1b3fb0..bb0bb55eb26cf870c1a2dca841ff68d6664902f5 100644 (file)
@@ -75,6 +75,9 @@ class Reports(object):
                # Increment the counter of the list
                report.list.pending_reports += 1
 
+               # Send a notification to the reporter
+               report._send_opening_notification()
+
                return report
 
        def notify(self):
@@ -229,6 +232,10 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True):
                """
                        Called when a moderator has made a decision
                """
+               # Prevent a report from being closed again
+               if self.closed_by:
+                       raise RuntimeError("Report %s has already been closed" % self)
+
                # Mark this report as closed
                self.closed_at = sqlmodel.func.current_timestamp()
                self.closed_by = closed_by
@@ -269,6 +276,40 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True):
        # Notified At
        notified_at: datetime.datetime | None = None
 
+       def _send_opening_notification(self):
+               """
+                       Sends a notification to the reporter when this report is opened.
+               """
+               # Fetch the reporter
+               reporter = self.backend.users.get_by_uid(self.reported_by)
+
+               # Do nothing if we could not find the reporter
+               if not reporter:
+                       return
+
+               # Compose the body
+               lines = (
+                       _("Hello,"),
+                       "",
+                       _("Thank you for submitting a report to the IPFire DNSBL service."),
+                       "",
+                       _("We have received your report regarding %s and wanted to confirm that it's now in our moderation queue.") % self.name,
+                       "",
+                       _("Our moderation team will carefully review your submission and you'll receive an update via email"
+                               " once a decision has been made. Please note that review times may vary depending on the volume of reports we receive."),
+                       "",
+                       _("We appreciate your contribution to keeping the internet safer."
+                               " Reports like yours are essential to maintaining the effectiveness of our service."),
+                       "",
+                       _("Best regards,"),
+                       "-%s" % _("DNSBL Moderation Team"),
+               )
+
+               # Send the email
+               reporter.sendmail("\n".join(lines), headers={
+                       "Subject" : _("Your DNSBL Report Has Been Received"),
+               })
+
        def _send_closing_notification(self):
                """
                        Sends a notification to the reporter when this report gets closed.