Users may only report a post once per IP address.

If a user *really* doesn't like a post, they may try to report it
multiple times. Users may now only report a single post once per IP
address.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-07-13 12:35:57 -07:00
parent f131c58d1b
commit f04604ce69
3 changed files with 7 additions and 1 deletions

View File

@@ -101,6 +101,8 @@ class ReportForm(ModelForm):
record = ReportRecord.objects.get(post=self.op)
except ReportRecord.DoesNotExist:
record = ReportRecord.objects.create(post=self.op)
if record.report_set.filter(ip=self.instance.ip):
raise ValidationError(_("You have already reported this post."))
self.instance.record = record
return super(ReportForm, self).clean()

View File

@@ -281,6 +281,11 @@ class Report(models.Model):
they are abusing the system.
"""
class Meta:
unique_together = [
["record", "ip"],
]
# The report that was made by this user
record = models.ForeignKey("ReportRecord", on_delete=models.CASCADE)
# Reason for this report

View File

@@ -200,7 +200,6 @@ function openReportWindow(reportUrl) {
});
$(reportWindow.iframe, "iframe").on("load", () => {
fitWindowToContent(reportWindow);
reportWindow.setResizable(false);
});
reportWindow.show();
}