Fix bug with forcing a user to exist on request

Allow for testing views without having to mock a user on the request.
This commit is contained in:
digia 2016-09-02 17:58:06 -04:00 committed by Matt Westcott
parent 6c57aba8a2
commit 875d2fcbd4
2 changed files with 8 additions and 1 deletions

View file

@ -163,6 +163,7 @@ Contributors
* Jesse Legg
* Tim Leguijt
* Luiz Boaretto
* Jonathon Moore
Translators
===========

View file

@ -36,8 +36,14 @@ def wagtailuserbar(context, position='bottom-right'):
except KeyError:
return ''
# Don't render without a user because we can't check their permissions
try:
user = request.user
except AttributeError:
return ''
# Don't render if user doesn't have permission to access the admin area
if not request.user.has_perm('wagtailadmin.access_admin'):
if not user.has_perm('wagtailadmin.access_admin'):
return ''
# Don't render if this is a preview. Since some routes can render the userbar without going through Page.serve(),