Notify admins when a report is filed
This commit is contained in:
parent
37dd661e49
commit
e5750de3dd
4 changed files with 60 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
""" flagged for moderation """
|
||||
from django.apps import apps
|
||||
from django.db import models
|
||||
from django.db.models import F, Q
|
||||
from .base_model import BookWyrmModel
|
||||
|
@ -15,6 +16,24 @@ class Report(BookWyrmModel):
|
|||
statuses = models.ManyToManyField("Status", blank=True)
|
||||
resolved = models.BooleanField(default=False)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
""" notify admins when a report is created """
|
||||
super().save(*args, **kwargs)
|
||||
user_model = apps.get_model("bookwyrm.User", require_ready=True)
|
||||
# moderators and superusers should be notified
|
||||
admins = user_model.objects.filter(
|
||||
Q(user_permissions__name__in=["moderate_user", "moderate_post"]) |
|
||||
Q(is_superuser=True)
|
||||
).all()
|
||||
notification_model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
||||
for admin in admins:
|
||||
notification_model.objects.create(
|
||||
user=admin,
|
||||
related_report=self,
|
||||
notification_type="REPORT",
|
||||
)
|
||||
|
||||
|
||||
class Meta:
|
||||
""" don't let users report themselves """
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue