Skip to content

Commit

Permalink
Split up templates by page type (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Jan 22, 2024
1 parent 2e482bb commit 3e172ba
Show file tree
Hide file tree
Showing 107 changed files with 60 additions and 36 deletions.
22 changes: 22 additions & 0 deletions cmd/mlpa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ func main() {
logger.Fatal(err)
}

donorTmpls, err := parseTemplates(webDir+"/template/donor", layouts)
if err != nil {
logger.Fatal(err)
}

certificateProviderTmpls, err := parseTemplates(webDir+"/template/certificateprovider", layouts)
if err != nil {
logger.Fatal(err)
}

attorneyTmpls, err := parseTemplates(webDir+"/template/attorney", layouts)
if err != nil {
logger.Fatal(err)
}

supporterTmpls, err := parseTemplates(webDir+"/template/supporter", layouts)
if err != nil {
logger.Fatal(err)
Expand Down Expand Up @@ -247,6 +262,9 @@ func main() {
bundle.For(localize.Cy),
localize.Cy,
tmpls,
donorTmpls,
certificateProviderTmpls,
attorneyTmpls,
supporterTmpls,
sessionStore,
lpasDynamoClient,
Expand All @@ -263,11 +281,15 @@ func main() {
eventClient,
lpaStoreClient,
)))

mux.Handle("/", app.App(
logger,
bundle.For(localize.En),
localize.En,
tmpls,
donorTmpls,
certificateProviderTmpls,
attorneyTmpls,
supporterTmpls,
sessionStore,
lpasDynamoClient,
Expand Down
6 changes: 4 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ func App(
logger *logging.Logger,
localizer page.Localizer,
lang localize.Lang,
tmpls template.Templates,
supporterTmpls template.Templates,
tmpls, donorTmpls, certificateProviderTmpls, attorneyTmpls, supporterTmpls template.Templates,
sessionStore SessionStore,
lpaDynamoClient DynamoClient,
appPublicURL string,
Expand Down Expand Up @@ -156,6 +155,7 @@ func App(
rootMux,
logger,
tmpls,
certificateProviderTmpls,
sessionStore,
donorStore,
oneLoginClient,
Expand All @@ -174,6 +174,7 @@ func App(
rootMux,
logger,
tmpls,
attorneyTmpls,
sessionStore,
donorStore,
certificateProviderStore,
Expand All @@ -190,6 +191,7 @@ func App(
rootMux,
logger,
tmpls,
donorTmpls,
sessionStore,
donorStore,
oneLoginClient,
Expand Down
2 changes: 1 addition & 1 deletion internal/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func TestApp(t *testing.T) {
app := App(&logging.Logger{}, &localize.Localizer{}, localize.En, template.Templates{}, template.Templates{}, nil, nil, "http://public.url", &pay.Client{}, &notify.Client{}, &place.Client{}, page.RumConfig{}, "?%3fNEI0t9MN", page.Paths, &onelogin.Client{}, "http://onelogin.url", nil, nil, nil)
app := App(&logging.Logger{}, &localize.Localizer{}, localize.En, template.Templates{}, template.Templates{}, template.Templates{}, template.Templates{}, template.Templates{}, nil, nil, "http://public.url", &pay.Client{}, &notify.Client{}, &place.Client{}, page.RumConfig{}, "?%3fNEI0t9MN", page.Paths, &onelogin.Client{}, "http://onelogin.url", nil, nil, nil)

assert.Implements(t, (*http.Handler)(nil), app)
}
Expand Down
28 changes: 14 additions & 14 deletions internal/page/attorney/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type ErrorHandler func(http.ResponseWriter, *http.Request, error)
func Register(
rootMux *http.ServeMux,
logger Logger,
tmpls template.Templates,
commonTmpls, tmpls template.Templates,
sessionStore SessionStore,
donorStore DonorStore,
certificateProviderStore CertificateProviderStore,
Expand All @@ -94,36 +94,36 @@ func Register(
handleRoot(page.Paths.Attorney.LoginCallback, None,
page.LoginCallback(oneLoginClient, sessionStore, page.Paths.Attorney.EnterReferenceNumber, dashboardStore, actor.TypeAttorney))
handleRoot(page.Paths.Attorney.EnterReferenceNumber, RequireSession,
EnterReferenceNumber(tmpls.Get("attorney_enter_reference_number.gohtml"), shareCodeStore, sessionStore, attorneyStore))
EnterReferenceNumber(tmpls.Get("enter_reference_number.gohtml"), shareCodeStore, sessionStore, attorneyStore))

attorneyMux := http.NewServeMux()
rootMux.Handle("/attorney/", page.RouteToPrefix("/attorney/", attorneyMux, notFoundHandler))
handleAttorney := makeAttorneyHandle(attorneyMux, sessionStore, errorHandler, attorneyStore)

handleAttorney(page.Paths.Attorney.CodeOfConduct, RequireAttorney,
Guidance(tmpls.Get("attorney_code_of_conduct.gohtml"), donorStore))
Guidance(tmpls.Get("code_of_conduct.gohtml"), donorStore))
handleAttorney(page.Paths.Attorney.TaskList, RequireAttorney,
TaskList(tmpls.Get("attorney_task_list.gohtml"), donorStore, certificateProviderStore))
TaskList(tmpls.Get("task_list.gohtml"), donorStore, certificateProviderStore))
handleAttorney(page.Paths.Attorney.MobileNumber, RequireAttorney,
MobileNumber(tmpls.Get("attorney_mobile_number.gohtml"), attorneyStore))
MobileNumber(tmpls.Get("mobile_number.gohtml"), attorneyStore))
handleAttorney(page.Paths.Attorney.YourPreferredLanguage, RequireAttorney,
YourPreferredLanguage(tmpls.Get("your_preferred_language.gohtml"), attorneyStore, donorStore))
YourPreferredLanguage(commonTmpls.Get("your_preferred_language.gohtml"), attorneyStore, donorStore))
handleAttorney(page.Paths.Attorney.ConfirmYourDetails, RequireAttorney,
ConfirmYourDetails(tmpls.Get("attorney_confirm_your_details.gohtml"), attorneyStore, donorStore))
ConfirmYourDetails(tmpls.Get("confirm_your_details.gohtml"), attorneyStore, donorStore))
handleAttorney(page.Paths.Attorney.ReadTheLpa, RequireAttorney,
ReadTheLpa(tmpls.Get("attorney_read_the_lpa.gohtml"), donorStore, attorneyStore))
ReadTheLpa(tmpls.Get("read_the_lpa.gohtml"), donorStore, attorneyStore))
handleAttorney(page.Paths.Attorney.RightsAndResponsibilities, RequireAttorney,
Guidance(tmpls.Get("attorney_legal_rights_and_responsibilities.gohtml"), nil))
Guidance(tmpls.Get("legal_rights_and_responsibilities.gohtml"), nil))
handleAttorney(page.Paths.Attorney.WhatHappensWhenYouSign, RequireAttorney,
Guidance(tmpls.Get("attorney_what_happens_when_you_sign.gohtml"), donorStore))
Guidance(tmpls.Get("what_happens_when_you_sign.gohtml"), donorStore))
handleAttorney(page.Paths.Attorney.Sign, RequireAttorney,
Sign(tmpls.Get("attorney_sign.gohtml"), donorStore, certificateProviderStore, attorneyStore, lpaStoreClient, time.Now))
Sign(tmpls.Get("sign.gohtml"), donorStore, certificateProviderStore, attorneyStore, lpaStoreClient, time.Now))
handleAttorney(page.Paths.Attorney.WouldLikeSecondSignatory, RequireAttorney,
WouldLikeSecondSignatory(tmpls.Get("attorney_would_like_second_signatory.gohtml"), attorneyStore, donorStore, lpaStoreClient))
WouldLikeSecondSignatory(tmpls.Get("would_like_second_signatory.gohtml"), attorneyStore, donorStore, lpaStoreClient))
handleAttorney(page.Paths.Attorney.WhatHappensNext, RequireAttorney,
Guidance(tmpls.Get("attorney_what_happens_next.gohtml"), donorStore))
Guidance(tmpls.Get("what_happens_next.gohtml"), donorStore))
handleAttorney(page.Paths.Attorney.Progress, RequireAttorney,
Progress(tmpls.Get("attorney_progress.gohtml"), attorneyStore, donorStore))
Progress(tmpls.Get("progress.gohtml"), attorneyStore, donorStore))
}

