Skip to content

Commit

Permalink
HOFF-659: Update NRM to use version of HOF that uses axios
Browse files Browse the repository at this point in the history
- update hof version to use axios
- remove request module in package.json
- update notifications-node-client version to fix vulnerabilities
- update knex version to fix vulnerabilities
- amend node env for dev:api script in package.json
- update yarn.lock
- refactored code in save-form-session, resume-form-session, delete-form-session, are-you-sure and continue-report behaviours to use hof model instead of request
- update icasework resolver image in kube/icasework-resolver.yml
- amended some html files that were breaking the app due to govuk design updates in hof version containing axios update
- update snyk ignore list
- ignore acceptance test in drone on failure as test needs to be refactored to no longer need request
- add PR template
  • Loading branch information
Rhodine-orleans-lindsay committed Jul 15, 2024
1 parent f746e25 commit 12f214b
Show file tree
Hide file tree
Showing 24 changed files with 7,106 additions and 141 deletions.
61 changes: 21 additions & 40 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,31 @@ version: v1.22.1
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JS-AXIOS-6032459:
- '*':
reason: will be resolved with HOFF-659
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z

- hof > notifications-node-client > axios:
reason: Need to update notifications-node-client in HOF to version 8.0.0
expires: '2024-06-21T00:00:00.000Z'
SNYK-JS-AXIOS-6124857:
- '*':
reason: will be resolved with HOFF-659
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z

- hof > notifications-node-client > axios:
reason: Need to update notifications-node-client in HOF to version 8.0.0.
expires: '2024-06-21T00:00:00.000Z'
SNYK-JS-AXIOS-6144788:
- hof > notifications-node-client > axios:
reason: Need to update notifications-node-client in HOF to version 8.0.0.
expires: '2024-06-21T00:00:00.000Z'
SNYK-JS-FOLLOWREDIRECTS-6444610:
- '*':
reason: will be resolved with HOFF-659
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z

SNYK-JS-MARKDOWNIT-6483324:
- '*':
reason: No upgrade or patch available yet
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z

reason: Need to update follow-redirects in HOF to version 1.15.6.
expires: '2024-06-21T00:00:00.000Z'
SNYK-JS-INFLIGHT-6095116:
- '*':
reason: No upgrade or patch available yet
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z

SNYK-JS-REQUEST-3361831:
reason: No update available.
expires: '2024-06-21T00:00:00.000Z'
SNYK-JS-EXPRESS-6474509:
- '*':
reason: No upgrade or patch available yet
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z

SNYK-JS-TOUGHCOOKIE-5672873:
- '*':
reason: will be resolved with HOFF-659
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z
SNYK-JS-BRACES-6838727:
- '*':
reason: No upgrade or patch available
expires: 2024-07-16T00:00:00.000Z
created: 2024-04-16T11:0522.224Z

reason: Need to update express to version 4.19.2.
expires: '2024-07-05T00:00:00.000Z'
SNYK-JS-MARKDOWNIT-6483324:
- hof > markdown-it:
reason: Need to update markdown-it in HOF to version 13.0.2.
expires: '2024-07-05T00:00:00.000Z'
patch: {}
14 changes: 9 additions & 5 deletions apps/nrm/behaviours/are-you-sure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const request = require('request');
const Model = require('hof').model;
const config = require('../../../config');
const baseUrl = config.saveService.host + ':' + config.saveService.port + '/reports/';

