diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 90af4ec829..a5c0b0142b 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -163,6 +163,7 @@ Contributors * Jesse Legg * Tim Leguijt * Luiz Boaretto +* Jonathon Moore Translators =========== diff --git a/wagtail/wagtailadmin/templatetags/wagtailuserbar.py b/wagtail/wagtailadmin/templatetags/wagtailuserbar.py index a8e62cdd0f..ab31e72fe0 100644 --- a/wagtail/wagtailadmin/templatetags/wagtailuserbar.py +++ b/wagtail/wagtailadmin/templatetags/wagtailuserbar.py @@ -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(),