mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-04 16:09:54 +00:00
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
32
bookwyrm/migrations/0051_auto_20210316_1950.py
Normal file
32
bookwyrm/migrations/0051_auto_20210316_1950.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# Generated by Django 3.0.7 on 2021-03-16 19:50
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bookwyrm', '0050_auto_20210313_0030'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveConstraint(
|
||||||
|
model_name='notification',
|
||||||
|
name='notification_type_valid',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='notification',
|
||||||
|
name='related_report',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='bookwyrm.Report'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='notification',
|
||||||
|
name='notification_type',
|
||||||
|
field=models.CharField(choices=[('FAVORITE', 'Favorite'), ('REPLY', 'Reply'), ('MENTION', 'Mention'), ('TAG', 'Tag'), ('FOLLOW', 'Follow'), ('FOLLOW_REQUEST', 'Follow Request'), ('BOOST', 'Boost'), ('IMPORT', 'Import'), ('ADD', 'Add'), ('REPORT', 'Report')], max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AddConstraint(
|
||||||
|
model_name='notification',
|
||||||
|
constraint=models.CheckConstraint(check=models.Q(notification_type__in=['FAVORITE', 'REPLY', 'MENTION', 'TAG', 'FOLLOW', 'FOLLOW_REQUEST', 'BOOST', 'IMPORT', 'ADD', 'REPORT']), name='notification_type_valid'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -5,7 +5,7 @@ from .base_model import BookWyrmModel
|
||||||
|
|
||||||
NotificationType = models.TextChoices(
|
NotificationType = models.TextChoices(
|
||||||
"NotificationType",
|
"NotificationType",
|
||||||
"FAVORITE REPLY MENTION TAG FOLLOW FOLLOW_REQUEST BOOST IMPORT ADD",
|
"FAVORITE REPLY MENTION TAG FOLLOW FOLLOW_REQUEST BOOST IMPORT ADD REPORT",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ class Notification(BookWyrmModel):
|
||||||
related_list_item = models.ForeignKey(
|
related_list_item = models.ForeignKey(
|
||||||
"ListItem", on_delete=models.CASCADE, null=True
|
"ListItem", on_delete=models.CASCADE, null=True
|
||||||
)
|
)
|
||||||
|
related_report = models.ForeignKey("Report", on_delete=models.CASCADE, null=True)
|
||||||
read = models.BooleanField(default=False)
|
read = models.BooleanField(default=False)
|
||||||
notification_type = models.CharField(
|
notification_type = models.CharField(
|
||||||
max_length=255, choices=NotificationType.choices
|
max_length=255, choices=NotificationType.choices
|
||||||
|
@ -37,6 +38,7 @@ class Notification(BookWyrmModel):
|
||||||
related_status=self.related_status,
|
related_status=self.related_status,
|
||||||
related_import=self.related_import,
|
related_import=self.related_import,
|
||||||
related_list_item=self.related_list_item,
|
related_list_item=self.related_list_item,
|
||||||
|
related_report=self.related_report,
|
||||||
notification_type=self.notification_type,
|
notification_type=self.notification_type,
|
||||||
).exists():
|
).exists():
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" flagged for moderation """
|
""" flagged for moderation """
|
||||||
|
from django.apps import apps
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import F, Q
|
from django.db.models import F, Q
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
|
@ -15,6 +16,24 @@ class Report(BookWyrmModel):
|
||||||
statuses = models.ManyToManyField("Status", blank=True)
|
statuses = models.ManyToManyField("Status", blank=True)
|
||||||
resolved = models.BooleanField(default=False)
|
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:
|
class Meta:
|
||||||
""" don't let users report themselves """
|
""" don't let users report themselves """
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
<span class="icon icon-list"></span>
|
<span class="icon icon-list"></span>
|
||||||
{% elif notification.notification_type == 'ADD' %}
|
{% elif notification.notification_type == 'ADD' %}
|
||||||
<span class="icon icon-plus"></span>
|
<span class="icon icon-plus"></span>
|
||||||
|
{% elif notification.notification_type == 'REPORT' %}
|
||||||
|
<span class="icon icon-warning"></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
|
@ -105,7 +107,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif notification.related_import %}
|
{% elif notification.related_import %}
|
||||||
{% blocktrans with related_id=notification.related_import.id %} your <a href="/import/{{ related_id }}">import</a> completed.{% endblocktrans %}
|
{% blocktrans with related_id=notification.related_import.id %}Your <a href="/import/{{ related_id }}">import</a> completed.{% endblocktrans %}
|
||||||
|
{% elif notification.related_report %}
|
||||||
|
{% url 'settings-report' notification.related_report.id as path %}
|
||||||
|
{% blocktrans with related_id=path %}A new <a href="{{ path }}">report</a> needs moderation.{% endblocktrans %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue