Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BRP-5: Re-route duplicate application requests to separate email address. #769

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ unit_tests: &unit_tests

sonar_scanner: &sonar_scanner
pull: if-not-exists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it doesn't work just add a comment saying usually good practice is to have a version number a sha pointing to the image because you don't want to grab the latest one in case it gets updated

image: quay.io/ukhomeofficedigital/sonar-scanner-node:549b75f593f28da1c4a0a6f79877ec69d3b21037
image: quay.io/ukhomeofficedigital/sonar-scanner-nodejs:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s usually good idea to avoid latest as it will keep updating the image for every deployment to the latest one. Ideally it’ll be good to take a specific sha

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you give this one a try sha256:dcc00d2581fdca090c171d4ae53d2a49b3a3bbb08a96cdaa4933a041d0ba2a42

commands:
- sonar-scanner -Dproject.settings=./sonar-project.properties

Expand Down
8 changes: 8 additions & 0 deletions apps/collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ module.exports = {
baseUrl: '/collection',
params: '/:action?',
steps: {
'/previous-submission': {
fields: [
'previous-submission',
'submission-reference'
],
next: '/where'
},
'/where': {
fields: [
'collection-where-radio',
'collection-date'
],
backLink: 'previous-submission',
next: '/reasons'
},
'/reasons': {
Expand Down
20 changes: 20 additions & 0 deletions apps/collection/views/previous-submission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{<partials-page}}
{{$journeyHeader}}
{{#t}}journeys.collection.header{{/t}}
{{/journeyHeader}}
{{$content}}
{{<partials-form}}

{{$form}}
{{#radio-group}}previous-submission{{/radio-group}}
<fieldset id="previous-submission-reference-group" class="panel-indent">
<div class="form-group">
{{#input-text}}submission-reference{{/input-text}}
</div>
</fieldset>

{{#input-submit}}continue{{/input-submit}}
{{/form}}
{{/partials-form}}
{{/content}}
{{/partials-page}}
49 changes: 41 additions & 8 deletions apps/common/behaviours/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,43 @@ const StatsD = require('hot-shots');
const client = new StatsD();
const Model = require('../models/email');

const {customAlphabet} = require('nanoid');
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const nanoid = customAlphabet(alphabet, 9);

function errorChecked(key, data) {
if (data[key + '-checkbox']) {
return key;
}
}

function setSubmissionReference(data) {
// This function is responsible for storing a submission referene if one is required
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This function is responsible for storing a submission referene if one is required
// This function is responsible for storing a submission reference if one is required


// Did the user say this is a resubmission?
if (data['previous-submission'] === 'yes') {
// Yes they did - Mark this as a resubmission for easier assessment when sending the email to caseworkers
data['is-resubmission'] = true;
// Did the user provide a reference for their previous submission?
// If they did, we should keep it the same
// If they did not, we should not populate the reference in
// the emails that are sent out so ensure this remains undefined
data['submission-reference'] = (data['submission-reference'] ? data['submission-reference'] : undefined);
} else {
data['is-resubmission'] = false;
// It's a new submission so generate a reference
data['submission-reference'] = nanoid();
}
}

function addSubmissionReference(data) {
// If we do not already have a submission reference, create one and store it in our data object
// We may want to re-use this later
setSubmissionReference(data);
// Ensure there's a space in front of it, since this is being appended to the end of the email subject
return !!data['submission-reference'] ? ` Ref: ${data['submission-reference']}` : '';
}

function checkedErrors(data) {
const checked = _.filter(_.keys(data), valueKey => {
return errorChecked(valueKey, data);
Expand All @@ -20,10 +51,10 @@ function checkedErrors(data) {
}

const serviceMap = {
'/not-arrived': () => {
'/not-arrived': data => {
return {
template: 'delivery',
subject: 'Form submitted: Your BRP hasn\'t arrived.'
subject: `Form submitted: Your BRP hasn\'t arrived.${addSubmissionReference(data)}`
};
},
'/correct-mistakes': data => {
Expand All @@ -34,26 +65,26 @@ const serviceMap = {
const suffix = data.triage ? '-triage' : '';
return {
template: 'error' + suffix,
subject: 'Form submitted: Report a problem with your new BRP (' + subjectErrors + ')'
subject: `Form submitted: Report a problem with your new BRP (${subjectErrors}).${addSubmissionReference(data)}`
};
},
'/lost-stolen': data => {
const suffix = (data['inside-uk'] === 'yes') ? '-uk' : '-abroad';
return {
template: 'lost-or-stolen' + suffix,
subject: 'Form submitted: Report a lost or stolen BRP.'
subject: `Form submitted: Report a lost or stolen BRP.${addSubmissionReference(data)}`
};
},
'/collection': () => {
'/collection': data => {
return {
template: 'collection',
subject: 'Form submitted: Report a collection problem.'
subject: `Form submitted: Report a collection problem.${addSubmissionReference(data)}`
};
},
'/someone-else': () => {
'/someone-else': data => {
return {
template: 'someone-else',
subject: 'Form submitted: Report someone else collecting your BRP.'
subject: `Form submitted: Report someone else collecting your BRP.${addSubmissionReference(data)}`
};
}
};
Expand All @@ -62,6 +93,8 @@ module.exports = superclass => class Emailer extends superclass {
saveValues(req, res, callback) {
super.saveValues(req, res, () => {
const data = _.pick(req.sessionModel.toJSON(), _.identity);

// Generate a reference for this submission
const service = serviceMap[req.baseUrl] && serviceMap[req.baseUrl](data);

if (!service) {
Expand Down
1 change: 1 addition & 0 deletions apps/common/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
module.exports = Object.assign({},
require('./contact-details'),
require('./personal-details'),
require('./previous-submission'),
require('./organisation-details')
);
25 changes: 25 additions & 0 deletions apps/common/fields/previous-submission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use-strict';

module.exports = {
'previous-submission': {
mixin: 'radio-group',
validate: ['required'],
className: ['inline', 'form-group'],
legend: {
className: 'visuallyhidden'
},
options: [{
value: 'yes',
toggle: 'previous-submission-reference-group'
}, {
value: 'no'
}]
},
'submission-reference': {
validate: [ {type: 'regex', arguments: /^[A-Za-z0-9]{9}$|(^$)+/g }],
dependent: {
field: 'previous-submission',
value: 'yes'
}
}
};
1 change: 1 addition & 0 deletions apps/common/models/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = class Email extends Model {
template: this.get('template'),
to: this.get('email'),
subject: this.get('subject'),
isResubmission: this.get('is-resubmission'),
dataToSend: _.omit(this.toJSON(), ['steps', 'csrf-secret', 'template'])
}, callback);
}
Expand Down
15 changes: 15 additions & 0 deletions apps/common/translations/src/en/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,20 @@
"label": "Support organisation"
}
}
},
"previous-submission": {
"label": "Have you previously submitted this request?",
"options": {
"yes": {
"label": "Yes"
},
"no": {
"label": "No"
}
}
},
"submission-reference": {
"label": "What is the reference for this request?",
"hint": "For example ZxeJ8vfBI"
}
}
5 changes: 5 additions & 0 deletions apps/common/translations/src/en/pages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"previous-submission": {
"header": "Have you previously submitted this request?"
}
}
6 changes: 6 additions & 0 deletions apps/common/translations/src/en/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@
"fullname": {
"required": "Enter your full name",
"notUrl": "Full name must not be a URL"
},
"previous-submission": {
"required": "Have you previously submitted this request?"
},
"submission-reference": {
"regex": "Please enter a 9 digit reference code"
}
}
8 changes: 8 additions & 0 deletions apps/correct-mistakes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ module.exports = {
params: '/:action?',
behaviours: [require('../common/behaviours/location')],
steps: {
'/previous-submission': {
fields: [
'previous-submission',
'submission-reference'
],
next: '/location'
},
'/location': {
template: 'location-applied',
fields: [
'location-applied'
],
backLink: 'previous-submission',
next: '/about-error'
},
'/about-error': {
Expand Down
20 changes: 20 additions & 0 deletions apps/correct-mistakes/views/previous-submission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{<partials-page}}
{{$journeyHeader}}
{{#t}}journeys.error.header{{/t}}
{{/journeyHeader}}
{{$content}}
{{<partials-form}}

{{$form}}
{{#radio-group}}previous-submission{{/radio-group}}
<fieldset id="previous-submission-reference-group" class="panel-indent">
<div class="form-group">
{{#input-text}}submission-reference{{/input-text}}
</div>
</fieldset>

{{#input-submit}}continue{{/input-submit}}
{{/form}}
{{/partials-form}}
{{/content}}
{{/partials-page}}
8 changes: 8 additions & 0 deletions apps/lost-stolen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ module.exports = {
params: '/:action?',
behaviours: [require('../common/behaviours/location')],
steps: {
'/previous-submission': {
fields: [
'previous-submission',
'submission-reference'
],
next: '/where'
},
'/where': {
fields: ['inside-uk', 'country'],
backLink: 'previous-submission',
next: '/date-lost'
},
'/date-lost': {
Expand Down
20 changes: 20 additions & 0 deletions apps/lost-stolen/views/previous-submission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{<partials-page}}
{{$journeyHeader}}
{{#t}}journeys.lost.header{{/t}}
{{/journeyHeader}}
{{$content}}
{{<partials-form}}

{{$form}}
{{#radio-group}}previous-submission{{/radio-group}}
<fieldset id="previous-submission-reference-group" class="panel-indent">
<div class="form-group">
{{#input-text}}submission-reference{{/input-text}}
</div>
</fieldset>

{{#input-submit}}continue{{/input-submit}}
{{/form}}
{{/partials-form}}
{{/content}}
{{/partials-page}}
10 changes: 9 additions & 1 deletion apps/not-arrived/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ module.exports = {
baseUrl: '/not-arrived',
params: '/:action?',
steps: {
'/previous-submission': {
fields: [
'previous-submission',
'submission-reference'
],
next: '/post-office-collect'
},
'/post-office-collect': {
backLink: 'previous-submission',
next: '/consignment-number',
behaviours: [require('./behaviours/change-path')],
template: 'collection.html',
Expand Down Expand Up @@ -90,7 +98,7 @@ module.exports = {
next: '/confirm'
},
'/confirm': {
behaviours: [ require('../common/behaviours/email')],
behaviours: ['complete', require('../common/behaviours/email')],
fields: [
'org-help',
'rep-name',
Expand Down
20 changes: 20 additions & 0 deletions apps/not-arrived/views/previous-submission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{<partials-page}}
{{$journeyHeader}}
{{#t}}journeys.delivery.header{{/t}}
{{/journeyHeader}}
{{$content}}
{{<partials-form}}

{{$form}}
{{#radio-group}}previous-submission{{/radio-group}}
<fieldset id="previous-submission-reference-group" class="panel-indent">
<div class="form-group">
{{#input-text}}submission-reference{{/input-text}}
</div>
</fieldset>

{{#input-submit}}continue{{/input-submit}}
{{/form}}
{{/partials-form}}
{{/content}}
{{/partials-page}}
8 changes: 8 additions & 0 deletions apps/someone-else/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ module.exports = {
baseUrl: '/someone-else',
params: '/:action?',
steps: {
'/previous-submission': {
fields: [
'previous-submission',
'submission-reference'
],
next: '/arrange'
},
'/arrange': {
behaviours: [require('./behaviours/someone-else-brp')],
fields: [
Expand All @@ -14,6 +21,7 @@ module.exports = {
'someone-else-id-type',
'someone-else-id-number'
],
backLink: 'previous-submission',
next: '/reason'
},
'/reason': {
Expand Down
20 changes: 20 additions & 0 deletions apps/someone-else/views/previous-submission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{<partials-page}}
{{$journeyHeader}}
{{#t}}journeys.someone-else.header{{/t}}
{{/journeyHeader}}
{{$content}}
{{<partials-form}}

{{$form}}
{{#radio-group}}previous-submission{{/radio-group}}
<fieldset id="previous-submission-reference-group" class="panel-indent">
<div class="form-group">
{{#input-text}}submission-reference{{/input-text}}
</div>
</fieldset>

{{#input-submit}}continue{{/input-submit}}
{{/form}}
{{/partials-form}}
{{/content}}
{{/partials-page}}
Loading