Skip to content

Commit

Permalink
Redirect /opportunity pages to /initiatives (#4248)
Browse files Browse the repository at this point in the history
* WIP, trying to redirect /opportunity pages to /initiatives

* fixes

* redirect /opportunity pages to /initiatives

* simplied code

* no need to import 'urljoin'

* update percy tests

* make sure redirect keeps query string as well

* Update network-api/networkapi/wagtailpages/views.py

Co-Authored-By: Pomax <pomax@nihongoresources.com>

* fix quotation marks

Co-authored-by: Pomax <pomax@nihongoresources.com>
  • Loading branch information
mmmavis and Pomax authored Mar 19, 2020
1 parent 48fa51a commit 544df47
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
38 changes: 22 additions & 16 deletions cypress/integration/endpoint-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,28 @@ describe(`Visual regression testing for foundation.mozilla.org`, () => {

// Opportunity page tests (single and multi-page)

it(`Single-page opportunity`, function() {
cy.visit(`/en/opportunity/single-page/`);
cy.window()
.its(`main-js:react:finished`)
.should(`equal`, true);
cy.wait(500);
cy.percySnapshot();
});

it(`Multi-page opportunity`, function() {
cy.visit(`/en/opportunity/multi-page/`);
cy.window()
.its(`main-js:react:finished`)
.should(`equal`, true);
cy.wait(500);
cy.percySnapshot();
it(`Single-page opportunity should redirect to /intiatives`, function() {
cy.request({
url: `/en/opportunity/single-page-opportunity/`,
followRedirect: false
}).then(res => {
expect(res.status).to.eq(302);
expect(res.redirectedToUrl).to.eq(
`${Cypress.config().baseUrl}/en/initiatives/single-page-opportunity/`
);
});
});

it(`Multi-page opportunity should redirect to /intiatives`, function() {
cy.request({
url: `/en/opportunity/multi-page-opportunity/`,
followRedirect: false
}).then(res => {
expect(res.status).to.eq(302);
expect(res.redirectedToUrl).to.eq(
`${Cypress.config().baseUrl}/en/initiatives/multi-page-opportunity/`
);
});
});

// Campaign page tests (single and multi-page)
Expand Down
5 changes: 5 additions & 0 deletions network-api/networkapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from networkapi.views import EnvVariablesView, review_app_help_view
from networkapi.buyersguide import views as buyersguide_views
from networkapi.wagtailpages.rss import RSSFeed, AtomFeed
from networkapi.wagtailpages.views import redirect_to_initiatives
from experiments import views as experiment_views

admin.autodiscover()
Expand Down Expand Up @@ -72,6 +73,10 @@
path('blog/rss/', RSSFeed()),
path('blog/atom/', AtomFeed()),

# redirect /opportunity Wagtail pages to /initiatives
# see https://github.com/mozilla/foundation.mozilla.org/issues/2971 for context
url(r'^opportunity/(?P<subpath>.*)', redirect_to_initiatives),

# wagtail-managed data
url(r'', include(wagtail_urls)),
)
Expand Down
15 changes: 14 additions & 1 deletion network-api/networkapi/wagtailpages/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.http import HttpResponseNotFound
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.utils import translation


def custom404_view(request, exception):
Expand All @@ -22,3 +23,15 @@ def custom404_view(request, exception):
else:
html = render(request, '404.html')
return HttpResponseNotFound(html.content)


def redirect_to_initiatives(request, subpath):
lang = request.LANGUAGE_CODE
translation.activate(lang)
request.session[translation.LANGUAGE_SESSION_KEY] = lang
query_string = ""

if request.META['QUERY_STRING']:
query_string = f'?{request.META["QUERY_STRING"]}'

return redirect(f'/{request.LANGUAGE_CODE}/initiatives/{subpath}{query_string}')

0 comments on commit 544df47

Please sign in to comment.