Updates reports created in automod task

This commit is contained in:
Mouse Reeve 2022-07-04 19:57:58 -07:00
parent 62e57ac931
commit dc8e61f316

View file

@ -3,7 +3,7 @@ from functools import reduce
import operator import operator
from django.apps import apps from django.apps import apps
from django.db import models from django.db import models, transaction
from django.db.models import Q from django.db.models import Q
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -58,25 +58,20 @@ def automod_task():
return return
reporter = AutoMod.objects.first().created_by reporter = AutoMod.objects.first().created_by
reports = automod_users(reporter) + automod_statuses(reporter) reports = automod_users(reporter) + automod_statuses(reporter)
if reports: if not reports:
admins = User.objects.filter( return
models.Q(user_permissions__name__in=["moderate_user", "moderate_post"])
| models.Q(is_superuser=True) admins = User.objects.filter(
).all() models.Q(user_permissions__name__in=["moderate_user", "moderate_post"])
notification_model = apps.get_model( | models.Q(is_superuser=True)
"bookwyrm", "Notification", require_ready=True ).all()
) notification_model = apps.get_model("bookwyrm", "Notification", require_ready=True)
with transaction.atomic():
for admin in admins: for admin in admins:
notification_model.objects.bulk_create( notification, _ = notification_model.objects.get_or_create(
[ user=admin, notification_type="REPORT", unread=True
notification_model(
user=admin,
related_report=r,
notification_type="REPORT",
)
for r in reports
]
) )
notification.related_repors.add(reports)
def automod_users(reporter): def automod_users(reporter):