mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Only show the link to notification preferences if the user has preferences to set
This commit is contained in:
parent
0cb60d6e27
commit
f910b1dbe8
@ -28,15 +28,17 @@
|
||||
</small>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="row row-flush">
|
||||
<div class="col6">
|
||||
<a href="{% url 'wagtailadmin_account_notification_preferences' %}" class="button button-primary">{% trans "Notification preferences" %}</a>
|
||||
</div>
|
||||
{% if show_notification_preferences %}
|
||||
<li class="row row-flush">
|
||||
<div class="col6">
|
||||
<a href="{% url 'wagtailadmin_account_notification_preferences' %}" class="button button-primary">{% trans "Notification preferences" %}</a>
|
||||
</div>
|
||||
|
||||
<small class="col6">
|
||||
{% trans "Choose which email notifications to receive." %}
|
||||
</small>
|
||||
</li>
|
||||
<small class="col6">
|
||||
{% trans "Choose which email notifications to receive." %}
|
||||
</small>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -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,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user