Skip to content

Commit

Permalink
Add ability to hide 'Submit for Moderation' in action menu using sett…
Browse files Browse the repository at this point in the history
…ing WAGTAIL_MODERATION_ENABLED. When set to false, SubmitForModerationMenuItem method is_shown returns false (#5574)
  • Loading branch information
jacobtoppm authored and gasman committed Sep 24, 2019
1 parent 1b2dadc commit a7b470b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Changelog
* Add `WAGTAIL_EMAIL_MANAGEMENT_ENABLED` setting to determine whether users can change their email address (Janne Alatalo)
* Recognise Soundcloud artist URLs as embeddable (Kiril Staikov)
* Add `WAGTAILDOCS_SERVE_METHOD` setting to determine how document downloads will be linked to and served (Tobias McNulty, Matt Westcott)
* Add `WAGTAIL_MODERATION_ENABLED` setting to enable / disable the 'Submit for Moderation' option (Jacob Topp-Mugglestone)
* Fix: Added line breaks to long filenames on multiple image / document uploader (Kevin Howbrook)
* Fix: Added https support for Scribd oEmbed provider (Rodrigo)
* Fix: Changed StreamField group labels color so labels are visible (Catherine Farman)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ Contributors
* Saptak Sengupta
* Dawid Bugajewski
* Dawn Wages
* Jacob Topp-Mugglestone

Translators
===========
Expand Down
8 changes: 8 additions & 0 deletions docs/advanced_topics/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ Allows the default ``LoginForm`` to be extended with extra fields.
If a user has not uploaded a profile picture, Wagtail will look for an avatar linked to their email address on gravatar.com. This setting allows you to specify an alternative provider such as like robohash.org, or can be set to ``None`` to disable the use of remote avatars completely.


.. code-block:: python
WAGTAIL_MODERATION_ENABLED = True
Changes whether the Submit for Moderation button is displayed in the action menu.



Images
------

Expand Down
1 change: 1 addition & 0 deletions docs/releases/2.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Other features
* Add ``WAGTAIL_EMAIL_MANAGEMENT_ENABLED`` setting to determine whether users can change their email address (Janne Alatalo)
* Recognise Soundcloud artist URLs as embeddable (Kiril Staikov)
* Add ``WAGTAILDOCS_SERVE_METHOD`` setting to determine how document downloads will be linked to and served (Tobias McNulty, Matt Westcott)
* Add ``WAGTAIL_MODERATION_ENABLED`` setting to enable / disable the 'Submit for Moderation' option (Jacob Topp-Mugglestone)


Bug fixes
Expand Down
6 changes: 5 additions & 1 deletion wagtail/admin/action_menu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Handles rendering of the list of actions in the footer of the page create/edit views."""

from django.conf import settings
from django.forms import Media, MediaDefiningClass
from django.template.loader import render_to_string
from django.urls import reverse
Expand Down Expand Up @@ -79,7 +80,10 @@ class SubmitForModerationMenuItem(ActionMenuItem):
name = 'action-submit'

def is_shown(self, request, context):
if context['view'] == 'create':
WAGTAIL_MODERATION_ENABLED = getattr(settings, 'WAGTAIL_MODERATION_ENABLED', True)
if not WAGTAIL_MODERATION_ENABLED:
return False
elif context['view'] == 'create':
return True
elif context['view'] == 'edit':
return not context['page'].locked
Expand Down
16 changes: 16 additions & 0 deletions wagtail/admin/tests/pages/test_create_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.core import mail
from django.http import HttpRequest, HttpResponse
from django.test import TestCase
from django.test.utils import override_settings
from django.urls import reverse
from django.utils import timezone

Expand Down Expand Up @@ -666,6 +667,21 @@ def hook_func(request, page):
# page should be created
self.assertTrue(Page.objects.filter(title="New page!").exists())

def test_display_moderation_button_by_default(self):
"""
Tests that by default the "Submit for Moderation" button is shown in the action menu.
"""
response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', self.root_page.id)))
self.assertContains(response, '<input type="submit" name="action-submit" value="Submit for moderation" class="button" />')

@override_settings(WAGTAIL_MODERATION_ENABLED=False)
def test_hide_moderation_button(self):
"""
Tests that if WAGTAIL_MODERATION_ENABLED is set to False, the "Submit for Moderation" button is not shown.
"""
response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', self.root_page.id)))
self.assertNotContains(response, '<input type="submit" name="action-submit" value="Submit for moderation" class="button" />')


class TestPerRequestEditHandler(TestCase, WagtailTestUtils):
fixtures = ['test.json']
Expand Down

0 comments on commit a7b470b

Please sign in to comment.