Add setting to disable notification to superusers -- Fixes #3969

WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS, default to True
If set to False, superusers do not receive moderation notification,
only moderators do.
pull/4119/merge
Bruno Alla 2017-10-25 18:54:51 +01:00 zatwierdzone przez Matt Westcott
rodzic 713520d197
commit be164048b8
6 zmienionych plików z 31 dodań i 5 usunięć

Wyświetl plik

@ -34,6 +34,7 @@ Changelog
* FormPage lists and Form submission lists in admin now use class based views for easy overriding (Johan Arensman)
* Form submission csv exports now have the export date in the filename and can be customized (Johan Arensman)
* FormBuilder class now uses bound methods for field generation, adding custom fields is now easier and documented (LB (Ben) Johnston)
* Added `WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS` setting to determine whether superusers are included in moderation email notifications (Bruno Alla)
* Fix: Do not remove stopwords when generating slugs from non-ASCII titles, to avoid issues with incorrect word boundaries (Sævar Öfjörð Magnússon)
* Fix: The PostgreSQL search backend now preserves ordering of the `QuerySet` when searching with `order_by_relevance=False` (Bertrand Bordage)
* Fix: Using `modeladmin_register` as a decorator no longer replaces the decorated class with `None` (Tim Heap)

Wyświetl plik

@ -266,6 +266,7 @@ Contributors
* Michael Palmer
* Philipp Bosch
* misraX
* Bruno Alla
Translators
===========

Wyświetl plik

@ -290,15 +290,17 @@ Wagtail sends email notifications when content is submitted for moderation, and
.. _email_notifications_format:
Email Notifications format
--------------------------
.. code-block:: python
WAGTAILADMIN_NOTIFICATION_USE_HTML = True
Notification emails are sent in `text/plain` by default, change this to use HTML formatting.
.. code-block:: python
WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS = False
Notification emails are sent to moderators and superusers by default. You can change this to exclude superusers and only notify moderators.
.. _update_notifications:

Wyświetl plik

@ -51,6 +51,8 @@ Other features
* FormPage lists and Form submission lists in admin now use class based views for easy overriding (Johan Arensman)
* Form submission csv exports now have the export date in the filename and can be customized (Johan Arensman)
* FormBuilder class now uses bound methods for field generation, adding custom fields is now easier and documented (LB (Ben Johnston))
* Added ``WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS`` setting to determine whether superusers are included in moderation email notifications (Bruno Alla)
Bug fixes
~~~~~~~~~

Wyświetl plik

@ -1,6 +1,7 @@
import datetime
import logging
import os
from itertools import chain
import mock
from django.conf import settings
@ -12,7 +13,7 @@ from django.core import mail, paginator
from django.core.files.base import ContentFile
from django.db.models.signals import post_delete, pre_delete
from django.http import HttpRequest, HttpResponse
from django.test import TestCase, modify_settings
from django.test import TestCase, modify_settings, override_settings
from django.urls import reverse
from django.utils import formats, timezone
from django.utils.dateparse import parse_date
@ -3188,6 +3189,24 @@ class TestNotificationPreferences(TestCase, WagtailTestUtils):
self.assertIn(user1.email, email_to)
self.assertIn(user2.email, email_to)
@override_settings(WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS=False)
def test_disable_superuser_notification(self):
# Add one of the superusers to the moderator group
self.moderator.groups.add(Group.objects.get(name='Moderators'))
response = self.submit()
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
# Check that the non-moderator superuser is not being notified
expected_emails = 1
self.assertEqual(len(mail.outbox), expected_emails)
# Use chain as the 'to' field is a list of recipients
email_to = list(chain.from_iterable([m.to for m in mail.outbox]))
self.assertIn(self.moderator.email, email_to)
self.assertNotIn(self.moderator2.email, email_to)
@mock.patch('wagtail.admin.utils.django_send_mail', side_effect=IOError('Server down'))
def test_email_send_error(self, mock_fn):
logging.disable(logging.CRITICAL)

Wyświetl plik

@ -213,7 +213,8 @@ def send_notification(page_revision_id, notification, excluded_user_id):
# Get list of recipients
if notification == 'submitted':
# Get list of publishers
recipients = users_with_page_permission(revision.page, 'publish')
include_superusers = getattr(settings, 'WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS', True)
recipients = users_with_page_permission(revision.page, 'publish', include_superusers)
elif notification in ['rejected', 'approved']:
# Get submitter
recipients = [revision.user]