Skip to content

Commit

Permalink
Bugfix/refresh session (#243)
Browse files Browse the repository at this point in the history
* Fix redirect when refreshing session

When session expires redirect the user to the page
that they were trying to get to.

* Bump chart version
  • Loading branch information
michaeljcollinsuk authored Aug 19, 2024
1 parent 44eb737 commit d14c8fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions ap/auth/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return redirect(reverse("login"))
if OIDCSessionValidator(request).expired():
request.session["next"] = request.get_full_path()
return redirect(reverse("login"))
return super().dispatch(request, *args, **kwargs)
3 changes: 2 additions & 1 deletion ap/auth/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def get(self, request):
return self._login_failure()
else:
self._login_success(request, user, token)
return redirect("/")
redirect_url = request.session.pop("next", "/")
return redirect(redirect_url)
except OAuthError as error:
if settings.DEBUG:
raise error
Expand Down
12 changes: 12 additions & 0 deletions ap/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
from django.http import HttpResponse
from django.shortcuts import redirect
from django.urls import reverse
from django.views import View
from django.views.generic import TemplateView

from ap.auth.oidc import OIDCSessionValidator


class IndexView(TemplateView):
template_name = "home.html"

def dispatch(self, request, *args, **kwargs):
"""
If the session has expired, redirect to login
"""
if OIDCSessionValidator(request).expired():
return redirect(reverse("login"))
return super().dispatch(request, *args, **kwargs)

def get_template_names(self) -> list[str]:
if not self.request.user.is_authenticated:
self.template_name = "login.html"
Expand Down
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apiVersion: v2
name: analytical-platform-ui
description: Analytical Platform UI
type: application
version: 0.1.5
appVersion: 0.1.5
version: 0.1.6
appVersion: 0.1.6
icon: https://upload.wikimedia.org/wikipedia/en/thumb/4/4a/Ministry_of_Justice_logo_%28United_Kingdom%29.svg/611px-Ministry_of_Justice_logo_%28United_Kingdom%29.svg.png
maintainers:
- name: moj-data-platform-robot
Expand Down

0 comments on commit d14c8fa

Please sign in to comment.