diff --git a/apps/tup-cms/src/apps/portal/views.py b/apps/tup-cms/src/apps/portal/views.py index d688e192f..af9a684b6 100644 --- a/apps/tup-cms/src/apps/portal/views.py +++ b/apps/tup-cms/src/apps/portal/views.py @@ -34,7 +34,11 @@ def LogoutView(request): def ImpersonateView(request): resp = HttpResponseRedirect("/portal/dashboard") - if not request.user.is_superuser: + + if not request.user: + return resp + + if not request.user.groups.filter(name='Impersonator').exists(): return resp headers = {"x-tup-token": settings.TUP_SERVICES_ADMIN_JWT} diff --git a/apps/tup-cms/src/apps/portal_nav/templates/portal_nav/nav_portal.raw.html b/apps/tup-cms/src/apps/portal_nav/templates/portal_nav/nav_portal.raw.html index aaa3f8261..dfef38819 100644 --- a/apps/tup-cms/src/apps/portal_nav/templates/portal_nav/nav_portal.raw.html +++ b/apps/tup-cms/src/apps/portal_nav/templates/portal_nav/nav_portal.raw.html @@ -39,7 +39,7 @@ Manage Account - {% if user.is_superuser %} + {% if show_impersonation %} Impersonate User diff --git a/apps/tup-cms/src/apps/portal_nav/views.py b/apps/tup-cms/src/apps/portal_nav/views.py index 97cd2113f..d3855edbf 100644 --- a/apps/tup-cms/src/apps/portal_nav/views.py +++ b/apps/tup-cms/src/apps/portal_nav/views.py @@ -5,6 +5,9 @@ def PortalNavView(request): user = authenticate(request) - context = {'user': user} + is_impersonator = False + if user: + is_impersonator = user.groups.filter(name='Impersonator').exists() + context = {'user': user, 'show_impersonation': is_impersonator} template = loader.get_template('portal_nav/nav_portal.raw.html') return HttpResponse(template.render(context, request))