diff --git a/ap/auth/views/mixins.py b/ap/auth/views/mixins.py index 6b6784e5..88427f14 100644 --- a/ap/auth/views/mixins.py +++ b/ap/auth/views/mixins.py @@ -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) diff --git a/ap/auth/views/views.py b/ap/auth/views/views.py index e2692e1b..71c274db 100644 --- a/ap/auth/views/views.py +++ b/ap/auth/views/views.py @@ -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 diff --git a/ap/views.py b/ap/views.py index d33c3e05..88f0336f 100644 --- a/ap/views.py +++ b/ap/views.py @@ -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" diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 919d0a10..7f38ad20 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -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