Skip to content

Commit 17116ad

Browse files
author
JHjava
authored
Merge pull request #524 from alphagov/auth-1385-add-referrer
AUTH-1385 - Add referer to Zendesk api
2 parents 5d45865 + e5e3a96 commit 17116ad

22 files changed

Lines changed: 135 additions & 23 deletions

src/components/contact-us/contact-us-controller.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,24 @@ export function contactUsGet(req: Request, res: Response): void {
3737
if (req.query.supportType === SUPPORT_TYPE.GOV_SERVICE) {
3838
return res.render("contact-us/index-gov-service-contact-us.njk");
3939
}
40+
let fromPage = req.headers.referer;
4041

41-
return res.render("contact-us/index-public-contact-us.njk");
42+
if (req.headers.referer && req.headers.referer.includes("fromPage")) {
43+
const urlObj = new URL(req.headers.referer);
44+
fromPage = urlObj.searchParams.get("fromPage");
45+
}
46+
47+
return res.render("contact-us/index-public-contact-us.njk", {
48+
fromPage: fromPage,
49+
});
4250
}
4351

4452
export function contactUsFormPost(req: Request, res: Response): void {
4553
let url = PATH_NAMES.CONTACT_US_QUESTIONS;
46-
const queryParams = new URLSearchParams({ theme: req.body.theme }).toString();
54+
const queryParams = new URLSearchParams({
55+
theme: req.body.theme,
56+
fromPage: req.body.fromPage,
57+
}).toString();
4758
if (
4859
[ZENDESK_THEMES.ACCOUNT_CREATION, ZENDESK_THEMES.SIGNING_IN].includes(
4960
req.body.theme
@@ -55,8 +66,12 @@ export function contactUsFormPost(req: Request, res: Response): void {
5566
}
5667

5768
export function furtherInformationGet(req: Request, res: Response): void {
69+
if (!req.query.theme) {
70+
return res.redirect(PATH_NAMES.CONTACT_US);
71+
}
5872
return res.render("contact-us/further-information/index.njk", {
5973
theme: req.query.theme,
74+
fromPage: req.query.fromPage,
6075
});
6176
}
6277

@@ -65,12 +80,16 @@ export function furtherInformationPost(req: Request, res: Response): void {
6580
const queryParams = new URLSearchParams({
6681
theme: req.body.theme,
6782
subtheme: req.body.subtheme,
83+
fromPage: req.body.fromPage,
6884
}).toString();
6985

7086
res.redirect(url + "?" + queryParams);
7187
}
7288

7389
export function contactUsQuestionsGet(req: Request, res: Response): void {
90+
if (!req.query.theme) {
91+
return res.redirect(PATH_NAMES.CONTACT_US);
92+
}
7493
let pageTitle = themeToPageTitle[req.query.theme as string];
7594
if (
7695
req.query.subtheme === ZENDESK_THEMES.SOMETHING_ELSE &&
@@ -84,6 +103,7 @@ export function contactUsQuestionsGet(req: Request, res: Response): void {
84103
theme: req.query.theme,
85104
subtheme: req.query.subtheme,
86105
backurl: req.headers.referer,
106+
fromPage: req.query.fromPage,
87107
pageTitleHeading: pageTitle,
88108
});
89109
}
@@ -116,6 +136,7 @@ export function contactUsQuestionsFormPost(
116136
feedbackContact: req.body.contact === "true",
117137
questions: questions,
118138
themeQuestions: themeQuestions,
139+
referer: req.body.fromPage,
119140
});
120141

121142
return res.redirect(PATH_NAMES.CONTACT_US_SUBMIT_SUCCESS);

src/components/contact-us/contact-us-service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export function contactUsService(
2525
contactForm.descriptions,
2626
contactForm.optionalData,
2727
contactForm.questions,
28-
contactForm.themeQuestions
28+
contactForm.themeQuestions,
29+
contactForm.referer
2930
),
3031
},
3132
group_id: getZendeskGroupIdPublic(),
@@ -47,7 +48,8 @@ export function contactUsService(
4748
descriptions: Descriptions,
4849
optionalData: OptionalData,
4950
questions: Questions,
50-
themeQuestions: ThemeQuestions
51+
themeQuestions: ThemeQuestions,
52+
referer: string
5153
) {
5254
const htmlBody = [];
5355

@@ -77,6 +79,13 @@ export function contactUsService(
7779
htmlBody.push(`<span>[Session ID]</span>`);
7880
htmlBody.push(`<p>${optionalData.sessionId}</p>`);
7981

82+
htmlBody.push(`<span>[From page]</span>`);
83+
if (referer) {
84+
htmlBody.push(`<p>${referer}</p>`);
85+
} else {
86+
htmlBody.push(`<p>Unable to capture referer</p>`);
87+
}
88+
8089
htmlBody.push(`<span>[User Agent]</span>`);
8190
htmlBody.push(`<p>${optionalData.userAgent}</p>`);
8291

src/components/contact-us/further-information/_account-creation-further-information.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<input type="hidden" name="_csrf" value="{{csrfToken}}"/>
88
<input type="hidden" name="theme" value="{{theme}}"/>
9+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
910

1011
{{ govukRadios({
1112
idPrefix: "account-creation",

src/components/contact-us/further-information/_signing-in-further-information.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<input type="hidden" name="_csrf" value="{{csrfToken}}"/>
88
<input type="hidden" name="theme" value="{{theme}}"/>
9+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
910

1011
{{ govukRadios({
1112
idPrefix: "signing-in",

src/components/contact-us/index-public-contact-us.njk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{% from "govuk/components/warning-text/macro.njk" import govukWarningText %}
88

99
{% set showBack = true %}
10-
{% set hrefBack = 'support' %}
10+
{% set hrefBack = fromPage %}
1111
{% set pageTitleName = 'pages.contactUsPublic.title' | translate %}
1212

1313
{% block content %}
@@ -34,6 +34,7 @@
3434
<form action="/contact-us" method="post" novalidate>
3535

3636
<input type="hidden" name="_csrf" value="{{csrfToken}}"/>
37+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
3738

3839
{{ govukRadios({
3940
idPrefix: "contact-us",

src/components/contact-us/questions/_account-creation-problem-questions.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<input type="hidden" name="subtheme" value="{{subtheme}}"/>
1010
<input type="hidden" name="backurl" value="{{backurl}}"/>
1111
<input type="hidden" name="formType" value="accountCreationProblem"/>
12+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
1213

1314
{{ govukTextarea({
1415
label: {

src/components/contact-us/questions/_account-not-found-questions.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<input type="hidden" name="subtheme" value="{{subtheme}}"/>
1010
<input type="hidden" name="backurl" value="{{backurl}}"/>
1111
<input type="hidden" name="formType" value="accountNotFound"/>
12+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
1213

1314
{{ govukTextarea({
1415
label: {

src/components/contact-us/questions/_another-problem-questions.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<input type="hidden" name="subtheme" value="{{subtheme}}"/>
1010
<input type="hidden" name="backurl" value="{{backurl}}"/>
1111
<input type="hidden" name="formType" value="accountProblem"/>
12+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
1213

1314
{{ govukTextarea({
1415
label: {

src/components/contact-us/questions/_email-subscriptions-questions.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<input type="hidden" name="theme" value="{{theme}}"/>
99
<input type="hidden" name="backurl" value="{{backurl}}"/>
1010
<input type="hidden" name="formType" value="emailSubscription"/>
11+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
1112

1213
{{ govukTextarea({
1314
label: {

src/components/contact-us/questions/_forgotten-password-questions.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<input type="hidden" name="subtheme" value="{{subtheme}}"/>
1010
<input type="hidden" name="backurl" value="{{backurl}}"/>
1111
<input type="hidden" name="formType" value="forgottenPassword"/>
12+
<input type="hidden" name="fromPage" value="{{fromPage}}"/>
1213

1314
{{ govukTextarea({
1415
label: {

0 commit comments

Comments
 (0)