mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-22 23:18:08 +00:00
Merge pull request #2300 from bookwyrm-social/notification
Fixes creating notifications for automod reports
This commit is contained in:
commit
d023f71058
5 changed files with 17 additions and 12 deletions
|
@ -61,17 +61,14 @@ def automod_task():
|
|||
if not reports:
|
||||
return
|
||||
|
||||
admins = User.objects.filter(
|
||||
models.Q(user_permissions__name__in=["moderate_user", "moderate_post"])
|
||||
| models.Q(is_superuser=True)
|
||||
).all()
|
||||
admins = User.admins()
|
||||
notification_model = apps.get_model("bookwyrm", "Notification", require_ready=True)
|
||||
with transaction.atomic():
|
||||
for admin in admins:
|
||||
notification, _ = notification_model.objects.get_or_create(
|
||||
user=admin, notification_type=notification_model.REPORT, read=False
|
||||
)
|
||||
notification.related_repors.add(reports)
|
||||
notification.related_reports.set(reports)
|
||||
|
||||
|
||||
def automod_users(reporter):
|
||||
|
|
|
@ -231,10 +231,7 @@ def notify_admins_on_report(sender, instance, created, *args, **kwargs):
|
|||
return
|
||||
|
||||
# moderators and superusers should be notified
|
||||
admins = User.objects.filter(
|
||||
models.Q(user_permissions__name__in=["moderate_user", "moderate_post"])
|
||||
| models.Q(is_superuser=True)
|
||||
).all()
|
||||
admins = User.admins()
|
||||
for admin in admins:
|
||||
notification, _ = Notification.objects.get_or_create(
|
||||
user=admin,
|
||||
|
|
|
@ -231,6 +231,14 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
queryset = queryset.exclude(blocks=viewer)
|
||||
return queryset
|
||||
|
||||
@classmethod
|
||||
def admins(cls):
|
||||
"""Get a queryset of the admins for this instance"""
|
||||
return cls.objects.filter(
|
||||
models.Q(user_permissions__name__in=["moderate_user", "moderate_post"])
|
||||
| models.Q(is_superuser=True)
|
||||
)
|
||||
|
||||
def update_active_date(self):
|
||||
"""this user is here! they are doing things!"""
|
||||
self.last_active_date = timezone.now()
|
||||
|
|
|
@ -14,6 +14,7 @@ from bookwyrm.models.antispam import automod_task
|
|||
class AutomodModel(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
|
@ -26,6 +27,7 @@ class AutomodModel(TestCase):
|
|||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
is_superuser=True,
|
||||
)
|
||||
|
||||
def test_automod_task_no_rules(self, *_):
|
||||
|
@ -33,6 +35,7 @@ class AutomodModel(TestCase):
|
|||
self.assertFalse(models.Report.objects.exists())
|
||||
automod_task()
|
||||
self.assertFalse(models.Report.objects.exists())
|
||||
self.assertFalse(models.Notification.objects.exists())
|
||||
|
||||
def test_automod_task_user(self, *_):
|
||||
"""scan activity"""
|
||||
|
@ -52,6 +55,7 @@ class AutomodModel(TestCase):
|
|||
reports = models.Report.objects.all()
|
||||
self.assertEqual(reports.count(), 1)
|
||||
self.assertEqual(reports.first().user, self.local_user)
|
||||
self.assertEqual(models.Notification.objects.count(), 1)
|
||||
|
||||
def test_automod_status(self, *_):
|
||||
"""scan activity"""
|
||||
|
@ -73,3 +77,4 @@ class AutomodModel(TestCase):
|
|||
self.assertEqual(reports.count(), 1)
|
||||
self.assertEqual(reports.first().status, status)
|
||||
self.assertEqual(reports.first().user, self.local_user)
|
||||
self.assertEqual(models.Notification.objects.count(), 1)
|
||||
|
|
|
@ -19,9 +19,7 @@ def about(request):
|
|||
"status_count": models.Status.objects.filter(
|
||||
user__local=True, deleted=False
|
||||
).count(),
|
||||
"admins": models.User.objects.filter(
|
||||
groups__name__in=["admin", "moderator"]
|
||||
).distinct(),
|
||||
"admins": models.User.admins(),
|
||||
"version": settings.VERSION,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue