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

LNP-868: Add profile feature switching per site #710

Merged
merged 28 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ff4d771
Allow profile features to be switched on/off per site
psoleckimoj Jul 23, 2024
49f52d7
Allow profile features to be switched on/off per site
psoleckimoj Jul 23, 2024
e17462b
Return 404 page when profile disabled
psoleckimoj Jul 23, 2024
f399d18
Replicate behaviour of approved visitors
psoleckimoj Jul 24, 2024
3d9e649
Extra check to check the site is enabled as well as the feature
psoleckimoj Jul 24, 2024
5a1e0aa
Extra check to check the site is enabled as well as the feature
psoleckimoj Jul 24, 2024
1185628
Remove adjudications enabled flag, enabled everywhere
psoleckimoj Jul 24, 2024
f2ea6bb
Remove approvedVisitors feature as fully enabled
psoleckimoj Jul 24, 2024
9a13bdc
Make adjudications enabled match what is currently in prod
psoleckimoj Jul 24, 2024
bdca4fa
Merge branch 'main' into feature/add-profile-feature-switching-per-site
psoleckimoj Jul 24, 2024
f78bfef
Remove Chelmsford from approved visitors
psoleckimoj Jul 24, 2024
09750a0
Get rid of hardwired Berwyn stuff
psoleckimoj Jul 24, 2024
583564b
Fix test
psoleckimoj Jul 24, 2024
e4b3e28
Fix test mocking
psoleckimoj Jul 24, 2024
e81b3d8
Fix tests
psoleckimoj Jul 25, 2024
50f1f71
Tidy feature/site checking
psoleckimoj Jul 25, 2024
c65d087
Move function to utils
psoleckimoj Jul 25, 2024
b227ada
Remove changes from irrelevant file
psoleckimoj Jul 25, 2024
5e34eea
Use common fn
psoleckimoj Jul 25, 2024
64e2b19
Make function easier to test
psoleckimoj Jul 25, 2024
67f1656
Add start of tests for checkFeatureEnabledAtSite
psoleckimoj Jul 25, 2024
145ed35
Add more tests
psoleckimoj Jul 25, 2024
1b97670
Use constant to make config simpler/cleaner
psoleckimoj Jul 25, 2024
95f86b6
Merge branch 'main' into feature/add-profile-feature-switching-per-site
psoleckimoj Jul 25, 2024
6c9405e
Rename new home template to home
psoleckimoj Jul 26, 2024
3f70b7f
Enable approved visitors only at The Mount
psoleckimoj Jul 31, 2024
6bbf09f
The Mount no approved visitors
psoleckimoj Aug 1, 2024
aafb4af
Comment to document commented out const
psoleckimoj Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: false
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: false
adjudicationsFeatureEnabled: true

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

const ALL_PROFILE_FEATURES = [
'adjudications',
'approvedVisitors',
'incentives',
'money',
'timetable',
'visits',
];

module.exports = {
isProduction,
logLevel: getEnv('LOG_LEVEL', 'info'),
Expand Down Expand Up @@ -95,27 +104,100 @@ 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: [
'approvedVisitors',
'incentives',
'money',
'timetable',
'visits',
],
},
chelmsford: {
enabled: true,
features: ['incentives', 'money', 'timetable', 'visits'],
Eli-TW marked this conversation as resolved.
Show resolved Hide resolved
},
cookhamwood: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
erlestoke: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
felthama: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
felthamb: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
garth: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
lindholme: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
newhall: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
ranby: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
stokeheath: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
styal: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
swaleside: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
themount: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
thestudio: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
wayland: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
werrington: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
wetherby: {
enabled: true,
features: ALL_PROFILE_FEATURES,
},
woodhill: {
enabled: true,
features: [
'approvedVisitors',
'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
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
36 changes: 29 additions & 7 deletions server/routes/profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const config = require('../config');
const { createBreadcrumbs } = require('../utils/breadcrumbs');
const { checkFeatureEnabledAtSite } = require('../utils');

const createProfileRouter = ({ offenderService }) => {
const router = express.Router();
Expand Down Expand Up @@ -84,6 +85,10 @@ const createProfileRouter = ({ offenderService }) => {
};

router.get('/', async (req, res, next) => {
if (!config.sites[req.session.establishmentName]?.enabled) {
return next();
}

try {
const { user } = req;
const personalisation = user ? await getPersonalisation(user) : {};
Expand All @@ -96,14 +101,31 @@ const createProfileRouter = ({ offenderService }) => {
detailsType: 'small',
data: { contentType: 'profile', breadcrumbs: createBreadcrumbs(req) },
...personalisation,
displayApprovedVisitorsCard:
config.features.approvedVisitorsFeatureEnabled,
displayAdjudicationsFeature:
config.features.adjudicationsFeatureEnabled &&
config.features.adjudicationsFeatureEnabledAt.includes(
displayVisits: checkFeatureEnabledAtSite(
req.session.establishmentName,
'visits',
),
displayTimetable: checkFeatureEnabledAtSite(
req.session.establishmentName,
'timetable',
),
displayIncentives: checkFeatureEnabledAtSite(
req.session.establishmentName,
'incentives',
),
displayMoney: checkFeatureEnabledAtSite(
req.session.establishmentName,
'money',
),
displayApprovedVisitors: checkFeatureEnabledAtSite(
req.session.establishmentName,
'approvedVisitors',
),
displayAdjudications:
checkFeatureEnabledAtSite(
req.session.establishmentName,
) &&
personalisation.hasAdjudications,
'adjudications',
) && personalisation.hasAdjudications,
});
} catch (e) {
return next(e);
Expand Down
Loading
Loading