mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Redirect implemented with tests coverage
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import pathlib
|
||||
from functools import partial
|
||||
from time import monotonic
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
import jinja2
|
||||
from flask import (
|
||||
@@ -254,6 +255,7 @@ def create_app(application):
|
||||
|
||||
|
||||
def init_app(application):
|
||||
application.before_request(redirect_notify_to_beta)
|
||||
application.before_request(load_service_before_request)
|
||||
application.before_request(load_organization_before_request)
|
||||
application.before_request(request_helper.check_proxy_header_before_request)
|
||||
@@ -332,6 +334,22 @@ def make_session_permanent():
|
||||
session.permanent = True
|
||||
|
||||
|
||||
def create_url(environment, url):
|
||||
url_created = urlparse(url)
|
||||
if environment == "production":
|
||||
url_list = list(url_created)
|
||||
url_list[1] = "beta.notify.gov"
|
||||
url_for_redirect = urlunparse(url_list)
|
||||
return url_for_redirect
|
||||
return url
|
||||
|
||||
|
||||
def redirect_notify_to_beta():
|
||||
url_to_beta = create_url(current_app.config["NOTIFY_ENVIRONMENT"], request.url)
|
||||
if current_app.config["NOTIFY_ENVIRONMENT"] == "production":
|
||||
redirect(url_to_beta, 301)
|
||||
|
||||
|
||||
def load_service_before_request():
|
||||
if "/static/" in request.url:
|
||||
request_ctx.service = None
|
||||
|
||||
Reference in New Issue
Block a user