type handleOpt byte
Expand Down
2 changes: 1 addition & 1 deletion internal/page/attorney/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

func TestRegister(t *testing.T) {
mux := http.NewServeMux()
Register(mux, nil, template.Templates{}, nil, nil, nil, nil, nil, nil, nil, nil, &mockDashboardStore{}, &lpastore.Client{})
Register(mux, nil, template.Templates{}, template.Templates{}, nil, nil, nil, nil, nil, nil, nil, nil, &mockDashboardStore{}, &lpastore.Client{})

assert.Implements(t, (*http.Handler)(nil), mux)
}
Expand Down
26 changes: 13 additions & 13 deletions internal/page/certificateprovider/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type ErrorHandler func(http.ResponseWriter, *http.Request, error)
func Register(
rootMux *http.ServeMux,
logger Logger,
tmpls template.Templates,
commonTmpls, tmpls template.Templates,
sessionStore SessionStore,
donorStore DonorStore,
oneLoginClient OneLoginClient,
Expand All @@ -114,38 +114,38 @@ func Register(
handleRoot(page.Paths.CertificateProvider.LoginCallback,
page.LoginCallback(oneLoginClient, sessionStore, page.Paths.CertificateProvider.EnterReferenceNumber, dashboardStore, actor.TypeCertificateProvider))
handleRoot(page.Paths.CertificateProvider.EnterReferenceNumber,
EnterReferenceNumber(tmpls.Get("certificate_provider_enter_reference_number.gohtml"), shareCodeStore, sessionStore, certificateProviderStore))
EnterReferenceNumber(tmpls.Get("enter_reference_number.gohtml"), shareCodeStore, sessionStore, certificateProviderStore))

certificateProviderMux := http.NewServeMux()
rootMux.Handle("/certificate-provider/", page.RouteToPrefix("/certificate-provider/", certificateProviderMux, notFoundHandler))
handleCertificateProvider := makeCertificateProviderHandle(certificateProviderMux, sessionStore, errorHandler)

handleCertificateProvider(page.Paths.CertificateProvider.WhoIsEligible, page.None,
WhoIsEligible(tmpls.Get("certificate_provider_who_is_eligible.gohtml"), donorStore))
WhoIsEligible(tmpls.Get("who_is_eligible.gohtml"), donorStore))
handleCertificateProvider(page.Paths.CertificateProvider.TaskList, page.None,
TaskList(tmpls.Get("certificate_provider_task_list.gohtml"), donorStore, certificateProviderStore))
TaskList(tmpls.Get("task_list.gohtml"), donorStore, certificateProviderStore))
handleCertificateProvider(page.Paths.CertificateProvider.EnterDateOfBirth, page.CanGoBack,
EnterDateOfBirth(tmpls.Get("certificate_provider_enter_date_of_birth.gohtml"), donorStore, certificateProviderStore))
EnterDateOfBirth(tmpls.Get("enter_date_of_birth.gohtml"), donorStore, certificateProviderStore))
handleCertificateProvider(page.Paths.CertificateProvider.YourPreferredLanguage, page.CanGoBack,
YourPreferredLanguage(tmpls.Get("your_preferred_language.gohtml"), certificateProviderStore, donorStore))
YourPreferredLanguage(commonTmpls.Get("your_preferred_language.gohtml"), certificateProviderStore, donorStore))
handleCertificateProvider(page.Paths.CertificateProvider.WhatIsYourHomeAddress, page.None,
WhatIsYourHomeAddress(logger, tmpls.Get("certificate_provider_what_is_your_home_address.gohtml"), addressClient, certificateProviderStore))
WhatIsYourHomeAddress(logger, tmpls.Get("what_is_your_home_address.gohtml"), addressClient, certificateProviderStore))
handleCertificateProvider(page.Paths.CertificateProvider.ConfirmYourDetails, page.None,
ConfirmYourDetails(tmpls.Get("certificate_provider_confirm_your_details.gohtml"), donorStore, certificateProviderStore))
ConfirmYourDetails(tmpls.Get("confirm_your_details.gohtml"), donorStore, certificateProviderStore))
handleCertificateProvider(page.Paths.CertificateProvider.YourRole, page.CanGoBack,
Guidance(tmpls.Get("certificate_provider_your_role.gohtml"), donorStore, nil))
Guidance(tmpls.Get("your_role.gohtml"), donorStore, nil))

