Fix bug with forcing a user to exist on request

Allow for testing views without having to mock a user on the request.
pull/2985/head^2
digia 2016-09-02 17:58:06 -04:00 zatwierdzone przez Matt Westcott
rodzic 6c57aba8a2
commit 875d2fcbd4
2 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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(),