Skip to content

Commit

Permalink
Merge branch 'main' into temporary_branch_that_should_not_be_merged
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli-TW committed Sep 2, 2024
2 parents 3a04afe + f9efc0f commit fa652d9
Show file tree
Hide file tree
Showing 28 changed files with 359 additions and 167 deletions.
2 changes: 1 addition & 1 deletion assets/javascript/govukFrontendInit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { initAll } from 'node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js';
import { initAll } from '/public/govuk-frontend.min.js';

initAll();
1 change: 0 additions & 1 deletion e2e/cypress/mockApis/drupalData/urgentBanners.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
"published_at": "2020-11-13T12:50:07+00:00",
"field_moj_episode": null,
"field_moj_season": null,
"field_not_in_series": true,
"field_release_date": null
},
"relationships": {
Expand Down
6 changes: 0 additions & 6 deletions helm_deploy/prisoner-content-hub-frontend/templates/_envs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ env:
name: {{ .Values.application.contentConfigMapName }}
key: internalUrl

- name: APPROVED_VISITORS_FEATURE_ENABLED
value: {{ .Values.application.config.approvedVisitorsFeatureEnabled | quote }}

- name: ADJUDICATIONS_FEATURE_ENABLED
value: {{ .Values.application.config.adjudicationsFeatureEnabled | quote }}

- name: ELASTICSEARCH_ENDPOINT
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ application:
analyticsSiteId: G-0RBPFCWD3X
googleTagManagerSiteId: GTM-M62TTBK
mockAuthEnabled: true
approvedVisitorsFeatureEnabled: true
adjudicationsFeatureEnabled: true

ingress:
annotations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ application:
analyticsSiteId: G-H1MT63QRLQ
googleTagManagerSiteId: GTM-M62TTBK
mockAuthEnabled: false
approvedVisitorsFeatureEnabled: true
adjudicationsFeatureEnabled: true

ingress:
annotations:
Expand Down
2 changes: 0 additions & 2 deletions helm_deploy/prisoner-content-hub-frontend/values-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ application:
analyticsSiteId: G-FVRKLRH5PJ
googleTagManagerSiteId: GTM-M62TTBK
mockAuthEnabled: false
approvedVisitorsFeatureEnabled: true
adjudicationsFeatureEnabled: true

ingress:
annotations:
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 92 additions & 21 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ const feedbackEndpoint = getRequiredEnv(
'/local-feedback/_doc',
);

// covers all features being enabled to stop repetition as requested, commented out to stop errors in linting while no sites are using everything
// const ALL_PROFILE_FEATURES = [
// 'adjudications',
// 'approvedVisitors',
// 'incentives',
// 'money',
// 'timetable',
// 'visits',
// ];

module.exports = {
isProduction,
logLevel: getEnv('LOG_LEVEL', 'info'),
Expand Down Expand Up @@ -95,27 +105,88 @@ module.exports = {
showStackTraces:
getEnv('ENABLE_STACK_TRACES_ON_ERROR_PAGES', 'false') === 'true',
useRedisCache: getEnv('ENABLE_REDIS_CACHE', 'true') === 'true',
approvedVisitorsFeatureEnabled:
getEnv('APPROVED_VISITORS_FEATURE_ENABLED', 'false') === 'true',
adjudicationsFeatureEnabled:
getEnv('ADJUDICATIONS_FEATURE_ENABLED', 'false') === 'true',
adjudicationsFeatureEnabledAt: [
'cookhamwood',
'erlestoke',
'felthama',
'felthamb',
'garth',
'lindholme',
'newhall',
'ranby',
'stokeheath',
'styal',
'swaleside',
'themount',
'wayland',
'werrington',
'wetherby',
],
},
sites: {
berwyn: {
enabled: false,
features: [],
},
bullingdon: {
enabled: true,
features: ['incentives', 'money', 'timetable', 'visits'],
},
chelmsford: {
enabled: true,
features: ['incentives', 'money', 'timetable', 'visits'],
},
cookhamwood: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
erlestoke: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
felthama: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
felthamb: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
garth: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
lindholme: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
newhall: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
ranby: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
stokeheath: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
styal: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
swaleside: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
themount: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
thestudio: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
wayland: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
werrington: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
wetherby: {
enabled: true,
features: ['adjudications', 'incentives', 'money', 'timetable', 'visits'],
},
woodhill: {
enabled: true,
features: ['incentives', 'money', 'timetable', 'visits'],
},
},
analytics: {
endpoint: getEnv(
Expand Down
24 changes: 24 additions & 0 deletions server/middleware/__tests__/configureEstablishment.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
const config = {
sites: {
berwyn: {
enabled: true,
features: [
'adjudications',
'approvedVisitors',
'incentives',
'money',
'timetable',
'visits',
],
},
},
analytics: {
endpoint: 'https://www.google-analytics.com/collect',
siteId: 'G-0RBPFCWD3X',
gtmSiteId: 'GTM-M62TTBK',
},
};

jest.mock('../../config', () => config);

const configureEstablishment = require('../configureEstablishment');

describe('configureEstablishment', () => {
Expand All @@ -22,6 +45,7 @@ describe('configureEstablishment', () => {
configureEstablishment(req, res, next);

expect(res.locals.establishmentName).toBe('berwyn');
expect(res.locals.establishmentEnabled).toBe(true);
expect(res.locals.establishmentDisplayName).toBe('HMP Berwyn');
expect(next).toHaveBeenCalled();
});
Expand Down
2 changes: 2 additions & 0 deletions server/middleware/configureEstablishment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { v4: uuid } = require('uuid');
const { getEstablishmentId, getEstablishmentDisplayName } = require('../utils');
const config = require('../config');

const configureEstablishment = (req, res, next) => {
const establishmentName = req.session?.establishmentName;
Expand All @@ -13,6 +14,7 @@ const configureEstablishment = (req, res, next) => {

res.locals.feedbackId = uuid();
res.locals.establishmentName = establishmentName;
res.locals.establishmentEnabled = config.sites[establishmentName]?.enabled;
res.locals.establishmentDisplayName = `${getEstablishmentDisplayName(
req.session.establishmentId,
)}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Category collection query', () => {
describe('path', () => {
it('should create correct path', () => {
expect(query.path()).toStrictEqual(
`/jsonapi/prison/${ESTABLISHMENTNAME}/node?filter%5Bfield_moj_top_level_categories.id%5D=${UUID}&filter%5Bfield_not_in_series%5D=1&include=field_moj_thumbnail_image&sort=-created&fields%5Bnode--page%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&fields%5Bnode--moj_video_item%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&fields%5Bnode--moj_radio_item%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&fields%5Bmoj_pdf_item%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&${getPagination(
`/jsonapi/prison/${ESTABLISHMENTNAME}/node?filter%5Bfield_moj_top_level_categories.id%5D=${UUID}&include=field_moj_thumbnail_image&sort=-created&fields%5Bnode--page%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&fields%5Bnode--moj_video_item%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&fields%5Bnode--moj_radio_item%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&fields%5Bmoj_pdf_item%5D=drupal_internal__nid%2Ctitle%2Cfield_summary%2Cfield_moj_thumbnail_image%2Cpath%2Cpublished_at&${getPagination(
PAGE,
LIMIT,
)}`,
Expand Down
1 change: 0 additions & 1 deletion server/repositories/cmsQueries/categoryContentQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class CategoryContentQuery {
this.page = page;
const queryWithoutOffset = new Query()
.addFilter('field_moj_top_level_categories.id', uuid)
.addFilter('field_not_in_series', 1)
.addFields('node--page', CategoryContentQuery.#TILE_FIELDS)
.addFields('node--moj_video_item', CategoryContentQuery.#TILE_FIELDS)
.addFields('node--moj_radio_item', CategoryContentQuery.#TILE_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions server/routes/__tests__/homepage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ describe('GET /', () => {
establishmentPersonalisationToggle(),
};
req.user = userSupplier();
res.locals.establishmentEnabled = true;
next();
});
app.use(setCurrentUser);
Expand Down
33 changes: 32 additions & 1 deletion server/routes/__tests__/profile.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
const request = require('supertest');
const cheerio = require('cheerio');

const config = {
sites: {
berwyn: {
enabled: true,
features: [
'adjudications',
'approvedVisitors',
'incentives',
'money',
'timetable',
'visits',
],
},
},
analytics: {
endpoint: 'https://www.google-analytics.com/collect',
siteId: 'G-0RBPFCWD3X',
gtmSiteId: 'GTM-M62TTBK',
},
};

jest.mock('../../config', () => config);

const {
testApp: { setupApp, userSupplier, sessionSupplier },
testData: { user },
Expand All @@ -19,12 +42,20 @@ describe('GET /profile', () => {
let app;

beforeEach(() => {
const establishmentData = {
1: {
name: 'berwyn',
},
};
const cmsService = {
getPrimaryNavigation: jest.fn().mockResolvedValue([]),
getUrgentBanners: jest.fn().mockResolvedValue([]),
getTopics: jest.fn().mockReturnValue([]),
};
app = setupApp({ offenderService, cmsService });
app = setupApp(
{ offenderService, cmsService },
{ config, establishmentData },
);
userSupplier.mockReturnValue(user);
});

Expand Down
10 changes: 4 additions & 6 deletions server/routes/adjudications.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const config = require('../config');
const { createBreadcrumbs } = require('../utils/breadcrumbs');
const { createPagination } = require('../utils/pagination');
const { checkFeatureEnabledAtSite } = require('../utils');
const { logger } = require('../utils/logger');

const createAdjudicationsRouter = ({ offenderService }) => {
Expand All @@ -27,10 +28,7 @@ const createAdjudicationsRouter = ({ offenderService }) => {
const { user, originalUrl: returnUrl, query } = req;

if (
config.features.adjudicationsFeatureEnabled &&
config.features.adjudicationsFeatureEnabledAt.includes(
req.session.establishmentName,
)
checkFeatureEnabledAtSite(req.session.establishmentName, 'adjudications')
) {
let personalisation;
let error = null;
Expand Down Expand Up @@ -66,9 +64,9 @@ const createAdjudicationsRouter = ({ offenderService }) => {
const { adjudicationId } = req.params;

if (
config.features.adjudicationsFeatureEnabled &&
config.features.adjudicationsFeatureEnabledAt.includes(
checkFeatureEnabledAtSite(
req.session.establishmentName,
'adjudications',
) &&
adjudicationId
) {
Expand Down
9 changes: 7 additions & 2 deletions server/routes/approvedVisitors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const config = require('../config');
const { createBreadcrumbs } = require('../utils/breadcrumbs');
const { checkFeatureEnabledAtSite } = require('../utils');

const createApprovedVisitorsRouter = ({ offenderService }) => {
const router = express.Router();
Expand Down Expand Up @@ -32,7 +32,12 @@ const createApprovedVisitorsRouter = ({ offenderService }) => {
router.get('/', async (req, res, next) => {
const { user, originalUrl: returnUrl, query } = req;

if (config.features.approvedVisitorsFeatureEnabled) {
if (
checkFeatureEnabledAtSite(
req.session.establishmentName,
'approvedVisitors',
)
) {
try {
const personalisation = user
? await getPersonalisation(user, query)
Expand Down
2 changes: 1 addition & 1 deletion server/routes/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const createHomepageRouter = ({ cmsService, offenderService }) => {
isLastPage &&
(updatesContentWithDuplicatesRemoved.length < 5 || !useLargeUpdateTile);

res.render('pages/home-new', {
res.render('pages/home', {
config: {
content: true,
header: true,
Expand Down
Loading

0 comments on commit fa652d9

Please sign in to comment.