Expand All @@ -25,12 +25,16 @@ module.exports = superclass => class extends superclass {

if (id) {
const email = encodeEmail(req.sessionModel.get('user-email'));
const model = new Model();
const params = {
url: baseUrl + email + '/' + id,
method: 'DELETE'
};

return request.del(baseUrl + email + '/' + id, err => {
if (err) {
return next(err);
}
return model._request(params).then(() => {
return super.saveValues(req, res, next);
}).catch(err => {
return next(err);
});
}
return super.saveValues(req, res, next);
Expand Down
19 changes: 10 additions & 9 deletions apps/nrm/behaviours/continue-report.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const request = require('request');
const Model = require('hof').model;
const config = require('../../../config');
const baseUrl = config.saveService.host + ':' + config.saveService.port + '/reports/';

Expand All @@ -25,14 +25,13 @@ module.exports = superclass => class extends superclass {
}

this.cleanSession(req);

const getUrl = baseUrl + encodeEmail(req.sessionModel.get('user-email')) + '/' + id;

return request.get(getUrl, (error, response, body) => {
if (error) {
return next(error);
}
const resBody = JSON.parse(body);
const model = new Model();
const params = {
url: baseUrl + encodeEmail(req.sessionModel.get('user-email')) + '/' + id,
method: 'GET'
};
return model._request(params).then(response => {
const resBody = response.data;

if (resBody && resBody.length && resBody[0].session) {
if (resBody[0].session.hasOwnProperty('alertUser')) {
Expand All @@ -52,6 +51,8 @@ module.exports = superclass => class extends superclass {
}

return super.getValues(req, res, next);
}).catch(error => {
return next(error);
});
}

Expand Down
16 changes: 13 additions & 3 deletions apps/nrm/behaviours/delete-form-session.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const request = require('request');
const Model = require('hof').model;
const config = require('../../../config');

const encodeEmail = email => Buffer.from(email).toString('hex');
Expand All @@ -10,8 +10,18 @@ module.exports = superclass => class extends superclass {
if (err) {
next(err);
}
request.del(config.saveService.host + ':' + config.saveService.port
+ '/reports/' + encodeEmail(req.sessionModel.get('user-email')) + '/' + req.sessionModel.get('id'), next);
const model = new Model();
const params = {
url: config.saveService.host + ':' + config.saveService.port
+ '/reports/' + encodeEmail(req.sessionModel.get('user-email')) + '/' + req.sessionModel.get('id'),
method: 'DELETE'
};

return model._request(params).then(() => {
next();
}).catch(error => {
next(error);
});
});
}
};
75 changes: 40 additions & 35 deletions apps/nrm/behaviours/resume-form-session.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable consistent-return */
'use strict';

const request = require('request');
const Model = require('hof').model;
const config = require('../../../config');
const moment = require('moment');
const baseUrl = config.saveService.host + ':' + config.saveService.port + '/reports/';
Expand Down Expand Up @@ -45,39 +45,44 @@ module.exports = superclass => class extends superclass {
if (config.env === 'local' || config.env === 'test') {
return super.getValues(req, res, next);
}

return request.get(baseUrl + encodeEmail(req.sessionModel.get('user-email')), (err, response, body) => {
if (err) {
return next(err);
}

const resBody = JSON.parse(body);

if (resBody && resBody.length && resBody[0].session) {
req.previousReports = [];

resBody.forEach(report => {
const created = moment(report.created_at);
const expires = moment(report.updated_at).add(config.reports.deletionTimeout, 'days').endOf('day');
const remaining = expires.diff(moment(), 'days');

req.log('info', `External ID: ${externalID}, Report Session ID: ${report.id}`);
req.log('info', `External ID: ${externalID}, Report Session Reference: ${report.session.reference}`);
req.log('info', `External ID: ${externalID}, Report Created at: ${created.format('DD MMMM YYYY')}`);
req.log('info', `External ID: ${externalID}, Report Expires at: ${expires.format('DD MMMM YYYY')}`);

const rep = {
id: report.id,
reference: report.session.reference,
createdAt: created.format('DD MMMM YYYY'),
expiresAt: expires.format('DD MMMM YYYY'),
daysRemaining: remaining
};
req.previousReports.push(rep);
});
}
req.sessionModel.set('redirect-to-reports', false);
return super.getValues(req, res, next);
});
const model = new Model();
const params = {
url: baseUrl + encodeEmail(req.sessionModel.get('user-email')),
method: 'GET'
};
return model._request(params)
.then(response => {
const resBody = response.data;

if (resBody && resBody.length && resBody[0].session) {
req.previousReports = [];

resBody.forEach(report => {
const created = moment(report.created_at);
const expires = moment(report.updated_at).add(config.reports.deletionTimeout, 'days').endOf('day');
const remaining = expires.diff(moment(), 'days');

req.log('info', `External ID: ${externalID}, Report Session ID: ${report.id}`);
req.log('info', `External ID: ${externalID}, Report Session Reference: ${report.session.reference}`);
req.log('info', `External ID: ${externalID}, Report Created at: ${created.format('DD MMMM YYYY')}`);
req.log('info', `External ID: ${externalID}, Report Expires at: ${expires.format('DD MMMM YYYY')}`);

const rep = {
id: report.id,
reference: report.session.reference,
createdAt: created.format('DD MMMM YYYY'),
expiresAt: expires.format('DD MMMM YYYY'),
daysRemaining: remaining
};
req.previousReports.push(rep);
});
}
req.sessionModel.set('redirect-to-reports', false);
return super.getValues(req, res, next);
})
.catch(e => {
req.log('info', `External ID: ${externalID}, Error Saving Session: ${e}`);
return next(e);
});
}
};
43 changes: 23 additions & 20 deletions apps/nrm/behaviours/save-form-session.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable consistent-return */
'use strict';

const request = require('request');
const Model = require('hof').model;
const config = require('../../../config');

module.exports = superclass => class extends superclass {
saveValues(req, res, next) {
super.saveValues(req, res, err => {
super.saveValues(req, res, async err => {
if (err) {
next(err);
}
Expand Down Expand Up @@ -39,22 +39,23 @@ module.exports = superclass => class extends superclass {
const externalID = req.sessionModel.get('externalID');
req.log('info', `External ID: ${externalID}, Saving Form Session: ${req.sessionModel.get('id')}`);

request.post({
headers: {'content-type': 'application/json'},
url: config.saveService.host + ':' + config.saveService.port + '/reports',
body: JSON.stringify({
email: req.sessionModel.get('user-email'),
id: req.sessionModel.get('id'),
session: session
})
}, (error, response, body) => {
if (error) {
req.log('info', `External ID: ${externalID}, Error Saving Session: ${error}`);
next(error);
}
const resBody = JSON.parse(body);
try {
const model = new Model();
const params = {
method: 'POST',
url: config.saveService.host + ':' + config.saveService.port + '/reports',
data: {
email: req.sessionModel.get('user-email'),
id: req.sessionModel.get('id'),
session: session
}
};
const response = await model._request(params);

const resBody = response.data;

if (resBody && resBody.length && resBody[0].id) {
req.sessionModel.set('id', JSON.parse(body)[0].id);
req.sessionModel.set('id', resBody[0].id);
} else {
req.sessionModel.unset('id');
}
Expand All @@ -68,9 +69,11 @@ module.exports = superclass => class extends superclass {
if (req.sessionModel.get('redirect-to-reports') && noEditContinue) {
return res.redirect(`/nrm/continue-report?id=${req.sessionModel.get('id')}`);
}

next();
});
return next();
} catch (e) {
req.log('info', `External ID: ${externalID}, Error Saving Session: ${e}`);
return next(e);
}
});
}
};
3 changes: 2 additions & 1 deletion apps/nrm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ module.exports = {
saveFormSession
],
fields: ['were-they-taken-somewhere-by-their-exploiter',
'were-they-taken-somewhere-by-their-exploiter-journey-details'],
'were-they-taken-somewhere-by-their-exploiter-journey-details'
],
next: '/how-they-were-treated'
},
'/how-they-were-treated': {
Expand Down
4 changes: 2 additions & 2 deletions apps/nrm/views/partials/are-others-involved.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="are-others-involved-details-fieldset" class="panel-indent">
{{#renderField}}are-others-involved-details{{/renderField}}
<fieldset id="are-others-involved-details-fieldset" class="govuk-radios__conditional govuk-radios__conditional--hidden">
{{#textarea}}are-others-involved-details{{/textarea}}
</fieldset>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="does-pv-have-children-yes-fieldset" class="panel-indent">
{{#renderField}}does-pv-have-children-yes-amount{{/renderField}}
{{#input-text}}does-pv-have-children-yes-amount{{/input-text}}
</fieldset>
2 changes: 1 addition & 1 deletion apps/nrm/views/partials/evidence-of-dishonesty.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="evidence-of-dishonesty-details-fieldset" class="panel-indent">
{{#renderField}}evidence-of-dishonesty-details{{/renderField}}
{{#textarea}}evidence-of-dishonesty-details{{/textarea}}
</fieldset>
2 changes: 1 addition & 1 deletion apps/nrm/views/partials/other-exploitation-fieldset.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="other-exploitation-fieldset" class="panel-indent">
{{#renderField}}other-exploitation-details{{/renderField}}
{{#textarea}}other-exploitation-details{{/textarea}}
</fieldset>
2 changes: 1 addition & 1 deletion apps/nrm/views/partials/pv-ho-reference-type.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="pv-ho-reference-type-fieldset" class="panel-indent">
{{#renderField}}pv-ho-reference-type{{/renderField}}
{{#input-text}}pv-ho-reference-type{{/input-text}}
</fieldset>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="pv-interpreter-requirements-language-fieldset" class="panel-indent">
{{#renderField}}pv-interpreter-requirements-language{{/renderField}}
{{#input-text}}pv-interpreter-requirements-language{{/input-text}}
</fieldset>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="pv-other-help-with-communication-aid-fieldset" class="panel-indent">
{{#renderField}}pv-other-help-with-communication-aid{{/renderField}}
{{#input-text}}pv-other-help-with-communication-aid{{/input-text}}
</fieldset>
4 changes: 2 additions & 2 deletions apps/nrm/views/partials/reported-to-police-yes.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<fieldset id="yes-crime-reference-fieldset" class="panel-indent">
{{#renderField}}reported-to-police-police-forces{{/renderField}}
{{#renderField}}reported-to-police-crime-reference{{/renderField}}
{{#select}}reported-to-police-police-forces{{/select}}
{{#input-text}}reported-to-police-crime-reference{{/input-text}}
</fieldset>
2 changes: 1 addition & 1 deletion apps/nrm/views/partials/someone-else-email-input.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="someone-else-email-input-fieldset" class="panel-indent">
{{#renderField}}someone-else-email-input{{/renderField}}
{{#input-text}}someone-else-email-input{{/input-text}}
</fieldset>
8 changes: 4 additions & 4 deletions apps/nrm/views/partials/someone-else-post.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<fieldset id="someone-else-post-fieldset" class="panel-indent">
{{#renderField}}someone-else-street{{/renderField}}
{{#renderField}}someone-else-town{{/renderField}}
{{#renderField}}someone-else-county{{/renderField}}
{{#renderField}}someone-else-postcode{{/renderField}}
{{#input-text}}someone-else-street{{/input-text}}
{{#input-text}}someone-else-town{{/input-text}}
{{#input-text}}someone-else-county{{/input-text}}
{{#input-text}}someone-else-postcode{{/input-text}}
</fieldset>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset id="were-they-taken-somewhere-by-their-exploiter-details-fieldset" class="panel-indent">
{{#renderField}}were-they-taken-somewhere-by-their-exploiter-journey-details{{/renderField}}
<fieldset id="were-they-taken-somewhere-by-their-exploiter-details-fieldset" class="govuk-radios__conditional govuk-radios__conditional--hidden" aria-hidden="false">
{{#textarea}}were-they-taken-somewhere-by-their-exploiter-journey-details{{/textarea}}
</fieldset>
Loading

0 comments on commit 12f214b

Please sign in to comment.