From be164048b84754480ba6fe175449329e7f65b198 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 25 Oct 2017 18:54:51 +0100 Subject: [PATCH] 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. --- CHANGELOG.txt | 1 + CONTRIBUTORS.rst | 1 + docs/advanced_topics/settings.rst | 8 +++++--- docs/releases/2.0.rst | 2 ++ wagtail/admin/tests/test_pages_views.py | 21 ++++++++++++++++++++- wagtail/admin/utils.py | 3 ++- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0f5866a9ca..95292bb006 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index c3153d06c9..08b88ebc0c 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -266,6 +266,7 @@ Contributors * Michael Palmer * Philipp Bosch * misraX +* Bruno Alla Translators =========== diff --git a/docs/advanced_topics/settings.rst b/docs/advanced_topics/settings.rst index f0cb3f3058..32b07310a6 100644 --- a/docs/advanced_topics/settings.rst +++ b/docs/advanced_topics/settings.rst @@ -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: diff --git a/docs/releases/2.0.rst b/docs/releases/2.0.rst index 635bbee27e..3633304ea6 100644 --- a/docs/releases/2.0.rst +++ b/docs/releases/2.0.rst @@ -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 ~~~~~~~~~ diff --git a/wagtail/admin/tests/test_pages_views.py b/wagtail/admin/tests/test_pages_views.py index 3f8b3bcf18..8d136f8e45 100644 --- a/wagtail/admin/tests/test_pages_views.py +++ b/wagtail/admin/tests/test_pages_views.py @@ -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) diff --git a/wagtail/admin/utils.py b/wagtail/admin/utils.py index 6e6aab0b26..899b1eccc5 100644 --- a/wagtail/admin/utils.py +++ b/wagtail/admin/utils.py @@ -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]