From f910b1dbe8faa25f0c6ad1363aa43e6297afd0ad Mon Sep 17 00:00:00 2001 From: Nick Smith Date: Fri, 20 Jun 2014 15:54:19 +0100 Subject: [PATCH] Only show the link to notification preferences if the user has preferences to set --- .../wagtailadmin/account/account.html | 18 ++++++++++-------- wagtail/wagtailadmin/views/account.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/account/account.html b/wagtail/wagtailadmin/templates/wagtailadmin/account/account.html index 21688ce37..f543d66dc 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/account/account.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/account/account.html @@ -28,15 +28,17 @@ {% endif %} -
  • - + {% if show_notification_preferences %} +
  • + - - {% trans "Choose which email notifications to receive." %} - -
  • + + {% trans "Choose which email notifications to receive." %} + + + {% endif %} {% endblock %} diff --git a/wagtail/wagtailadmin/views/account.py b/wagtail/wagtailadmin/views/account.py index d5ab71bd6..c5cf6ffae 100644 --- a/wagtail/wagtailadmin/views/account.py +++ b/wagtail/wagtailadmin/views/account.py @@ -10,12 +10,17 @@ from django.views.decorators.cache import never_cache from wagtail.wagtailadmin import forms from wagtail.wagtailusers.forms import NotificationPreferencesForm +from wagtail.wagtailcore.models import UserPagePermissionsProxy @permission_required('wagtailadmin.access_admin') def account(request): + user_perms = UserPagePermissionsProxy(request.user) + show_notification_preferences = user_perms.can_edit_pages() or user_perms.can_publish_pages() + return render(request, 'wagtailadmin/account/account.html', { 'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(), + 'show_notification_preferences': show_notification_preferences }) @@ -56,6 +61,11 @@ def notification_preferences(request): else: form = NotificationPreferencesForm(instance=request.user.get_profile()) + # quick-and-dirty catch-all in case the form has been rendered with no + # fields, as the user has no customisable permissions + if not form.fields: + return redirect('wagtailadmin_account') + return render(request, 'wagtailadmin/account/notification_preferences.html', { 'form': form, })