diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 865bc02fe..f2e3f9bbe 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -550,3 +550,9 @@ class ReadThroughForm(CustomForm): class Meta: model = models.ReadThrough fields = ["user", "book", "start_date", "finish_date"] + + +class AutoModRuleForm(CustomForm): + class Meta: + model = models.AutoMod + fields = ["string_match", "flag_users", "flag_statuses", "created_by"] diff --git a/bookwyrm/migrations/0138_autoflag.py b/bookwyrm/migrations/0138_automod.py similarity index 71% rename from bookwyrm/migrations/0138_autoflag.py rename to bookwyrm/migrations/0138_automod.py index b1e803d43..8b0369efa 100644 --- a/bookwyrm/migrations/0138_autoflag.py +++ b/bookwyrm/migrations/0138_automod.py @@ -1,7 +1,6 @@ -# Generated by Django 3.2.12 on 2022-02-18 04:53 +# Generated by Django 3.2.12 on 2022-02-24 18:59 from django.conf import settings -import django.contrib.postgres.fields from django.db import migrations, models import django.db.models.deletion @@ -14,12 +13,12 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='AutoFlag', + name='AutoMod', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('flag_users', models.BooleanField(default=False)), - ('flag_statuses', models.BooleanField(default=False)), - ('string_match', models.CharField(max_length=200)), + ('string_match', models.CharField(max_length=200, unique=True)), + ('flag_users', models.BooleanField(default=True)), + ('flag_statuses', models.BooleanField(default=True)), ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), ], ), diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index 4c6305f99..1dc6825e4 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -29,7 +29,7 @@ from .import_job import ImportJob, ImportItem from .site import SiteSettings, SiteInvite from .site import PasswordReset, InviteRequest from .announcement import Announcement -from .antispam import EmailBlocklist, IPBlocklist +from .antispam import EmailBlocklist, IPBlocklist, AutoMod from .notification import Notification diff --git a/bookwyrm/models/antispam.py b/bookwyrm/models/antispam.py index 98587a47d..be1050b3a 100644 --- a/bookwyrm/models/antispam.py +++ b/bookwyrm/models/antispam.py @@ -35,9 +35,9 @@ class IPBlocklist(models.Model): ordering = ("-created_date",) -class AutoFlag(models.Model): +class AutoMod(models.Model): """rules to automatically flag suspicious activity""" + string_match = models.CharField(max_length=200, unique=True) + flag_users = models.BooleanField(default=True) + flag_statuses = models.BooleanField(default=True) created_by = models.ForeignKey("User", on_delete=models.PROTECT) - flag_users = models.BooleanField(default=False) - flag_statuses = models.BooleanField(default=False) - string_match = models.CharField(max_length=200) diff --git a/bookwyrm/templates/settings/automod/rules.html b/bookwyrm/templates/settings/automod/rules.html new file mode 100644 index 000000000..7555df2d6 --- /dev/null +++ b/bookwyrm/templates/settings/automod/rules.html @@ -0,0 +1,91 @@ +{% extends 'settings/layout.html' %} +{% load i18n %} +{% load utilities %} + +{% block title %} +{% trans "Auto-moderation rules" %} +{% endblock %} + +{% block header %} +{% trans "Auto-moderation rules" %} +{% endblock %} + +{% block panel %} + +
+ {% trans "Auto-moderation rules will create reports for any user or status with fields matching the provided string." %} + {% trans "At this time, reports are not being generated automatically, and you must manually trigger a scan." %} +
+ +
+ {{ rule.string_match }}
+ |
+ + {{ rule.flag_users|yesno }} + | ++ {{ rule.flag_statuses|yesno }} + | ++ + | +