def register_permissions(): user_permissions = Q(content_type__app_label=AUTH_USER_APP_LABEL, codename__in=[ 'add_%s' % AUTH_USER_MODEL_NAME.lower(), 'change_%s' % AUTH_USER_MODEL_NAME.lower(), 'delete_%s' % AUTH_USER_MODEL_NAME.lower(), ]) group_permissions = Q(content_type__app_label='auth', codename__in=['add_group', 'change_group', 'delete_group']) return Permission.objects.filter(user_permissions | group_permissions)
def register_permissions(): user_permissions = Q(content_type__app_label=AUTH_USER_APP_LABEL, codename__in=[ 'add_%s' % AUTH_USER_MODEL_NAME.lower(), 'change_%s' % AUTH_USER_MODEL_NAME.lower(), 'delete_%s' % AUTH_USER_MODEL_NAME.lower(), ]) group_permissions = Q(content_type__app_label='auth', codename__in=['add_group', 'change_group', 'delete_group']) return Permission.objects.filter(user_permissions | group_permissions)
def register_permissions(): user_permissions = Q( content_type__app_label=AUTH_USER_APP_LABEL, codename__in=[ "add_%s" % AUTH_USER_MODEL_NAME.lower(), "change_%s" % AUTH_USER_MODEL_NAME.lower(), "delete_%s" % AUTH_USER_MODEL_NAME.lower(), ], ) group_permissions = Q( content_type__app_label="auth", codename__in=["add_group", "change_group", "delete_group"], ) return Permission.objects.filter(user_permissions | group_permissions)
import hashlib from django.conf import settings from django.utils.http import urlencode from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME delete_user_perm = "{0}.delete_{1}".format( AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower() ) def user_can_delete_user(current_user, user_to_delete): if not current_user.has_perm(delete_user_perm): return False if current_user == user_to_delete: # users may not delete themselves return False if user_to_delete.is_superuser and not current_user.is_superuser: # ordinary users may not delete superusers return False return True def get_gravatar_url(email, size=50): default = "mm" size = ( int(size) * 2
from wagtail.admin.auth import any_permission_required, permission_required from wagtail.admin.forms.search import SearchForm from wagtail.core import hooks from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME from wagtail.core.log_actions import log from wagtail.users.forms import UserCreationForm, UserEditForm from wagtail.users.utils import user_can_delete_user from wagtail.utils.loading import get_custom_form User = get_user_model() # 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()) def get_user_creation_form(): form_setting = "WAGTAIL_USER_CREATION_FORM" if hasattr(settings, form_setting): return get_custom_form(form_setting) else: return UserCreationForm def get_user_edit_form():
) else: group_view_set_cls = GroupViewSet return group_view_set_cls @hooks.register('register_admin_viewset') def register_viewset(): group_view_set_cls = get_group_view_set_cls() return group_view_set_cls('wagtailusers_groups', url_prefix='groups') # 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_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') def register_users_menu_item():
from wagtail.utils.pagination import paginate from wagtail.admin import messages from wagtail.admin.forms import SearchForm from wagtail.admin.utils import ( any_permission_required, permission_denied, permission_required) from wagtail.core import hooks from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME from wagtail.users.forms import UserCreationForm, UserEditForm from wagtail.users.utils import user_can_delete_user User = get_user_model() # 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()) def get_custom_user_form(form_setting): try: return import_string(getattr(settings, form_setting)) except ImportError: raise ImproperlyConfigured( "%s refers to a form '%s' that is not available" % (form_setting, getattr(settings, form_setting)) ) def get_user_creation_form():