diff --git a/wagtail/wagtailusers/views/users.py b/wagtail/wagtailusers/views/users.py index 78da0c456c..0e0b145e5c 100644 --- a/wagtail/wagtailusers/views/users.py +++ b/wagtail/wagtailusers/views/users.py @@ -8,19 +8,21 @@ from django.views.decorators.vary import vary_on_headers from wagtail.wagtailadmin import messages from wagtail.wagtailadmin.forms import SearchForm -from wagtail.wagtailadmin.utils import permission_required +from wagtail.wagtailadmin.utils import permission_required, any_permission_required from wagtail.wagtailusers.forms import UserCreationForm, UserEditForm from wagtail.wagtailcore.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME User = get_user_model() -# Typically we would check the permission 'auth.change_user' for user -# management actions, but this may vary according to the AUTH_USER_MODEL -# setting +# Typically we would check the permission 'auth.change_user' (and 'auth.add_user' / +# 'auth.delete_user') for user management actions, but this may vary according to +# the AUTH_USER_MODEL setting +add_user_perm = "{0}.add_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower()) change_user_perm = "{0}.change_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower()) +delete_user_perm = "{0}.delete_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower()) -@permission_required(change_user_perm) +@any_permission_required(add_user_perm, change_user_perm, delete_user_perm) @vary_on_headers('X-Requested-With') def index(request): q = None @@ -81,7 +83,7 @@ def index(request): }) -@permission_required(change_user_perm) +@permission_required(add_user_perm) def create(request): if request.POST: form = UserCreationForm(request.POST) diff --git a/wagtail/wagtailusers/wagtail_hooks.py b/wagtail/wagtailusers/wagtail_hooks.py index e946e626db..d5fbb900d3 100644 --- a/wagtail/wagtailusers/wagtail_hooks.py +++ b/wagtail/wagtailusers/wagtail_hooks.py @@ -5,6 +5,7 @@ from django.contrib.contenttypes.models import ContentType from django.utils.translation import ugettext_lazy as _ from wagtail.wagtailcore import hooks +from wagtail.wagtailcore.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME from wagtail.wagtailadmin.menu import MenuItem from wagtail.wagtailusers.urls import users, groups @@ -18,9 +19,21 @@ def register_admin_urls(): ] +# Typically we would check the permission 'auth.change_user' (and 'auth.add_user' / +# 'auth.delete_user') for user management actions, but this may vary according to +# the AUTH_USER_MODEL setting +add_user_perm = "{0}.add_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower()) +change_user_perm = "{0}.change_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower()) +delete_user_perm = "{0}.delete_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower()) + + class UsersMenuItem(MenuItem): def is_shown(self, request): - return request.user.has_module_perms('auth') + return ( + request.user.has_perm(add_user_perm) + or request.user.has_perm(change_user_perm) + or request.user.has_perm(delete_user_perm) + ) @hooks.register('register_settings_menu_item')