diff --git a/internal/localize/lang.go b/internal/localize/lang.go index 86e01d9294..f85421882b 100644 --- a/internal/localize/lang.go +++ b/internal/localize/lang.go @@ -10,6 +10,14 @@ func (l Lang) String() string { return englishAbbreviation } +func (l Lang) URL(path string) string { + if l == Cy { + return "/" + Cy.String() + path + } + + return path +} + const ( En Lang = iota Cy diff --git a/internal/localize/lang_test.go b/internal/localize/lang_test.go index a049088efe..7d0506f0d5 100644 --- a/internal/localize/lang_test.go +++ b/internal/localize/lang_test.go @@ -26,3 +26,22 @@ func TestLangAbbreviation(t *testing.T) { }) } } + +func TestLangURL(t *testing.T) { + testCases := map[string]struct { + lang Lang + url string + want string + }{ + "english": {lang: En, url: "/example.org", want: "/example.org"}, + "welsh": {lang: Cy, url: "/example.org", want: "/cy/example.org"}, + "other language": {lang: Lang(3), url: "/example.org", want: "/example.org"}, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + builtUrl := tc.lang.URL(tc.url) + assert.Equal(t, tc.want, builtUrl) + }) + } +} diff --git a/internal/page/app_data.go b/internal/page/app_data.go index 2f71be2fb2..fded54dec5 100644 --- a/internal/page/app_data.go +++ b/internal/page/app_data.go @@ -28,33 +28,11 @@ type AppData struct { OneloginURL string } -func (d AppData) Redirect(w http.ResponseWriter, r *http.Request, lpa *Lpa, url string) error { - if fromURL := r.FormValue("from"); fromURL != "" { - url = fromURL - } - - if lpa != nil && d.LpaID == "" { - d.LpaID = lpa.ID - } - - // as a shortcut for when you don't have an Lpa but know the transition is fine we allow passing nil - if lpa == nil || lpa.CanGoTo(url) { - http.Redirect(w, r, d.BuildUrl(url), http.StatusFound) - } else { - http.Redirect(w, r, d.BuildUrl(Paths.TaskList.Format(d.LpaID)), http.StatusFound) - } - +func (d AppData) Redirect(w http.ResponseWriter, r *http.Request, url string) error { + http.Redirect(w, r, d.Lang.URL(url), http.StatusFound) return nil } -func (d AppData) BuildUrl(url string) string { - if d.Lang == localize.Cy { - return "/" + localize.Cy.String() + url - } - - return url -} - func ContextWithAppData(ctx context.Context, appData AppData) context.Context { return context.WithValue(ctx, contextKey("appData"), appData) } diff --git a/internal/page/app_data_test.go b/internal/page/app_data_test.go index c7e4a41eb6..a52f3ed906 100644 --- a/internal/page/app_data_test.go +++ b/internal/page/app_data_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/stretchr/testify/assert" ) @@ -23,7 +22,7 @@ func TestAppDataRedirect(t *testing.T) { r, _ := http.NewRequest(http.MethodGet, "/", nil) w := httptest.NewRecorder() - AppData{Lang: lang, LpaID: "lpa-id"}.Redirect(w, r, nil, "/dashboard") + AppData{Lang: lang, LpaID: "lpa-id"}.Redirect(w, r, "/dashboard") resp := w.Result() assert.Equal(t, http.StatusFound, resp.StatusCode) @@ -32,93 +31,6 @@ func TestAppDataRedirect(t *testing.T) { } } -func TestAppDataRedirectWhenCanGoTo(t *testing.T) { - testCases := map[string]struct { - url string - lpa *Lpa - expected string - }{ - "nil": { - url: "/", - lpa: nil, - expected: Paths.HowToConfirmYourIdentityAndSign.Format("lpa-id"), - }, - "nil and from": { - url: "/?from=" + Paths.Restrictions.Format("lpa-id"), - lpa: nil, - expected: Paths.Restrictions.Format("lpa-id"), - }, - "allowed": { - url: "/", - lpa: &Lpa{ - Donor: actor.Donor{ - CanSign: form.Yes, - }, - Type: LpaTypeHealthWelfare, - Tasks: Tasks{ - YourDetails: actor.TaskCompleted, - ChooseAttorneys: actor.TaskCompleted, - ChooseReplacementAttorneys: actor.TaskCompleted, - LifeSustainingTreatment: actor.TaskCompleted, - Restrictions: actor.TaskCompleted, - CertificateProvider: actor.TaskCompleted, - PeopleToNotify: actor.TaskCompleted, - CheckYourLpa: actor.TaskCompleted, - PayForLpa: actor.PaymentTaskCompleted, - }, - }, - expected: Paths.HowToConfirmYourIdentityAndSign.Format("lpa-id"), - }, - "allowed from": { - url: "/?from=" + Paths.Restrictions.Format("lpa-id"), - lpa: &Lpa{Tasks: Tasks{YourDetails: actor.TaskCompleted, ChooseAttorneys: actor.TaskCompleted}}, - expected: Paths.Restrictions.Format("lpa-id"), - }, - "not allowed": { - url: "/", - lpa: &Lpa{}, - expected: Paths.TaskList.Format("lpa-id"), - }, - "not allowed from": { - url: "/?from=" + Paths.Restrictions.Format("lpa-id"), - lpa: &Lpa{}, - expected: Paths.TaskList.Format("lpa-id"), - }, - } - - for name, tc := range testCases { - t.Run(name, func(t *testing.T) { - r, _ := http.NewRequest(http.MethodGet, tc.url, nil) - w := httptest.NewRecorder() - - AppData{Lang: localize.En, LpaID: "lpa-id"}.Redirect(w, r, tc.lpa, Paths.HowToConfirmYourIdentityAndSign.Format("lpa-id")) - resp := w.Result() - - assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, tc.expected, resp.Header.Get("Location")) - }) - } -} - -func TestAppDataBuildUrl(t *testing.T) { - testCases := map[string]struct { - lang localize.Lang - url string - want string - }{ - "english": {lang: localize.En, url: "/example.org", want: "/example.org"}, - "welsh": {lang: localize.Cy, url: "/example.org", want: "/cy/example.org"}, - "other language": {lang: localize.Lang(3), url: "/example.org", want: "/example.org"}, - } - - for name, tc := range testCases { - t.Run(name, func(t *testing.T) { - builtUrl := AppData{Lang: tc.lang}.BuildUrl(tc.url) - assert.Equal(t, tc.want, builtUrl) - }) - } -} - func TestAppDataContext(t *testing.T) { appData := AppData{LpaID: "me"} ctx := context.Background() diff --git a/internal/page/attorney/confirm_your_details.go b/internal/page/attorney/confirm_your_details.go index d849827f53..a5c8d21a1a 100644 --- a/internal/page/attorney/confirm_your_details.go +++ b/internal/page/attorney/confirm_your_details.go @@ -27,7 +27,7 @@ func ConfirmYourDetails(tmpl template.Template, attorneyStore AttorneyStore, don return err } - return appData.Redirect(w, r, nil, page.Paths.Attorney.ReadTheLpa.Format(attorneyProvidedDetails.LpaID)) + return page.Paths.Attorney.ReadTheLpa.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } lpa, err := donorStore.GetAny(r.Context()) diff --git a/internal/page/attorney/enter_reference_number.go b/internal/page/attorney/enter_reference_number.go index ddd0b92b8d..a819ff5003 100644 --- a/internal/page/attorney/enter_reference_number.go +++ b/internal/page/attorney/enter_reference_number.go @@ -64,7 +64,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, } appData.LpaID = shareCode.LpaID - return appData.Redirect(w, r, nil, page.Paths.Attorney.CodeOfConduct.Format(shareCode.LpaID)) + return page.Paths.Attorney.CodeOfConduct.Redirect(w, r, appData, shareCode.LpaID) } } diff --git a/internal/page/attorney/mobile_number.go b/internal/page/attorney/mobile_number.go index 6c5eddacda..818656ad28 100644 --- a/internal/page/attorney/mobile_number.go +++ b/internal/page/attorney/mobile_number.go @@ -43,7 +43,7 @@ func MobileNumber(tmpl template.Template, attorneyStore AttorneyStore) Handler { return err } - return appData.Redirect(w, r, nil, page.Paths.Attorney.ConfirmYourDetails.Format(attorneyProvidedDetails.LpaID)) + return page.Paths.Attorney.ConfirmYourDetails.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } } diff --git a/internal/page/attorney/read_the_lpa.go b/internal/page/attorney/read_the_lpa.go index 8d5ec63fa0..b0de58972e 100644 --- a/internal/page/attorney/read_the_lpa.go +++ b/internal/page/attorney/read_the_lpa.go @@ -24,7 +24,7 @@ func ReadTheLpa(tmpl template.Template, donorStore DonorStore, attorneyStore Att return err } - return appData.Redirect(w, r, nil, page.Paths.Attorney.RightsAndResponsibilities.Format(attorneyProvidedDetails.LpaID)) + return page.Paths.Attorney.RightsAndResponsibilities.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } lpa, err := donorStore.GetAny(r.Context()) diff --git a/internal/page/attorney/sign.go b/internal/page/attorney/sign.go index 007ce25719..2f535b2a64 100644 --- a/internal/page/attorney/sign.go +++ b/internal/page/attorney/sign.go @@ -53,7 +53,7 @@ func Sign(tmpl template.Template, donorStore DonorStore, certificateProviderStor } if ok, _ := canSign(r.Context(), certificateProviderStore, lpa); !ok { - return appData.Redirect(w, r, lpa, page.Paths.Attorney.TaskList.Format(attorneyProvidedDetails.LpaID)) + return page.Paths.Attorney.TaskList.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } data := &signData{ @@ -90,7 +90,7 @@ func Sign(tmpl template.Template, donorStore DonorStore, certificateProviderStor attorney, ok := attorneys.Get(appData.AttorneyID) if !ok { - return appData.Redirect(w, r, lpa, page.Paths.Attorney.Start.Format()) + return page.Paths.Attorney.Start.Redirect(w, r, appData) } data.Attorney = attorney @@ -125,9 +125,9 @@ func Sign(tmpl template.Template, donorStore DonorStore, certificateProviderStor } if appData.IsTrustCorporation() && signatoryIndex == 0 { - return appData.Redirect(w, r, lpa, page.Paths.Attorney.WouldLikeSecondSignatory.Format(attorneyProvidedDetails.LpaID)) + return page.Paths.Attorney.WouldLikeSecondSignatory.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } else { - return appData.Redirect(w, r, lpa, page.Paths.Attorney.WhatHappensNext.Format(attorneyProvidedDetails.LpaID)) + return page.Paths.Attorney.WhatHappensNext.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } } } diff --git a/internal/page/attorney/would_like_second_signatory.go b/internal/page/attorney/would_like_second_signatory.go index 0944ef1bbb..2f06d353bd 100644 --- a/internal/page/attorney/would_like_second_signatory.go +++ b/internal/page/attorney/would_like_second_signatory.go @@ -2,6 +2,7 @@ package attorney import ( "net/http" + "net/url" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" @@ -37,9 +38,9 @@ func WouldLikeSecondSignatory(tmpl template.Template, attorneyStore AttorneyStor } if form.YesNo.IsYes() { - return appData.Redirect(w, r, nil, page.Paths.Attorney.Sign.Format(attorneyProvidedDetails.LpaID)+"?second") + return page.Paths.Attorney.Sign.RedirectQuery(w, r, appData, attorneyProvidedDetails.LpaID, url.Values{"second": {""}}) } else { - return appData.Redirect(w, r, nil, page.Paths.Attorney.WhatHappensNext.Format(attorneyProvidedDetails.LpaID)) + return page.Paths.Attorney.WhatHappensNext.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } } } diff --git a/internal/page/attorney/would_like_second_signatory_test.go b/internal/page/attorney/would_like_second_signatory_test.go index 58b7324f4d..984177fcd0 100644 --- a/internal/page/attorney/would_like_second_signatory_test.go +++ b/internal/page/attorney/would_like_second_signatory_test.go @@ -55,7 +55,7 @@ func TestGetWouldLikeSecondSignatoryWhenTemplateErrors(t *testing.T) { func TestPostWouldLikeSecondSignatory(t *testing.T) { testcases := map[form.YesNo]string{ - form.Yes: page.Paths.Attorney.Sign.Format("lpa-id") + "?second", + form.Yes: page.Paths.Attorney.Sign.Format("lpa-id") + "?second=", form.No: page.Paths.Attorney.WhatHappensNext.Format("lpa-id"), } diff --git a/internal/page/auth_redirect.go b/internal/page/auth_redirect.go index b27feb47c5..56e98f7364 100644 --- a/internal/page/auth_redirect.go +++ b/internal/page/auth_redirect.go @@ -27,6 +27,6 @@ func AuthRedirect(logger Logger, store sesh.Store) http.HandlerFunc { appData := AppData{Lang: lang, LpaID: oneLoginSession.LpaID} - appData.Redirect(w, r, nil, oneLoginSession.Redirect+"?"+r.URL.RawQuery) + appData.Redirect(w, r, oneLoginSession.Redirect+"?"+r.URL.RawQuery) } } diff --git a/internal/page/certificateprovider/confirm_your_details.go b/internal/page/certificateprovider/confirm_your_details.go index af9c77534e..539b95447c 100644 --- a/internal/page/certificateprovider/confirm_your_details.go +++ b/internal/page/certificateprovider/confirm_your_details.go @@ -29,9 +29,9 @@ func ConfirmYourDetails(tmpl template.Template, donorStore DonorStore, certifica } if r.Method == http.MethodPost { - redirect := page.Paths.CertificateProvider.YourRole.Format(certificateProvider.LpaID) + redirect := page.Paths.CertificateProvider.YourRole if certificateProvider.Tasks.ConfirmYourDetails.Completed() || !lpa.SignedAt.IsZero() { - redirect = page.Paths.CertificateProvider.TaskList.Format(certificateProvider.LpaID) + redirect = page.Paths.CertificateProvider.TaskList } certificateProvider.Tasks.ConfirmYourDetails = actor.TaskCompleted @@ -40,7 +40,7 @@ func ConfirmYourDetails(tmpl template.Template, donorStore DonorStore, certifica return err } - return appData.Redirect(w, r, nil, redirect) + return redirect.Redirect(w, r, appData, certificateProvider.LpaID) } data := &confirmYourDetailsData{ diff --git a/internal/page/certificateprovider/enter_date_of_birth.go b/internal/page/certificateprovider/enter_date_of_birth.go index a16f0b8696..f6cdca6eb7 100644 --- a/internal/page/certificateprovider/enter_date_of_birth.go +++ b/internal/page/certificateprovider/enter_date_of_birth.go @@ -62,7 +62,7 @@ func EnterDateOfBirth(tmpl template.Template, donorStore DonorStore, certificate return err } - return appData.Redirect(w, r, lpa, page.Paths.CertificateProvider.ConfirmYourDetails.Format(certificateProvider.LpaID)) + return page.Paths.CertificateProvider.ConfirmYourDetails.Redirect(w, r, appData, certificateProvider.LpaID) } } diff --git a/internal/page/certificateprovider/enter_reference_number.go b/internal/page/certificateprovider/enter_reference_number.go index 2d0f49a3c0..e5e8c908ce 100644 --- a/internal/page/certificateprovider/enter_reference_number.go +++ b/internal/page/certificateprovider/enter_reference_number.go @@ -64,7 +64,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, } appData.LpaID = shareCode.LpaID - return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.WhoIsEligible.Format(shareCode.LpaID)) + return page.Paths.CertificateProvider.WhoIsEligible.Redirect(w, r, appData, shareCode.LpaID) } } diff --git a/internal/page/certificateprovider/identity_with_one_login_callback.go b/internal/page/certificateprovider/identity_with_one_login_callback.go index cb77b85e50..3e28078fd1 100644 --- a/internal/page/certificateprovider/identity_with_one_login_callback.go +++ b/internal/page/certificateprovider/identity_with_one_login_callback.go @@ -36,9 +36,9 @@ func IdentityWithOneLoginCallback(tmpl template.Template, oneLoginClient OneLogi if r.Method == http.MethodPost { if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { - return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.ReadTheLpa.Format(certificateProvider.LpaID)) + return page.Paths.CertificateProvider.ReadTheLpa.Redirect(w, r, appData, certificateProvider.LpaID) } else { - return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.ProveYourIdentity.Format(certificateProvider.LpaID)) + return page.Paths.CertificateProvider.ProveYourIdentity.Redirect(w, r, appData, certificateProvider.LpaID) } } diff --git a/internal/page/certificateprovider/provide_certificate.go b/internal/page/certificateprovider/provide_certificate.go index b361223656..c909ea76dc 100644 --- a/internal/page/certificateprovider/provide_certificate.go +++ b/internal/page/certificateprovider/provide_certificate.go @@ -31,7 +31,7 @@ func ProvideCertificate(tmpl template.Template, donorStore DonorStore, now func( } if lpa.SignedAt.IsZero() { - return appData.Redirect(w, r, lpa, page.Paths.CertificateProvider.TaskList.Format(lpa.ID)) + return page.Paths.CertificateProvider.TaskList.Redirect(w, r, appData, lpa.ID) } data := &provideCertificateData{ @@ -55,7 +55,7 @@ func ProvideCertificate(tmpl template.Template, donorStore DonorStore, now func( return err } - return appData.Redirect(w, r, lpa, page.Paths.CertificateProvider.CertificateProvided.Format(certificateProvider.LpaID)) + return page.Paths.CertificateProvider.CertificateProvided.Redirect(w, r, appData, certificateProvider.LpaID) } } diff --git a/internal/page/certificateprovider/read_the_lpa.go b/internal/page/certificateprovider/read_the_lpa.go index c3efb06575..733d80f4ec 100644 --- a/internal/page/certificateprovider/read_the_lpa.go +++ b/internal/page/certificateprovider/read_the_lpa.go @@ -30,7 +30,7 @@ func ReadTheLpa(tmpl template.Template, donorStore DonorStore, certificateProvid if r.Method == http.MethodPost { if lpa.SignedAt.IsZero() || !lpa.Tasks.PayForLpa.IsCompleted() { - return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.TaskList.Format(lpa.ID)) + return page.Paths.CertificateProvider.TaskList.Redirect(w, r, appData, lpa.ID) } certificateProvider.Tasks.ReadTheLpa = actor.TaskCompleted @@ -38,7 +38,7 @@ func ReadTheLpa(tmpl template.Template, donorStore DonorStore, certificateProvid return err } - return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.WhatHappensNext.Format(lpa.ID)) + return page.Paths.CertificateProvider.WhatHappensNext.Redirect(w, r, appData, lpa.ID) } data := &readTheLpaData{ diff --git a/internal/page/dashboard.go b/internal/page/dashboard.go index f21bf3b4ed..086ee16400 100644 --- a/internal/page/dashboard.go +++ b/internal/page/dashboard.go @@ -37,7 +37,7 @@ func Dashboard(tmpl template.Template, donorStore DonorStore, dashboardStore Das return err } - return appData.Redirect(w, r, lpa, Paths.YourDetails.Format(lpa.ID)) + return Paths.YourDetails.Redirect(w, r, appData, lpa) } donorLpas, attorneyLpas, certificateProviderLpas, err := dashboardStore.GetAll(r.Context()) diff --git a/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go b/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go index acf09755c6..4848144d57 100644 --- a/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go +++ b/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go @@ -39,7 +39,7 @@ func AreYouApplyingForFeeDiscountOrExemption(tmpl template.Template, payer Payer if data.Form.YesNo.IsNo() { return payer.Pay(appData, w, r, lpa) } else { - return appData.Redirect(w, r, lpa, page.Paths.WhichFeeTypeAreYouApplyingFor.Format(lpa.ID)) + return page.Paths.WhichFeeTypeAreYouApplyingFor.Redirect(w, r, appData, lpa) } } } diff --git a/internal/page/donor/certificate_provider_address.go b/internal/page/donor/certificate_provider_address.go index 67c8d6bdc8..defe768a15 100644 --- a/internal/page/donor/certificate_provider_address.go +++ b/internal/page/donor/certificate_provider_address.go @@ -56,7 +56,7 @@ func CertificateProviderAddress(logger Logger, tmpl template.Template, addressCl return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } case "postcode-select": @@ -82,7 +82,7 @@ func CertificateProviderAddress(logger Logger, tmpl template.Template, addressCl return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } else { data.Addresses = lpa.ActorAddresses() } diff --git a/internal/page/donor/certificate_provider_details.go b/internal/page/donor/certificate_provider_details.go index fc8d3d84f7..f5f5cfa1e9 100644 --- a/internal/page/donor/certificate_provider_details.go +++ b/internal/page/donor/certificate_provider_details.go @@ -72,7 +72,7 @@ func CertificateProviderDetails(tmpl template.Template, donorStore DonorStore) H return err } - return appData.Redirect(w, r, lpa, page.Paths.HowDoYouKnowYourCertificateProvider.Format(lpa.ID)) + return page.Paths.HowDoYouKnowYourCertificateProvider.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/change_mobile_number.go b/internal/page/donor/change_mobile_number.go index f6e8436d81..098ad9e786 100644 --- a/internal/page/donor/change_mobile_number.go +++ b/internal/page/donor/change_mobile_number.go @@ -69,7 +69,7 @@ func ChangeMobileNumber(tmpl template.Template, witnessCodeSender WitnessCodeSen return err } - return appData.Redirect(w, r, lpa, redirect.Format(lpa.ID)) + return redirect.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/check_you_can_sign.go b/internal/page/donor/check_you_can_sign.go index 1b59fff7ae..2d88878232 100644 --- a/internal/page/donor/check_you_can_sign.go +++ b/internal/page/donor/check_you_can_sign.go @@ -42,7 +42,7 @@ func CheckYouCanSign(tmpl template.Template, donorStore DonorStore) Handler { redirect = page.Paths.NeedHelpSigningConfirmation } - return appData.Redirect(w, r, lpa, redirect.Format(lpa.ID)) + return redirect.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/check_your_lpa.go b/internal/page/donor/check_your_lpa.go index 06ac36a2cf..631d37bd37 100644 --- a/internal/page/donor/check_your_lpa.go +++ b/internal/page/donor/check_your_lpa.go @@ -4,6 +4,7 @@ import ( "context" "errors" "net/http" + "net/url" "time" "github.com/ministryofjustice/opg-go-common/template" @@ -118,12 +119,6 @@ func CheckYourLpa(tmpl template.Template, donorStore DonorStore, shareCodeSender data.Errors = data.Form.Validate() if data.Errors.None() { - redirect := page.Paths.LpaDetailsSaved.Format(lpa.ID) - - if !data.Completed { - redirect = redirect + "?firstCheck=1" - } - lpa.Tasks.CheckYourLpa = actor.TaskCompleted lpa.CheckedAt = now() @@ -141,7 +136,11 @@ func CheckYourLpa(tmpl template.Template, donorStore DonorStore, shareCodeSender return err } - return appData.Redirect(w, r, lpa, redirect) + if !data.Completed { + return page.Paths.LpaDetailsSaved.RedirectQuery(w, r, appData, lpa, url.Values{"firstCheck": {"1"}}) + } + + return page.Paths.LpaDetailsSaved.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/choose_a_new_certificate_provider.go b/internal/page/donor/choose_a_new_certificate_provider.go index fe5da62d13..ebc074c114 100644 --- a/internal/page/donor/choose_a_new_certificate_provider.go +++ b/internal/page/donor/choose_a_new_certificate_provider.go @@ -26,7 +26,7 @@ func ChooseNewCertificateProvider(tmpl template.Template, donorStore DonorStore) return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseYourCertificateProvider.Format(lpa.ID)) + return page.Paths.ChooseYourCertificateProvider.Redirect(w, r, appData, lpa) } return tmpl(w, data) diff --git a/internal/page/donor/choose_attorneys.go b/internal/page/donor/choose_attorneys.go index 577c794811..ebee4a5060 100644 --- a/internal/page/donor/choose_attorneys.go +++ b/internal/page/donor/choose_attorneys.go @@ -2,6 +2,7 @@ package donor import ( "net/http" + "net/url" "strings" "github.com/ministryofjustice/opg-go-common/template" @@ -27,7 +28,7 @@ func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString f attorney, attorneyFound := lpa.Attorneys.Get(r.URL.Query().Get("id")) if r.Method == http.MethodGet && len(lpa.Attorneys.Attorneys) > 0 && !attorneyFound && !addAnother { - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) } data := &chooseAttorneysData{ @@ -81,7 +82,7 @@ func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString f return err } - return appData.Redirect(w, r, lpa, appData.Paths.ChooseAttorneysAddress.Format(lpa.ID)+"?id="+attorney.ID) + return appData.Paths.ChooseAttorneysAddress.RedirectQuery(w, r, appData, lpa, url.Values{"id": {attorney.ID}}) } } diff --git a/internal/page/donor/choose_attorneys_address.go b/internal/page/donor/choose_attorneys_address.go index b3c3b2e3d0..fc856343fb 100644 --- a/internal/page/donor/choose_attorneys_address.go +++ b/internal/page/donor/choose_attorneys_address.go @@ -15,7 +15,7 @@ func ChooseAttorneysAddress(logger Logger, tmpl template.Template, addressClient attorney, found := lpa.Attorneys.Get(attorneyId) if found == false { - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneys.Format(lpa.ID)) + return page.Paths.ChooseAttorneys.Redirect(w, r, appData, lpa) } data := newChooseAddressData( @@ -55,7 +55,7 @@ func ChooseAttorneysAddress(logger Logger, tmpl template.Template, addressClient return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) case "manual": if data.Errors.None() { @@ -63,7 +63,7 @@ func ChooseAttorneysAddress(logger Logger, tmpl template.Template, addressClient return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) } case "postcode-select": @@ -89,7 +89,7 @@ func ChooseAttorneysAddress(logger Logger, tmpl template.Template, addressClient return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) } else { data.Addresses = lpa.ActorAddresses() } diff --git a/internal/page/donor/choose_attorneys_summary.go b/internal/page/donor/choose_attorneys_summary.go index e267fbb95a..19c45d3304 100644 --- a/internal/page/donor/choose_attorneys_summary.go +++ b/internal/page/donor/choose_attorneys_summary.go @@ -1,8 +1,8 @@ package donor import ( - "fmt" "net/http" + "net/url" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" @@ -21,7 +21,7 @@ type chooseAttorneysSummaryData struct { func ChooseAttorneysSummary(tmpl template.Template) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if lpa.Attorneys.Len() == 0 { - return appData.Redirect(w, r, lpa, fmt.Sprintf("%s?addAnother=1", appData.Paths.ChooseAttorneys.Format(lpa.ID))) + return appData.Paths.ChooseAttorneys.RedirectQuery(w, r, appData, lpa, url.Values{"addAnother": {"1"}}) } data := &chooseAttorneysSummaryData{ @@ -36,17 +36,16 @@ func ChooseAttorneysSummary(tmpl template.Template) Handler { data.Errors = data.Form.Validate() if data.Errors.None() { - redirectUrl := appData.Paths.TaskList.Format(lpa.ID) - + redirectUrl := appData.Paths.TaskList if lpa.Attorneys.Len() > 1 { - redirectUrl = appData.Paths.HowShouldAttorneysMakeDecisions.Format(lpa.ID) + redirectUrl = appData.Paths.HowShouldAttorneysMakeDecisions } if data.Form.YesNo == form.Yes { - redirectUrl = fmt.Sprintf("%s?addAnother=1", appData.Paths.ChooseAttorneys.Format(lpa.ID)) + return appData.Paths.ChooseAttorneys.RedirectQuery(w, r, appData, lpa, url.Values{"addAnother": {"1"}}) + } else { + return redirectUrl.Redirect(w, r, appData, lpa) } - - return appData.Redirect(w, r, lpa, redirectUrl) } } diff --git a/internal/page/donor/choose_people_to_notify.go b/internal/page/donor/choose_people_to_notify.go index 958b7bd35a..73f43166b9 100644 --- a/internal/page/donor/choose_people_to_notify.go +++ b/internal/page/donor/choose_people_to_notify.go @@ -2,6 +2,7 @@ package donor import ( "net/http" + "net/url" "strings" "github.com/ministryofjustice/opg-go-common/template" @@ -20,14 +21,14 @@ type choosePeopleToNotifyData struct { func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, uuidString func() string) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if len(lpa.PeopleToNotify) > 4 { - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotifySummary.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, lpa) } addAnother := r.FormValue("addAnother") == "1" personToNotify, personFound := lpa.PeopleToNotify.Get(r.URL.Query().Get("id")) if r.Method == http.MethodGet && len(lpa.PeopleToNotify) > 0 && personFound == false && addAnother == false { - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotifySummary.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, lpa) } data := &choosePeopleToNotifyData{ @@ -80,7 +81,7 @@ func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, uuidStr return err } - return appData.Redirect(w, r, lpa, appData.Paths.ChoosePeopleToNotifyAddress.Format(lpa.ID)+"?id="+personToNotify.ID) + return appData.Paths.ChoosePeopleToNotifyAddress.RedirectQuery(w, r, appData, lpa, url.Values{"id": {personToNotify.ID}}) } } diff --git a/internal/page/donor/choose_people_to_notify_address.go b/internal/page/donor/choose_people_to_notify_address.go index 7aecac7cec..cab02445c9 100644 --- a/internal/page/donor/choose_people_to_notify_address.go +++ b/internal/page/donor/choose_people_to_notify_address.go @@ -16,7 +16,7 @@ func ChoosePeopleToNotifyAddress(logger Logger, tmpl template.Template, addressC personToNotify, found := lpa.PeopleToNotify.Get(personId) if found == false { - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotify.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotify.Redirect(w, r, appData, lpa) } data := newChooseAddressData( @@ -51,7 +51,7 @@ func ChoosePeopleToNotifyAddress(logger Logger, tmpl template.Template, addressC return err } - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotifySummary.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, lpa) } case "postcode-select": @@ -77,7 +77,7 @@ func ChoosePeopleToNotifyAddress(logger Logger, tmpl template.Template, addressC return err } - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotifySummary.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, lpa) } else { data.Addresses = lpa.ActorAddresses() } diff --git a/internal/page/donor/choose_people_to_notify_summary.go b/internal/page/donor/choose_people_to_notify_summary.go index 65c78ef681..75fcda3dd0 100644 --- a/internal/page/donor/choose_people_to_notify_summary.go +++ b/internal/page/donor/choose_people_to_notify_summary.go @@ -2,6 +2,7 @@ package donor import ( "net/http" + "net/url" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" @@ -20,7 +21,7 @@ type choosePeopleToNotifySummaryData struct { func ChoosePeopleToNotifySummary(tmpl template.Template) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if len(lpa.PeopleToNotify) == 0 { - return appData.Redirect(w, r, lpa, page.Paths.DoYouWantToNotifyPeople.Format(lpa.ID)) + return page.Paths.DoYouWantToNotifyPeople.Redirect(w, r, appData, lpa) } data := &choosePeopleToNotifySummaryData{ @@ -35,13 +36,11 @@ func ChoosePeopleToNotifySummary(tmpl template.Template) Handler { data.Errors = data.Form.Validate() if data.Errors.None() { - redirectUrl := appData.Paths.ChoosePeopleToNotify.Format(lpa.ID) + "?addAnother=1" - if data.Form.YesNo == form.No { - redirectUrl = appData.Paths.TaskList.Format(lpa.ID) + return appData.Paths.TaskList.Redirect(w, r, appData, lpa) + } else { + return appData.Paths.ChoosePeopleToNotify.RedirectQuery(w, r, appData, lpa, url.Values{"addAnother": {"1"}}) } - - return appData.Redirect(w, r, lpa, redirectUrl) } } diff --git a/internal/page/donor/choose_replacement_attorneys.go b/internal/page/donor/choose_replacement_attorneys.go index f42fbfcde7..73e5b279b1 100644 --- a/internal/page/donor/choose_replacement_attorneys.go +++ b/internal/page/donor/choose_replacement_attorneys.go @@ -2,6 +2,7 @@ package donor import ( "net/http" + "net/url" "strings" "github.com/ministryofjustice/opg-go-common/template" @@ -25,7 +26,7 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u attorney, attorneyFound := lpa.ReplacementAttorneys.Get(r.URL.Query().Get("id")) if r.Method == http.MethodGet && lpa.ReplacementAttorneys.Len() > 0 && !attorneyFound && !addAnother { - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } data := &chooseReplacementAttorneysData{ @@ -77,7 +78,7 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u return err } - return appData.Redirect(w, r, lpa, appData.Paths.ChooseReplacementAttorneysAddress.Format(lpa.ID)+"?id="+attorney.ID) + return appData.Paths.ChooseReplacementAttorneysAddress.RedirectQuery(w, r, appData, lpa, url.Values{"id": {attorney.ID}}) } } diff --git a/internal/page/donor/choose_replacement_attorneys_address.go b/internal/page/donor/choose_replacement_attorneys_address.go index 561ff0dd99..a453efa70c 100644 --- a/internal/page/donor/choose_replacement_attorneys_address.go +++ b/internal/page/donor/choose_replacement_attorneys_address.go @@ -45,7 +45,7 @@ func ChooseReplacementAttorneysAddress(logger Logger, tmpl template.Template, ad return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) case "manual": if data.Errors.None() { @@ -53,7 +53,7 @@ func ChooseReplacementAttorneysAddress(logger Logger, tmpl template.Template, ad return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } case "postcode-select": @@ -79,7 +79,7 @@ func ChooseReplacementAttorneysAddress(logger Logger, tmpl template.Template, ad return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } else { data.Addresses = lpa.ActorAddresses() } diff --git a/internal/page/donor/choose_replacement_attorneys_summary.go b/internal/page/donor/choose_replacement_attorneys_summary.go index 5de8aeac4a..07f54a6ceb 100644 --- a/internal/page/donor/choose_replacement_attorneys_summary.go +++ b/internal/page/donor/choose_replacement_attorneys_summary.go @@ -2,6 +2,7 @@ package donor import ( "net/http" + "net/url" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" @@ -20,7 +21,7 @@ type chooseReplacementAttorneysSummaryData struct { func ChooseReplacementAttorneysSummary(tmpl template.Template) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if lpa.ReplacementAttorneys.Len() == 0 { - return appData.Redirect(w, r, lpa, page.Paths.DoYouWantReplacementAttorneys.Format(lpa.ID)) + return page.Paths.DoYouWantReplacementAttorneys.Redirect(w, r, appData, lpa) } data := &chooseReplacementAttorneysSummaryData{ @@ -35,19 +36,15 @@ func ChooseReplacementAttorneysSummary(tmpl template.Template) Handler { data.Errors = data.Form.Validate() if data.Errors.None() { - var redirectUrl string - if data.Form.YesNo == form.Yes { - redirectUrl = appData.Paths.ChooseReplacementAttorneys.Format(lpa.ID) + "?addAnother=1" + return appData.Paths.ChooseReplacementAttorneys.RedirectQuery(w, r, appData, lpa, url.Values{"addAnother": {"1"}}) } else if lpa.ReplacementAttorneys.Len() > 1 && (lpa.Attorneys.Len() == 1 || lpa.AttorneyDecisions.How.IsJointlyForSomeSeverallyForOthers() || lpa.AttorneyDecisions.How.IsJointly()) { - redirectUrl = appData.Paths.HowShouldReplacementAttorneysMakeDecisions.Format(lpa.ID) + return appData.Paths.HowShouldReplacementAttorneysMakeDecisions.Redirect(w, r, appData, lpa) } else if lpa.AttorneyDecisions.How.IsJointlyAndSeverally() { - redirectUrl = appData.Paths.HowShouldReplacementAttorneysStepIn.Format(lpa.ID) + return appData.Paths.HowShouldReplacementAttorneysStepIn.Redirect(w, r, appData, lpa) } else { - redirectUrl = page.Paths.TaskList.Format(lpa.ID) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } - - return appData.Redirect(w, r, lpa, redirectUrl) } } diff --git a/internal/page/donor/confirm_your_certificate_provider_is_not_related.go b/internal/page/donor/confirm_your_certificate_provider_is_not_related.go index ebfdfc4206..d17eb6c5b6 100644 --- a/internal/page/donor/confirm_your_certificate_provider_is_not_related.go +++ b/internal/page/donor/confirm_your_certificate_provider_is_not_related.go @@ -36,7 +36,7 @@ func ConfirmYourCertificateProviderIsNotRelated(tmpl template.Template, donorSto return err } - return appData.Redirect(w, r, lpa, page.Paths.CheckYourLpa.Format(lpa.ID)) + return page.Paths.CheckYourLpa.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/delete_lpa.go b/internal/page/donor/delete_lpa.go index 70693e5216..0fc7dafeb3 100644 --- a/internal/page/donor/delete_lpa.go +++ b/internal/page/donor/delete_lpa.go @@ -2,6 +2,7 @@ package donor import ( "net/http" + "net/url" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -21,7 +22,7 @@ func DeleteLpa(tmpl template.Template, donorStore DonorStore) Handler { return err } - return appData.Redirect(w, r, nil, page.Paths.LpaDeleted.Format()+"?uid="+lpa.UID) + return page.Paths.LpaDeleted.RedirectQuery(w, r, appData, url.Values{"uid": {lpa.UID}}) } return tmpl(w, &deleteLpaData{ diff --git a/internal/page/donor/do_you_want_to_notify_people.go b/internal/page/donor/do_you_want_to_notify_people.go index e037def2af..0c2ef3fc6e 100644 --- a/internal/page/donor/do_you_want_to_notify_people.go +++ b/internal/page/donor/do_you_want_to_notify_people.go @@ -22,7 +22,7 @@ type doYouWantToNotifyPeopleData struct { func DoYouWantToNotifyPeople(tmpl template.Template, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if len(lpa.PeopleToNotify) > 0 { - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotifySummary.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, lpa) } data := &doYouWantToNotifyPeopleData{ @@ -51,10 +51,10 @@ func DoYouWantToNotifyPeople(tmpl template.Template, donorStore DonorStore) Hand lpa.DoYouWantToNotifyPeople = data.Form.YesNo lpa.Tasks.PeopleToNotify = actor.TaskInProgress - redirectPath := appData.Paths.ChoosePeopleToNotify.Format(lpa.ID) + redirectPath := appData.Paths.ChoosePeopleToNotify if lpa.DoYouWantToNotifyPeople == form.No { - redirectPath = appData.Paths.TaskList.Format(lpa.ID) + redirectPath = appData.Paths.TaskList lpa.Tasks.PeopleToNotify = actor.TaskCompleted } @@ -62,7 +62,7 @@ func DoYouWantToNotifyPeople(tmpl template.Template, donorStore DonorStore) Hand return err } - return appData.Redirect(w, r, lpa, redirectPath) + return redirectPath.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/enter_replacement_trust_corporation.go b/internal/page/donor/enter_replacement_trust_corporation.go index 820e399dfb..47d51f0ae3 100644 --- a/internal/page/donor/enter_replacement_trust_corporation.go +++ b/internal/page/donor/enter_replacement_trust_corporation.go @@ -45,7 +45,7 @@ func EnterReplacementTrustCorporation(tmpl template.Template, donorStore DonorSt return err } - return appData.Redirect(w, r, lpa, appData.Paths.EnterReplacementTrustCorporationAddress.Format(lpa.ID)) + return appData.Paths.EnterReplacementTrustCorporationAddress.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/enter_replacement_trust_corporation_address.go b/internal/page/donor/enter_replacement_trust_corporation_address.go index 4caa0d2363..20c9a97af7 100644 --- a/internal/page/donor/enter_replacement_trust_corporation_address.go +++ b/internal/page/donor/enter_replacement_trust_corporation_address.go @@ -46,7 +46,7 @@ func EnterReplacementTrustCorporationAddress(logger Logger, tmpl template.Templa return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } case "postcode-select": @@ -72,7 +72,7 @@ func EnterReplacementTrustCorporationAddress(logger Logger, tmpl template.Templa return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } else { data.Addresses = lpa.ActorAddresses() } diff --git a/internal/page/donor/enter_trust_corporation.go b/internal/page/donor/enter_trust_corporation.go index 3c4e5d6551..7e0541d21e 100644 --- a/internal/page/donor/enter_trust_corporation.go +++ b/internal/page/donor/enter_trust_corporation.go @@ -46,7 +46,7 @@ func EnterTrustCorporation(tmpl template.Template, donorStore DonorStore) Handle return err } - return appData.Redirect(w, r, lpa, appData.Paths.EnterTrustCorporationAddress.Format(lpa.ID)) + return appData.Paths.EnterTrustCorporationAddress.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/enter_trust_corporation_address.go b/internal/page/donor/enter_trust_corporation_address.go index bbde2bd981..160cd7133b 100644 --- a/internal/page/donor/enter_trust_corporation_address.go +++ b/internal/page/donor/enter_trust_corporation_address.go @@ -47,7 +47,7 @@ func EnterTrustCorporationAddress(logger Logger, tmpl template.Template, address return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) } case "postcode-select": @@ -73,7 +73,7 @@ func EnterTrustCorporationAddress(logger Logger, tmpl template.Template, address return err } - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) } else { data.Addresses = lpa.ActorAddresses() } diff --git a/internal/page/donor/how_do_you_know_your_certificate_provider.go b/internal/page/donor/how_do_you_know_your_certificate_provider.go index b5019e9f0b..8d111a4f6c 100644 --- a/internal/page/donor/how_do_you_know_your_certificate_provider.go +++ b/internal/page/donor/how_do_you_know_your_certificate_provider.go @@ -50,10 +50,10 @@ func HowDoYouKnowYourCertificateProvider(tmpl template.Template, donorStore Dono } if lpa.CertificateProvider.Relationship.IsPersonally() { - return appData.Redirect(w, r, lpa, page.Paths.HowLongHaveYouKnownCertificateProvider.Format(lpa.ID)) + return page.Paths.HowLongHaveYouKnownCertificateProvider.Redirect(w, r, appData, lpa) } - return appData.Redirect(w, r, lpa, page.Paths.HowWouldCertificateProviderPreferToCarryOutTheirRole.Format(lpa.ID)) + return page.Paths.HowWouldCertificateProviderPreferToCarryOutTheirRole.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/how_long_have_you_known_certificate_provider.go b/internal/page/donor/how_long_have_you_known_certificate_provider.go index df6b784509..bda89ed86e 100644 --- a/internal/page/donor/how_long_have_you_known_certificate_provider.go +++ b/internal/page/donor/how_long_have_you_known_certificate_provider.go @@ -32,7 +32,7 @@ func HowLongHaveYouKnownCertificateProvider(tmpl template.Template, donorStore D if data.Errors.None() { if form.RelationshipLength == actor.LessThanTwoYears { - return appData.Redirect(w, r, lpa, page.Paths.ChooseNewCertificateProvider.Format(lpa.ID)) + return page.Paths.ChooseNewCertificateProvider.Redirect(w, r, appData, lpa) } lpa.CertificateProvider.RelationshipLength = form.RelationshipLength @@ -40,7 +40,7 @@ func HowLongHaveYouKnownCertificateProvider(tmpl template.Template, donorStore D return err } - return appData.Redirect(w, r, lpa, page.Paths.HowWouldCertificateProviderPreferToCarryOutTheirRole.Format(lpa.ID)) + return page.Paths.HowWouldCertificateProviderPreferToCarryOutTheirRole.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/how_should_attorneys_make_decisions.go b/internal/page/donor/how_should_attorneys_make_decisions.go index 481d52cb11..430ceff973 100644 --- a/internal/page/donor/how_should_attorneys_make_decisions.go +++ b/internal/page/donor/how_should_attorneys_make_decisions.go @@ -45,7 +45,7 @@ func HowShouldAttorneysMakeDecisions(tmpl template.Template, donorStore DonorSto return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/how_should_replacement_attorneys_make_decisions.go b/internal/page/donor/how_should_replacement_attorneys_make_decisions.go index f5994584c3..dbbff67c7f 100644 --- a/internal/page/donor/how_should_replacement_attorneys_make_decisions.go +++ b/internal/page/donor/how_should_replacement_attorneys_make_decisions.go @@ -44,7 +44,7 @@ func HowShouldReplacementAttorneysMakeDecisions(tmpl template.Template, donorSto return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/how_should_replacement_attorneys_step_in.go b/internal/page/donor/how_should_replacement_attorneys_step_in.go index b90cc2fc59..40d7546a92 100644 --- a/internal/page/donor/how_should_replacement_attorneys_step_in.go +++ b/internal/page/donor/how_should_replacement_attorneys_step_in.go @@ -46,9 +46,9 @@ func HowShouldReplacementAttorneysStepIn(tmpl template.Template, donorStore Dono } if lpa.ReplacementAttorneys.Len() > 1 && lpa.HowShouldReplacementAttorneysStepIn.IsWhenAllCanNoLongerAct() { - return appData.Redirect(w, r, lpa, appData.Paths.HowShouldReplacementAttorneysMakeDecisions.Format(lpa.ID)) + return appData.Paths.HowShouldReplacementAttorneysMakeDecisions.Redirect(w, r, appData, lpa) } else { - return appData.Redirect(w, r, lpa, appData.Paths.TaskList.Format(lpa.ID)) + return appData.Paths.TaskList.Redirect(w, r, appData, lpa) } } } diff --git a/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go b/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go index 1dfc5b5457..83f6d5e3ca 100644 --- a/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go +++ b/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go @@ -41,7 +41,7 @@ func HowWouldCertificateProviderPreferToCarryOutTheirRole(tmpl template.Template return err } - return appData.Redirect(w, r, lpa, page.Paths.CertificateProviderAddress.Format(lpa.ID)) + return page.Paths.CertificateProviderAddress.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/how_would_you_like_to_send_evidence.go b/internal/page/donor/how_would_you_like_to_send_evidence.go index 196c8a3fdc..2d12da2371 100644 --- a/internal/page/donor/how_would_you_like_to_send_evidence.go +++ b/internal/page/donor/how_would_you_like_to_send_evidence.go @@ -35,9 +35,9 @@ func HowWouldYouLikeToSendEvidence(tmpl template.Template, donorStore DonorStore } if lpa.EvidenceDelivery.IsUpload() { - return appData.Redirect(w, r, lpa, page.Paths.UploadEvidence.Format(lpa.ID)) + return page.Paths.UploadEvidence.Redirect(w, r, appData, lpa) } else { - return appData.Redirect(w, r, lpa, page.Paths.SendUsYourEvidenceByPost.Format(lpa.ID)) + return page.Paths.SendUsYourEvidenceByPost.Redirect(w, r, appData, lpa) } } } diff --git a/internal/page/donor/identity_with_one_login_callback.go b/internal/page/donor/identity_with_one_login_callback.go index 42170b2d77..648036f0ae 100644 --- a/internal/page/donor/identity_with_one_login_callback.go +++ b/internal/page/donor/identity_with_one_login_callback.go @@ -26,9 +26,9 @@ func IdentityWithOneLoginCallback(tmpl template.Template, oneLoginClient OneLogi return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if r.Method == http.MethodPost { if lpa.DonorIdentityConfirmed() { - return appData.Redirect(w, r, lpa, page.Paths.ReadYourLpa.Format(lpa.ID)) + return page.Paths.ReadYourLpa.Redirect(w, r, appData, lpa) } else { - return appData.Redirect(w, r, lpa, page.Paths.ProveYourIdentity.Format(lpa.ID)) + return page.Paths.ProveYourIdentity.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/life_sustaining_treatment.go b/internal/page/donor/life_sustaining_treatment.go index c9e72051d7..75a83f1baf 100644 --- a/internal/page/donor/life_sustaining_treatment.go +++ b/internal/page/donor/life_sustaining_treatment.go @@ -37,7 +37,7 @@ func LifeSustainingTreatment(tmpl template.Template, donorStore DonorStore) Hand return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/lpa_type.go b/internal/page/donor/lpa_type.go index c4fd4330e2..a6c0771f16 100644 --- a/internal/page/donor/lpa_type.go +++ b/internal/page/donor/lpa_type.go @@ -49,7 +49,7 @@ func LpaType(tmpl template.Template, donorStore DonorStore) Handler { } } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/previous_application_number.go b/internal/page/donor/previous_application_number.go index 603de59ccb..1a9a077ab4 100644 --- a/internal/page/donor/previous_application_number.go +++ b/internal/page/donor/previous_application_number.go @@ -37,9 +37,9 @@ func PreviousApplicationNumber(tmpl template.Template, donorStore DonorStore) Ha } if lpa.PreviousApplicationNumber[0] == '7' { - return appData.Redirect(w, r, lpa, page.Paths.PreviousFee.Format(lpa.ID)) + return page.Paths.PreviousFee.Redirect(w, r, appData, lpa) } else { - return appData.Redirect(w, r, lpa, page.Paths.EvidenceSuccessfullyUploaded.Format(lpa.ID)) + return page.Paths.EvidenceSuccessfullyUploaded.Redirect(w, r, appData, lpa) } } } diff --git a/internal/page/donor/previous_fee.go b/internal/page/donor/previous_fee.go index f571b17718..4303aa0ed2 100644 --- a/internal/page/donor/previous_fee.go +++ b/internal/page/donor/previous_fee.go @@ -43,7 +43,7 @@ func PreviousFee(tmpl template.Template, payer Payer, donorStore DonorStore) Han return payer.Pay(appData, w, r, lpa) } - return appData.Redirect(w, r, lpa, page.Paths.EvidenceRequired.Format(lpa.ID)) + return page.Paths.EvidenceRequired.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/register.go b/internal/page/donor/register.go index e25b3eb692..e1815346ee 100644 --- a/internal/page/donor/register.go +++ b/internal/page/donor/register.go @@ -490,17 +490,17 @@ func (p *payHelper) Pay(appData page.AppData, w http.ResponseWriter, r *http.Req } if lpa.EvidenceDelivery.IsPost() { - return appData.Redirect(w, r, lpa, page.Paths.WhatHappensNextPostEvidence.Format(lpa.ID)) + return page.Paths.WhatHappensNextPostEvidence.Redirect(w, r, appData, lpa) } - return appData.Redirect(w, r, lpa, page.Paths.EvidenceSuccessfullyUploaded.Format(lpa.ID)) + return page.Paths.EvidenceSuccessfullyUploaded.Redirect(w, r, appData, lpa) } createPaymentBody := pay.CreatePaymentBody{ Amount: lpa.FeeAmount(), Reference: p.randomString(12), Description: "Property and Finance LPA", - ReturnUrl: p.appPublicURL + appData.BuildUrl(page.Paths.PaymentConfirmation.Format(lpa.ID)), + ReturnUrl: p.appPublicURL + appData.Lang.URL(page.Paths.PaymentConfirmation.Format(lpa.ID)), Email: lpa.Donor.Email, Language: appData.Lang.String(), } @@ -531,5 +531,5 @@ func (p *payHelper) Pay(appData page.AppData, w http.ResponseWriter, r *http.Req return nil } - return appData.Redirect(w, r, lpa, page.Paths.PaymentConfirmation.Format(lpa.ID)) + return page.Paths.PaymentConfirmation.Redirect(w, r, appData, lpa) } diff --git a/internal/page/donor/remove_attorney.go b/internal/page/donor/remove_attorney.go index 704bd0b33f..f5fdea6702 100644 --- a/internal/page/donor/remove_attorney.go +++ b/internal/page/donor/remove_attorney.go @@ -26,7 +26,7 @@ func RemoveAttorney(logger Logger, tmpl template.Template, donorStore DonorStore attorney, found := lpa.Attorneys.Get(id) if found == false { - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) } data := &removeAttorneyData{ @@ -57,7 +57,7 @@ func RemoveAttorney(logger Logger, tmpl template.Template, donorStore DonorStore } } - return appData.Redirect(w, r, lpa, page.Paths.ChooseAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/remove_person_to_notify.go b/internal/page/donor/remove_person_to_notify.go index 897820f198..9a432f1adb 100644 --- a/internal/page/donor/remove_person_to_notify.go +++ b/internal/page/donor/remove_person_to_notify.go @@ -25,7 +25,7 @@ func RemovePersonToNotify(logger Logger, tmpl template.Template, donorStore Dono person, found := lpa.PeopleToNotify.Get(id) if found == false { - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotifySummary.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, lpa) } data := &removePersonToNotifyData{ @@ -52,7 +52,7 @@ func RemovePersonToNotify(logger Logger, tmpl template.Template, donorStore Dono } } - return appData.Redirect(w, r, lpa, page.Paths.ChoosePeopleToNotifySummary.Format(lpa.ID)) + return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/remove_replacement_attorney.go b/internal/page/donor/remove_replacement_attorney.go index 04a8cf5ba8..2590895c72 100644 --- a/internal/page/donor/remove_replacement_attorney.go +++ b/internal/page/donor/remove_replacement_attorney.go @@ -16,7 +16,7 @@ func RemoveReplacementAttorney(logger Logger, tmpl template.Template, donorStore attorney, found := lpa.ReplacementAttorneys.Get(id) if found == false { - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } data := &removeAttorneyData{ @@ -46,7 +46,7 @@ func RemoveReplacementAttorney(logger Logger, tmpl template.Template, donorStore } } - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/remove_trust_corporation.go b/internal/page/donor/remove_trust_corporation.go index 81d2b7bd94..774fb20041 100644 --- a/internal/page/donor/remove_trust_corporation.go +++ b/internal/page/donor/remove_trust_corporation.go @@ -63,7 +63,7 @@ func RemoveTrustCorporation(tmpl template.Template, donorStore DonorStore, isRep } } - return appData.Redirect(w, r, lpa, redirect.Format(lpa.ID)) + return redirect.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/resend_witness_code.go b/internal/page/donor/resend_witness_code.go index 7a09252a23..b6e6ecbcb1 100644 --- a/internal/page/donor/resend_witness_code.go +++ b/internal/page/donor/resend_witness_code.go @@ -39,7 +39,7 @@ func ResendWitnessCode(tmpl template.Template, witnessCodeSender WitnessCodeSend return err } - return appData.Redirect(w, r, lpa, redirect.Format(lpa.ID)) + return redirect.Redirect(w, r, appData, lpa) } return tmpl(w, data) diff --git a/internal/page/donor/restrictions.go b/internal/page/donor/restrictions.go index cfdca4aedf..e89b869cca 100644 --- a/internal/page/donor/restrictions.go +++ b/internal/page/donor/restrictions.go @@ -34,7 +34,7 @@ func Restrictions(tmpl template.Template, donorStore DonorStore) Handler { return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/sign_your_lpa.go b/internal/page/donor/sign_your_lpa.go index c3f094e77f..d9898ad2ef 100644 --- a/internal/page/donor/sign_your_lpa.go +++ b/internal/page/donor/sign_your_lpa.go @@ -54,7 +54,7 @@ func SignYourLpa(tmpl template.Template, donorStore DonorStore) Handler { } if data.Errors.None() { - return appData.Redirect(w, r, lpa, page.Paths.WitnessingYourSignature.Format(lpa.ID)) + return page.Paths.WitnessingYourSignature.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/upload_evidence.go b/internal/page/donor/upload_evidence.go index be648480f3..e1d21c9424 100644 --- a/internal/page/donor/upload_evidence.go +++ b/internal/page/donor/upload_evidence.go @@ -60,7 +60,7 @@ type uploadEvidenceData struct { func UploadEvidence(tmpl template.Template, logger Logger, payer Payer, documentStore DocumentStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if lpa.Tasks.PayForLpa.IsPending() { - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } documents, err := documentStore.GetAll(r.Context()) diff --git a/internal/page/donor/want_replacement_attorneys.go b/internal/page/donor/want_replacement_attorneys.go index eea3a7f36a..afbd93b5ff 100644 --- a/internal/page/donor/want_replacement_attorneys.go +++ b/internal/page/donor/want_replacement_attorneys.go @@ -35,13 +35,13 @@ func WantReplacementAttorneys(tmpl template.Template, donorStore DonorStore) Han if data.Errors.None() { lpa.WantReplacementAttorneys = f.YesNo - var redirectUrl string + var redirectUrl page.LpaPath if lpa.WantReplacementAttorneys == form.No { lpa.ReplacementAttorneys = actor.Attorneys{} - redirectUrl = page.Paths.TaskList.Format(lpa.ID) + redirectUrl = page.Paths.TaskList } else { - redirectUrl = page.Paths.ChooseReplacementAttorneys.Format(lpa.ID) + redirectUrl = page.Paths.ChooseReplacementAttorneys } lpa.Tasks.ChooseReplacementAttorneys = page.ChooseReplacementAttorneysState(lpa) @@ -50,12 +50,12 @@ func WantReplacementAttorneys(tmpl template.Template, donorStore DonorStore) Han return err } - return appData.Redirect(w, r, lpa, redirectUrl) + return redirectUrl.Redirect(w, r, appData, lpa) } } if lpa.ReplacementAttorneys.Len() > 0 { - return appData.Redirect(w, r, lpa, page.Paths.ChooseReplacementAttorneysSummary.Format(lpa.ID)) + return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, lpa) } return tmpl(w, data) diff --git a/internal/page/donor/when_can_the_lpa_be_used.go b/internal/page/donor/when_can_the_lpa_be_used.go index 022466a329..59014cf48f 100644 --- a/internal/page/donor/when_can_the_lpa_be_used.go +++ b/internal/page/donor/when_can_the_lpa_be_used.go @@ -39,7 +39,7 @@ func WhenCanTheLpaBeUsed(tmpl template.Template, donorStore DonorStore) Handler return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/which_fee_type_are_you_applying_for.go b/internal/page/donor/which_fee_type_are_you_applying_for.go index d2fb7550d5..31c6790636 100644 --- a/internal/page/donor/which_fee_type_are_you_applying_for.go +++ b/internal/page/donor/which_fee_type_are_you_applying_for.go @@ -37,9 +37,9 @@ func WhichFeeTypeAreYouApplyingFor(tmpl template.Template, donorStore DonorStore } if lpa.FeeType.IsRepeatApplicationFee() { - return appData.Redirect(w, r, lpa, page.Paths.PreviousApplicationNumber.Format(lpa.ID)) + return page.Paths.PreviousApplicationNumber.Redirect(w, r, appData, lpa) } else { - return appData.Redirect(w, r, lpa, page.Paths.EvidenceRequired.Format(lpa.ID)) + return page.Paths.EvidenceRequired.Redirect(w, r, appData, lpa) } } } diff --git a/internal/page/donor/withdraw_lpa.go b/internal/page/donor/withdraw_lpa.go index 0dd2c1febc..5fdf047196 100644 --- a/internal/page/donor/withdraw_lpa.go +++ b/internal/page/donor/withdraw_lpa.go @@ -2,6 +2,7 @@ package donor import ( "net/http" + "net/url" "time" "github.com/ministryofjustice/opg-go-common/template" @@ -23,7 +24,7 @@ func WithdrawLpa(tmpl template.Template, donorStore DonorStore, now func() time. return err } - return appData.Redirect(w, r, nil, page.Paths.LpaWithdrawn.Format()+"?uid="+lpa.UID) + return page.Paths.LpaWithdrawn.RedirectQuery(w, r, appData, url.Values{"uid": {lpa.UID}}) } return tmpl(w, &withdrawLpaData{ diff --git a/internal/page/donor/witnessing_as_certificate_provider.go b/internal/page/donor/witnessing_as_certificate_provider.go index 8a29a1668a..d59122c8b3 100644 --- a/internal/page/donor/witnessing_as_certificate_provider.go +++ b/internal/page/donor/witnessing_as_certificate_provider.go @@ -77,7 +77,7 @@ func WitnessingAsCertificateProvider(tmpl template.Template, donorStore DonorSto return err } - return appData.Redirect(w, r, lpa, page.Paths.YouHaveSubmittedYourLpa.Format(lpa.ID)) + return page.Paths.YouHaveSubmittedYourLpa.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/witnessing_as_independent_witness.go b/internal/page/donor/witnessing_as_independent_witness.go index 4c4b93e41c..8da51afe16 100644 --- a/internal/page/donor/witnessing_as_independent_witness.go +++ b/internal/page/donor/witnessing_as_independent_witness.go @@ -53,7 +53,7 @@ func WitnessingAsIndependentWitness(tmpl template.Template, donorStore DonorStor } if data.Errors.None() { - return appData.Redirect(w, r, lpa, page.Paths.WitnessingAsCertificateProvider.Format(lpa.ID)) + return page.Paths.WitnessingAsCertificateProvider.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/witnessing_your_signature.go b/internal/page/donor/witnessing_your_signature.go index ffe0c456f9..9b4b1828c6 100644 --- a/internal/page/donor/witnessing_your_signature.go +++ b/internal/page/donor/witnessing_your_signature.go @@ -22,7 +22,7 @@ func WitnessingYourSignature(tmpl template.Template, witnessCodeSender WitnessCo } if lpa.Donor.CanSign.IsYes() { - return appData.Redirect(w, r, lpa, page.Paths.WitnessingAsCertificateProvider.Format(lpa.ID)) + return page.Paths.WitnessingAsCertificateProvider.Redirect(w, r, appData, lpa) } else { lpa, err := donorStore.Get(r.Context()) if err != nil { @@ -33,7 +33,7 @@ func WitnessingYourSignature(tmpl template.Template, witnessCodeSender WitnessCo return err } - return appData.Redirect(w, r, lpa, page.Paths.WitnessingAsIndependentWitness.Format(lpa.ID)) + return page.Paths.WitnessingAsIndependentWitness.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/your_address.go b/internal/page/donor/your_address.go index d271e9acbe..a40590ca3c 100644 --- a/internal/page/donor/your_address.go +++ b/internal/page/donor/your_address.go @@ -41,7 +41,7 @@ func YourAddress(logger Logger, tmpl template.Template, addressClient AddressCli return err } - return appData.Redirect(w, r, lpa, page.Paths.LpaType.Format(lpa.ID)) + return page.Paths.LpaType.Redirect(w, r, appData, lpa) } case "postcode-select": diff --git a/internal/page/donor/your_authorised_signatory.go b/internal/page/donor/your_authorised_signatory.go index 8701423c9a..38f8d9606d 100644 --- a/internal/page/donor/your_authorised_signatory.go +++ b/internal/page/donor/your_authorised_signatory.go @@ -54,7 +54,7 @@ func YourAuthorisedSignatory(tmpl template.Template, donorStore DonorStore) Hand return err } - return appData.Redirect(w, r, lpa, page.Paths.YourIndependentWitness.Format(lpa.ID)) + return page.Paths.YourIndependentWitness.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/your_details.go b/internal/page/donor/your_details.go index 972348ff01..fc97a557bf 100644 --- a/internal/page/donor/your_details.go +++ b/internal/page/donor/your_details.go @@ -107,7 +107,7 @@ func YourDetails(tmpl template.Template, donorStore DonorStore, sessionStore ses return err } - return appData.Redirect(w, r, lpa, redirect.Format(lpa.ID)) + return redirect.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/your_independent_witness.go b/internal/page/donor/your_independent_witness.go index 1bc831aed8..da81b2f30f 100644 --- a/internal/page/donor/your_independent_witness.go +++ b/internal/page/donor/your_independent_witness.go @@ -54,7 +54,7 @@ func YourIndependentWitness(tmpl template.Template, donorStore DonorStore) Handl return err } - return appData.Redirect(w, r, lpa, page.Paths.YourIndependentWitnessMobile.Format(lpa.ID)) + return page.Paths.YourIndependentWitnessMobile.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/donor/your_independent_witness_address.go b/internal/page/donor/your_independent_witness_address.go index 1d8795c161..f399b88933 100644 --- a/internal/page/donor/your_independent_witness_address.go +++ b/internal/page/donor/your_independent_witness_address.go @@ -43,7 +43,7 @@ func YourIndependentWitnessAddress(logger Logger, tmpl template.Template, addres return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } case "postcode-select": @@ -69,7 +69,7 @@ func YourIndependentWitnessAddress(logger Logger, tmpl template.Template, addres return err } - return appData.Redirect(w, r, lpa, page.Paths.TaskList.Format(lpa.ID)) + return page.Paths.TaskList.Redirect(w, r, appData, lpa) } else { data.Addresses = lpa.ActorAddresses() } diff --git a/internal/page/donor/your_independent_witness_mobile.go b/internal/page/donor/your_independent_witness_mobile.go index 444f7987f7..7e09d953db 100644 --- a/internal/page/donor/your_independent_witness_mobile.go +++ b/internal/page/donor/your_independent_witness_mobile.go @@ -48,7 +48,7 @@ func YourIndependentWitnessMobile(tmpl template.Template, donorStore DonorStore) return err } - return appData.Redirect(w, r, lpa, page.Paths.YourIndependentWitnessAddress.Format(lpa.ID)) + return page.Paths.YourIndependentWitnessAddress.Redirect(w, r, appData, lpa) } } diff --git a/internal/page/fixtures/attorney.go b/internal/page/fixtures/attorney.go index 3c9a09edd9..71ecab6334 100644 --- a/internal/page/fixtures/attorney.go +++ b/internal/page/fixtures/attorney.go @@ -272,7 +272,8 @@ func Attorney( Localizer: appData.Localizer, }, lpa) - return page.AppData{}.Redirect(w, r, nil, page.Paths.Attorney.Start.Format()) + http.Redirect(w, r, page.Paths.Attorney.Start.Format(), http.StatusFound) + return nil } if redirect == "" { @@ -281,6 +282,7 @@ func Attorney( redirect = "/attorney/" + lpa.ID + redirect } - return page.AppData{}.Redirect(w, r, nil, redirect) + http.Redirect(w, r, redirect, http.StatusFound) + return nil } } diff --git a/internal/page/fixtures/certificate_provider.go b/internal/page/fixtures/certificate_provider.go index 71fa1aecff..908debc8c5 100644 --- a/internal/page/fixtures/certificate_provider.go +++ b/internal/page/fixtures/certificate_provider.go @@ -131,7 +131,8 @@ func CertificateProvider( Localizer: appData.Localizer, }, true, lpa) - return page.AppData{}.Redirect(w, r, nil, page.Paths.CertificateProviderStart.Format()) + http.Redirect(w, r, page.Paths.CertificateProviderStart.Format(), http.StatusFound) + return nil } if redirect == "" { @@ -140,6 +141,7 @@ func CertificateProvider( redirect = "/certificate-provider/" + lpa.ID + redirect } - return page.AppData{}.Redirect(w, r, nil, redirect) + http.Redirect(w, r, redirect, http.StatusFound) + return nil } } diff --git a/internal/page/fixtures/dashboard.go b/internal/page/fixtures/dashboard.go index 57021549e3..fd4e7590f5 100644 --- a/internal/page/fixtures/dashboard.go +++ b/internal/page/fixtures/dashboard.go @@ -119,6 +119,7 @@ func Dashboard( } } - return page.AppData{}.Redirect(w, r, nil, page.Paths.Dashboard.Format()) + http.Redirect(w, r, page.Paths.Dashboard.Format(), http.StatusFound) + return nil } } diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index d3e4d01f91..a2bbd55d4d 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -356,6 +356,7 @@ func Donor( } random.UseTestCode = true - return page.AppData{}.Redirect(w, r, nil, redirect) + http.Redirect(w, r, redirect, http.StatusFound) + return nil } } diff --git a/internal/page/login_callback.go b/internal/page/login_callback.go index 37c6650998..e31e8cf89a 100644 --- a/internal/page/login_callback.go +++ b/internal/page/login_callback.go @@ -38,6 +38,6 @@ func LoginCallback(oneLoginClient LoginCallbackOneLoginClient, sessionStore sesh return err } - return appData.Redirect(w, r, nil, redirect.Format()) + return appData.Redirect(w, r, redirect.Format()) } } diff --git a/internal/page/paths.go b/internal/page/paths.go index f2a8e50b8f..74e983764e 100644 --- a/internal/page/paths.go +++ b/internal/page/paths.go @@ -1,5 +1,10 @@ package page +import ( + "net/http" + "net/url" +) + type Path string func (p Path) String() string { @@ -10,6 +15,16 @@ func (p Path) Format() string { return string(p) } +func (p Path) Redirect(w http.ResponseWriter, r *http.Request, appData AppData) error { + http.Redirect(w, r, appData.Lang.URL(p.Format()), http.StatusFound) + return nil +} + +func (p Path) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, query url.Values) error { + http.Redirect(w, r, appData.Lang.URL(p.Format())+"?"+query.Encode(), http.StatusFound) + return nil +} + type LpaPath string func (p LpaPath) String() string { @@ -20,6 +35,36 @@ func (p LpaPath) Format(id string) string { return "/lpa/" + id + string(p) } +func (p LpaPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData, lpa *Lpa) error { + rurl := p.Format(lpa.ID) + if fromURL := r.FormValue("from"); fromURL != "" { + rurl = fromURL + } + + if lpa.CanGoTo(rurl) { + http.Redirect(w, r, appData.Lang.URL(rurl), http.StatusFound) + } else { + http.Redirect(w, r, appData.Lang.URL(Paths.TaskList.Format(lpa.ID)), http.StatusFound) + } + + return nil +} + +func (p LpaPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, lpa *Lpa, query url.Values) error { + rurl := p.Format(lpa.ID) + "?" + query.Encode() + if fromURL := r.FormValue("from"); fromURL != "" { + rurl = fromURL + } + + if lpa.CanGoTo(rurl) { + http.Redirect(w, r, appData.Lang.URL(rurl), http.StatusFound) + } else { + http.Redirect(w, r, appData.Lang.URL(Paths.TaskList.Format(lpa.ID)), http.StatusFound) + } + + return nil +} + type AttorneyPath string func (p AttorneyPath) String() string { @@ -30,6 +75,16 @@ func (p AttorneyPath) Format(id string) string { return "/attorney/" + id + string(p) } +func (p AttorneyPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string) error { + http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID)), http.StatusFound) + return nil +} + +func (p AttorneyPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string, query url.Values) error { + http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID))+"?"+query.Encode(), http.StatusFound) + return nil +} + type CertificateProviderPath string func (p CertificateProviderPath) String() string { @@ -40,6 +95,11 @@ func (p CertificateProviderPath) Format(id string) string { return "/certificate-provider/" + id + string(p) } +func (p CertificateProviderPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string) error { + http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID)), http.StatusFound) + return nil +} + type AttorneyPaths struct { EnterReferenceNumber Path Login Path diff --git a/internal/page/paths_test.go b/internal/page/paths_test.go index a88642535a..0c772837c2 100644 --- a/internal/page/paths_test.go +++ b/internal/page/paths_test.go @@ -1,8 +1,14 @@ package page import ( + "net/http" + "net/http/httptest" + "net/url" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/form" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/stretchr/testify/assert" ) @@ -14,6 +20,32 @@ func TestPathFormat(t *testing.T) { assert.Equal(t, "/anything", Path("/anything").Format()) } +func TestPathRedirect(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, "/", nil) + w := httptest.NewRecorder() + p := Path("/something") + + err := p.Redirect(w, r, AppData{Lang: localize.En}) + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, p.Format(), resp.Header.Get("Location")) +} + +func TestPathRedirectQuery(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, "/", nil) + w := httptest.NewRecorder() + p := Path("/something") + + err := p.RedirectQuery(w, r, AppData{Lang: localize.En}, url.Values{"q": {"1"}}) + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, p.Format()+"?q=1", resp.Header.Get("Location")) +} + func TestLpaPathString(t *testing.T) { assert.Equal(t, "/anything", LpaPath("/anything").String()) } @@ -22,6 +54,78 @@ func TestLpaPathFormat(t *testing.T) { assert.Equal(t, "/lpa/abc/anything", LpaPath("/anything").Format("abc")) } +func TestLpaPathRedirect(t *testing.T) { + testCases := map[string]struct { + url string + lpa *Lpa + expected string + }{ + "allowed": { + url: "/", + lpa: &Lpa{ + ID: "lpa-id", + Donor: actor.Donor{ + CanSign: form.Yes, + }, + Type: LpaTypeHealthWelfare, + Tasks: Tasks{ + YourDetails: actor.TaskCompleted, + ChooseAttorneys: actor.TaskCompleted, + ChooseReplacementAttorneys: actor.TaskCompleted, + LifeSustainingTreatment: actor.TaskCompleted, + Restrictions: actor.TaskCompleted, + CertificateProvider: actor.TaskCompleted, + PeopleToNotify: actor.TaskCompleted, + CheckYourLpa: actor.TaskCompleted, + PayForLpa: actor.PaymentTaskCompleted, + }, + }, + expected: Paths.HowToConfirmYourIdentityAndSign.Format("lpa-id"), + }, + "allowed from": { + url: "/?from=" + Paths.Restrictions.Format("lpa-id"), + lpa: &Lpa{ID: "lpa-id", Tasks: Tasks{YourDetails: actor.TaskCompleted, ChooseAttorneys: actor.TaskCompleted}}, + expected: Paths.Restrictions.Format("lpa-id"), + }, + "not allowed": { + url: "/", + lpa: &Lpa{ID: "lpa-id"}, + expected: Paths.TaskList.Format("lpa-id"), + }, + "not allowed from": { + url: "/?from=" + Paths.Restrictions.Format("lpa-id"), + lpa: &Lpa{ID: "lpa-id"}, + expected: Paths.TaskList.Format("lpa-id"), + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, tc.url, nil) + w := httptest.NewRecorder() + + err := Paths.HowToConfirmYourIdentityAndSign.Redirect(w, r, AppData{Lang: localize.En}, tc.lpa) + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, tc.expected, resp.Header.Get("Location")) + }) + } +} + +func TestLpaPathRedirectQuery(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, "/", nil) + w := httptest.NewRecorder() + + err := Paths.TaskList.RedirectQuery(w, r, AppData{Lang: localize.En}, &Lpa{ID: "lpa-id"}, url.Values{"q": {"1"}}) + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, Paths.TaskList.Format("lpa-id")+"?q=1", resp.Header.Get("Location")) +} + func TestAttorneyPathString(t *testing.T) { assert.Equal(t, "/anything", AttorneyPath("/anything").String()) } @@ -30,6 +134,32 @@ func TestAttorneyPathFormat(t *testing.T) { assert.Equal(t, "/attorney/abc/anything", AttorneyPath("/anything").Format("abc")) } +func TestAttorneyPathRedirect(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, "/", nil) + w := httptest.NewRecorder() + p := AttorneyPath("/something") + + err := p.Redirect(w, r, AppData{Lang: localize.En}, "lpa-id") + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, p.Format("lpa-id"), resp.Header.Get("Location")) +} + +func TestAttorneyPathRedirectQuery(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, "/", nil) + w := httptest.NewRecorder() + p := AttorneyPath("/something") + + err := p.RedirectQuery(w, r, AppData{Lang: localize.En}, "lpa-id", url.Values{"q": {"1"}}) + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, p.Format("lpa-id")+"?q=1", resp.Header.Get("Location")) +} + func TestCertificateProviderPathString(t *testing.T) { assert.Equal(t, "/anything", CertificateProviderPath("/anything").String()) } @@ -37,3 +167,16 @@ func TestCertificateProviderPathString(t *testing.T) { func TestCertificateProviderPathFormat(t *testing.T) { assert.Equal(t, "/certificate-provider/abc/anything", CertificateProviderPath("/anything").Format("abc")) } + +func TestCertificateProviderPathRedirect(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, "/", nil) + w := httptest.NewRecorder() + p := CertificateProviderPath("/something") + + err := p.Redirect(w, r, AppData{Lang: localize.En}, "lpa-id") + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, p.Format("lpa-id"), resp.Header.Get("Location")) +} diff --git a/internal/templatefn/fn.go b/internal/templatefn/fn.go index 506a965830..f034642367 100644 --- a/internal/templatefn/fn.go +++ b/internal/templatefn/fn.go @@ -137,7 +137,7 @@ func inc(i int) int { } func link(app page.AppData, path string) string { - return app.BuildUrl(path) + return app.Lang.URL(path) } func contains(needle string, list any) bool { diff --git a/web/template/layout/page.gohtml b/web/template/layout/page.gohtml index b632ea01d4..21bab99a26 100644 --- a/web/template/layout/page.gohtml +++ b/web/template/layout/page.gohtml @@ -162,7 +162,7 @@