handleCertificateProvider(page.Paths.CertificateProvider.ProveYourIdentity, page.None,
Guidance(tmpls.Get("certificate_provider_prove_your_identity.gohtml"), nil, nil))
Guidance(tmpls.Get("prove_your_identity.gohtml"), nil, nil))
handleCertificateProvider(page.Paths.CertificateProvider.IdentityWithOneLogin, page.None,
IdentityWithOneLogin(oneLoginClient, sessionStore, random.String))
handleCertificateProvider(page.Paths.CertificateProvider.IdentityWithOneLoginCallback, page.None,
IdentityWithOneLoginCallback(tmpls.Get("identity_with_one_login_callback.gohtml"), oneLoginClient, sessionStore, certificateProviderStore, donorStore))
IdentityWithOneLoginCallback(commonTmpls.Get("identity_with_one_login_callback.gohtml"), oneLoginClient, sessionStore, certificateProviderStore, donorStore))

handleCertificateProvider(page.Paths.CertificateProvider.ReadTheLpa, page.None,
ReadTheLpa(tmpls.Get("certificate_provider_read_the_lpa.gohtml"), donorStore, certificateProviderStore))
ReadTheLpa(tmpls.Get("read_the_lpa.gohtml"), donorStore, certificateProviderStore))
handleCertificateProvider(page.Paths.CertificateProvider.WhatHappensNext, page.CanGoBack,
Guidance(tmpls.Get("certificate_provider_what_happens_next.gohtml"), donorStore, nil))
Guidance(tmpls.Get("what_happens_next.gohtml"), donorStore, nil))
handleCertificateProvider(page.Paths.CertificateProvider.ProvideCertificate, page.CanGoBack,
ProvideCertificate(tmpls.Get("provide_certificate.gohtml"), donorStore, certificateProviderStore, notifyClient, shareCodeSender, lpaStoreClient, time.Now))
handleCertificateProvider(page.Paths.CertificateProvider.CertificateProvided, page.None,
Expand Down
2 changes: 1 addition & 1 deletion internal/page/certificateprovider/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func TestRegister(t *testing.T) {
mux := http.NewServeMux()
Register(mux, &log.Logger{}, template.Templates{}, nil, nil, &onelogin.Client{}, nil, nil, nil, nil, &place.Client{}, &notify.Client{}, nil, &mockDashboardStore{}, nil)
Register(mux, &log.Logger{}, template.Templates{}, template.Templates{}, nil, nil, &onelogin.Client{}, nil, nil, nil, nil, &place.Client{}, &notify.Client{}, nil, &mockDashboardStore{}, nil)

assert.Implements(t, (*http.Handler)(nil), mux)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/page/donor/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type ErrorHandler func(http.ResponseWriter, *http.Request, error)
func Register(
rootMux *http.ServeMux,
logger Logger,
tmpls template.Templates,
commonTmpls, tmpls template.Templates,
sessionStore SessionStore,
donorStore DonorStore,
oneLoginClient OneLoginClient,
Expand Down Expand Up @@ -210,7 +210,7 @@ func Register(
handleWithDonor(page.Paths.WeHaveUpdatedYourDetails, page.None,
Guidance(tmpls.Get("we_have_updated_your_details.gohtml")))
handleWithDonor(page.Paths.YourPreferredLanguage, page.None,
YourPreferredLanguage(tmpls.Get("your_preferred_language.gohtml"), donorStore))
YourPreferredLanguage(commonTmpls.Get("your_preferred_language.gohtml"), donorStore))
handleWithDonor(page.Paths.LpaType, page.None,
LpaType(tmpls.Get("lpa_type.gohtml"), donorStore))
handleWithDonor(page.Paths.CheckYouCanSign, page.None,
Expand Down Expand Up @@ -350,7 +350,7 @@ func Register(
handleWithDonor(page.Paths.IdentityWithOneLogin, page.CanGoBack,
IdentityWithOneLogin(oneLoginClient, sessionStore, random.String))
handleWithDonor(page.Paths.IdentityWithOneLoginCallback, page.CanGoBack,
IdentityWithOneLoginCallback(tmpls.Get("identity_with_one_login_callback.gohtml"), oneLoginClient, sessionStore, donorStore))
IdentityWithOneLoginCallback(commonTmpls.Get("identity_with_one_login_callback.gohtml"), oneLoginClient, sessionStore, donorStore))

handleWithDonor(page.Paths.ReadYourLpa, page.None,
Guidance(tmpls.Get("read_your_lpa.gohtml")))
Expand Down
2 changes: 1 addition & 1 deletion internal/page/donor/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestRegister(t *testing.T) {
mux := http.NewServeMux()
Register(mux, &log.Logger{}, template.Templates{}, nil, nil, &onelogin.Client{}, &place.Client{}, "http://example.org", &pay.Client{}, nil, &mockWitnessCodeSender{}, nil, nil, nil, nil, &notify.Client{}, nil, nil, nil, nil, nil)
Register(mux, &log.Logger{}, template.Templates{}, template.Templates{}, nil, nil, &onelogin.Client{}, &place.Client{}, "http://example.org", &pay.Client{}, nil, &mockWitnessCodeSender{}, nil, nil, nil, nil, &notify.Client{}, nil, nil, nil, nil, nil)

assert.Implements(t, (*http.Handler)(nil), mux)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3e172ba

Please sign in to comment.