Skip to content

Commit

Permalink
task/TUP-511: Use a specific Impersonator group to manage impersonati…
Browse files Browse the repository at this point in the history
…on permissions. (#244)

* only allow impersonation if users belong to the Impersonator group

* handle case where user doesn't exist

---------

Co-authored-by: Jake Rosenberg <[email protected]>
Co-authored-by: Wesley B <[email protected]>
  • Loading branch information
3 people authored Jun 15, 2023
1 parent 59214c5 commit 19e87bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion apps/tup-cms/src/apps/portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<a class="dropdown-item" href="/portal/account">
<i class="icon icon-user"></i> Manage Account
</a>
{% if user.is_superuser %}
{% if show_impersonation %}
<a class="dropdown-item" href="/portal/impersonation">
<i class="icon icon-user"></i> Impersonate User
</a>
Expand Down
5 changes: 4 additions & 1 deletion apps/tup-cms/src/apps/portal_nav/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 19e87bf

Please sign in to comment.