diff --git a/bookwyrm/migrations/0138_automod.py b/bookwyrm/migrations/0138_automod.py index 8b0369efa..691ea94bb 100644 --- a/bookwyrm/migrations/0138_automod.py +++ b/bookwyrm/migrations/0138_automod.py @@ -8,18 +8,32 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ('bookwyrm', '0137_alter_sitesettings_allow_registration'), + ("bookwyrm", "0137_alter_sitesettings_allow_registration"), ] operations = [ migrations.CreateModel( - name='AutoMod', + name="AutoMod", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('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)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("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/antispam.py b/bookwyrm/models/antispam.py index 43b524f63..e0d1aa4ef 100644 --- a/bookwyrm/models/antispam.py +++ b/bookwyrm/models/antispam.py @@ -71,22 +71,25 @@ def automod_users(reporter): users = User.objects.filter( reduce(operator.or_, (Q(**f) for f in filters)), is_active=True, - report__isnull=True, # don't flag users that already have reports + report__isnull=True, # don't flag users that already have reports ).values_list("id", flat=True) report_model = apps.get_model("bookwyrm", "Report", require_ready=True) - report_model.objects.bulk_create([ - report_model( - reporter=reporter, - note=_("Automatically generated report"), - user=u, - ) for u in users - ]) + report_model.objects.bulk_create( + [ + report_model( + reporter=reporter, + note=_("Automatically generated report"), + user=u, + ) + for u in users + ] + ) def automod_statuses(reporter): - """ check statues for moderation flags """ + """check statues for moderation flags""" status_rules = AutoMod.objects.filter(flag_statuses=True).values_list( "string_match", flat=True ) @@ -96,15 +99,18 @@ def automod_statuses(reporter): statuses = status_model.objects.filter( reduce(operator.or_, (Q(**f) for f in filters)), deleted=False, - report__isnull=True, # don't flag statuses that already have reports + report__isnull=True, # don't flag statuses that already have reports ) report_model = apps.get_model("bookwyrm", "Report", require_ready=True) - report_model.objects.bulk_create([ - report_model( - reporter=reporter, - note=_("Automatically generated report"), - user=s.user, - statuses=[s.id], - ) for s in statuses - ]) + report_model.objects.bulk_create( + [ + report_model( + reporter=reporter, + note=_("Automatically generated report"), + user=s.user, + statuses=[s.id], + ) + for s in statuses + ] + ) diff --git a/bookwyrm/templates/settings/automod/rules.html b/bookwyrm/templates/settings/automod/rules.html index 7555df2d6..d913d5964 100644 --- a/bookwyrm/templates/settings/automod/rules.html +++ b/bookwyrm/templates/settings/automod/rules.html @@ -17,7 +17,10 @@ {% 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." %}
- + {% if success %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 3c37eef55..d2caa76ea 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -216,7 +216,12 @@ urlpatterns = [ ), # auto-moderation rules re_path(r"^settings/automod/?$", views.AutoMod.as_view(), name="settings-automod"), - re_path(r"^settings/automod/(?P