Skip to content

Commit

Permalink
ensure redirect to index if no justice id regardless of route hit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesstottmoj committed Apr 9, 2024
1 parent b45def2 commit 43cfba6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions controlpanel/frontend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
urlpatterns = [
path("", views.IndexView.as_view(), name="index"),
path("oidc/entraid/auth/", views.EntraIdAuthView.as_view(), name="entraid-auth"),
path("oidc/callback/", views.EntraOIDCAuthenticationCallbackView.as_view(), name="entra_callback"),
path("oidc/logout/", views.LogoutView.as_view(), name="oidc_logout"),
path("datasources/", views.AdminBucketList.as_view(), name="list-all-datasources"),
path(
Expand Down
2 changes: 1 addition & 1 deletion controlpanel/frontend/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# First-party/Local
from controlpanel.frontend.views.accessibility import Accessibility
from controlpanel.frontend.views.auth import EntraIdAuthView
from controlpanel.frontend.views.auth import EntraIdAuthView, EntraOIDCAuthenticationCallbackView

# isort: off
from controlpanel.frontend.views.app import (
Expand Down
15 changes: 15 additions & 0 deletions controlpanel/frontend/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.http import HttpResponseRedirect, Http404
from django.urls import reverse
from django.views import View
from mozilla_django_oidc.views import OIDCAuthenticationCallbackView

# First-party/Local
from controlpanel.oidc import OIDCLoginRequiredMixin, oauth
Expand Down Expand Up @@ -62,3 +63,17 @@ def update_user(self, token):
email = token["userinfo"]["email"]
self.request.user.justice_email = email
self.request.user.save()


class EntraOIDCAuthenticationCallbackView(OIDCAuthenticationCallbackView):
"""
This view is used to redirect to the index page if the user has not
authenticated with their justice email.
"""
def get(self, request):
response = super().get(request)

if self.user.justice_email is not None:
return response

return HttpResponseRedirect(reverse("index"))

0 comments on commit 43cfba6

Please sign in to comment.