Skip to content

Commit

Permalink
Fix #232 by adding basic auth support and redir to /
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Oct 12, 2023
1 parent ea66bba commit 3ab9520
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/edrnsite.policy/src/edrnsite/policy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@

from django.core.cache import caches
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from edrn.auth.views import logged_in_or_basicauth


def _get_referrer(request: HttpRequest) -> str:
try:
return request.META['HTTP_REFERER']
except KeyError:
return '/'


@logged_in_or_basicauth('edrn')
def clear_caches(request: HttpRequest) -> HttpResponse:
'''Clear all caches.'''
if request.user.is_staff or request.user.is_superuser:
for cache in caches:
caches[cache].clear()
return HttpResponseRedirect(request.META['HTTP_REFERER'])
return HttpResponseRedirect(_get_referrer(request))
else:
return HttpResponseForbidden()

0 comments on commit 3ab9520

Please sign in to comment.