0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Show groups menu item iff user has add, change or delete permission on groups (rather than checking 'auth' permissions en masse)

This commit is contained in:
Matt Westcott 2015-08-13 15:34:25 +02:00
parent 90b009583e
commit e1f4b9a68c

View File

@ -18,19 +18,28 @@ def register_admin_urls():
]
class AuthMenuItem(MenuItem):
class UsersMenuItem(MenuItem):
def is_shown(self, request):
return request.user.has_module_perms('auth')
@hooks.register('register_settings_menu_item')
def register_users_menu_item():
return AuthMenuItem(_('Users'), urlresolvers.reverse('wagtailusers_users:index'), classnames='icon icon-user', order=600)
return UsersMenuItem(_('Users'), urlresolvers.reverse('wagtailusers_users:index'), classnames='icon icon-user', order=600)
class GroupsMenuItem(MenuItem):
def is_shown(self, request):
return (
request.user.has_perm('auth.add_group')
or request.user.has_perm('auth.change_group')
or request.user.has_perm('auth.delete_group')
)
@hooks.register('register_settings_menu_item')
def register_groups_menu_item():
return AuthMenuItem(_('Groups'), urlresolvers.reverse('wagtailusers_groups:index'), classnames='icon icon-group', order=601)
return GroupsMenuItem(_('Groups'), urlresolvers.reverse('wagtailusers_groups:index'), classnames='icon icon-group', order=601)
@hooks.register('register_permissions')