mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Updates reports created in automod task
This commit is contained in:
parent
62e57ac931
commit
dc8e61f316
1 changed files with 13 additions and 18 deletions
|
@ -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):
|
||||||
|
|
Loading…
Reference in a new issue