Skip to content

Commit

Permalink
Merge pull request #1621 from unicef/develop
Browse files Browse the repository at this point in the history
redirect url
  • Loading branch information
ntrncic authored Sep 7, 2021
2 parents 0b0d8e7 + 7496c74 commit 96d8062
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion django_api/etools_prp/apps/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.views import View
from django.views.generic import RedirectView, TemplateView

import django_filters
Expand Down Expand Up @@ -250,6 +252,21 @@ def get_redirect_url(self, *args, **kwargs):
return redirect_page


class RedirectAppView(LoginRequiredMixin, View):

def get(self, request, *args, **kwargs):
url = self.get_redirect_url(request, *args, **kwargs)
return HttpResponseRedirect(url)

def get_redirect_url(self, request, *args, **kwargs):
path = request.path
if "cluster" in path:
new_path = path.replace("app", "cluster", 1)
else:
new_path = path.replace("app", "ip", 1)
return new_path


class UnauthorizedView(TemplateView):
template_name = 'unauthorized.html'

Expand All @@ -264,4 +281,4 @@ class SocialLogoutView(RedirectView):

def get_redirect_url(self, *args, **kwargs):
return f'https://{settings.TENANT_B2C_URL}/{settings.TENANT_ID}.onmicrosoft.com/{settings.POLICY}/oauth2/' \
f'v2.0/logout?post_logout_redirect_uri={settings.FRONTEND_HOST}{settings.LOGOUT_URL}'
f'v2.0/logout?post_logout_redirect_uri={settings.FRONTEND_HOST}{settings.LOGOUT_URL}'
3 changes: 2 additions & 1 deletion django_api/etools_prp/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

from rest_framework_swagger.views import get_swagger_view

from etools_prp.apps.core.views import HomeView, SocialLogoutView, UnauthorizedView
from etools_prp.apps.core.views import HomeView, RedirectAppView, SocialLogoutView, UnauthorizedView

schema_view = get_swagger_view(title='eTools PRP API')

urlpatterns = [
url(r'^$', HomeView.as_view()),
url(r'^app/', RedirectAppView.as_view()),
url(r'^api/docs/', schema_view),
url(r'^api/admin/', admin.site.urls),
url(r'^api/core/', include('etools_prp.apps.core.urls')),
Expand Down

0 comments on commit 96d8062

Please sign in to comment.