Skip to content

Commit bc1101f

Browse files
authored
[OGUI-1761] Restrict Lock force ALL actions to admin users only (#3102)
* updates the front-end to display lock buttons for 'Force Release ALL'&'Force Take ALL' to admin users only * updates the API endpoint to restrict those actions via the middleware * add tests for aforementioned cases Reason: * restriction is needed to prevent shifters from force taking all locks and attempting to start a run with detectors that should not be used. * in this manner the shifter has to take the locks one by one, confirming which ones are to be used with SL
1 parent 145ec0b commit bc1101f

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

Control/lib/api.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,16 @@ module.exports.setup = (http, ws) => {
260260
requireDetectorOrGlobalRoleMiddleware,
261261
lockController.actionLockHandler.bind(lockController)
262262
);
263+
264+
http.put(`/locks/force/:action/${DetectorId.ALL}`,
265+
minimumRoleMiddleware(Role.ADMIN),
266+
addDetectorIdMiddleware(DetectorId.ALL),
267+
lockController.actionForceLockHandler.bind(lockController)
268+
);
263269
http.put('/locks/force/:action/:detectorId',
264270
minimumRoleMiddleware(Role.GLOBAL),
265-
lockController.actionForceLockHandler.bind(lockController));
271+
lockController.actionForceLockHandler.bind(lockController)
272+
);
266273

267274
// Status Service
268275
http.get('/status/consul', statusController.getConsulStatus.bind(statusController));

Control/public/lock/lockPage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ export const content = (model) => {
6060
Failure: (error) => errorPage(error),
6161
Success: (detectorsLocksState) => h('.flex-column', [
6262
h('.flex-row.g2.pv2', [
63-
isUserAllowedRole(ROLES.Global) && [
63+
isUserAllowedRole(ROLES.Admin) && [
6464
detectorLockActionButton(lock, DETECTOR_ALL, {}, DetectorLockAction.RELEASE, true, 'Force Release ALL'),
6565
detectorLockActionButton(lock, DETECTOR_ALL, {}, DetectorLockAction.TAKE, true, 'Force Take ALL'),
66+
],
67+
isUserAllowedRole(ROLES.Global) && [
6668
detectorLockActionButton(lock, DETECTOR_ALL, {}, DetectorLockAction.RELEASE, false, 'Release ALL*'),
6769
detectorLockActionButton(lock, DETECTOR_ALL, {}, DetectorLockAction.TAKE, false, 'Take ALL*'),
6870
],

Control/test/api/lock/api-put-locks.test.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ describe(`'API - PUT - /locks/:action/:detectorId' test suite`, () => {
138138
});
139139
});
140140

141-
it('should successfully FORCE take ALL available lock as Global user', async () => {
141+
it('should fail to FORCE take ALL available lock as Global user', async () => {
142142
await request(`${TEST_URL}/api/locks`)
143143
.put(`/force/${DetectorLockAction.TAKE}/ALL?token=${GLOBAL_TEST_TOKEN}`)
144-
.expect(200, {
145-
MID: { name: 'MID', state: 'TAKEN', owner: { username: 'global', fullName: 'Global User', personid: 1 } },
146-
DCS: { name: 'DCS', state: 'TAKEN', owner: { username: 'global', fullName: 'Global User', personid: 1 } },
147-
ODC: { name: 'ODC', state: 'TAKEN', owner: { username: 'global', fullName: 'Global User', personid: 1 } },
144+
.expect(403, {
145+
message: 'Not enough permissions for this operation',
146+
status: 403,
147+
title: 'Unauthorized Access',
148148
});
149149
});
150150

@@ -198,7 +198,7 @@ describe(`'API - PUT - /locks/:action/:detectorId' test suite`, () => {
198198
});
199199
});
200200

201-
it('should successfully force release ALL locks from all users', async () => {
201+
it('should fail to force release ALL locks from all users as global', async () => {
202202
// first we retake a lock to ensure we have a lock to release from different types of users
203203
await request(`${TEST_URL}/api/locks`)
204204
.put(`/${DetectorLockAction.TAKE}/DCS?token=${GLOBAL_TEST_TOKEN}`)
@@ -210,6 +210,16 @@ describe(`'API - PUT - /locks/:action/:detectorId' test suite`, () => {
210210

211211
await request(`${TEST_URL}/api/locks`)
212212
.put(`/force/${DetectorLockAction.RELEASE}/ALL?token=${GLOBAL_TEST_TOKEN}`)
213+
.expect(403, {
214+
message: 'Not enough permissions for this operation',
215+
status: 403,
216+
title: 'Unauthorized Access',
217+
});
218+
});
219+
220+
it('should successfully force release ALL locks from all users as admin', async () => {
221+
await request(`${TEST_URL}/api/locks`)
222+
.put(`/force/${DetectorLockAction.RELEASE}/ALL?token=${ADMIN_TEST_TOKEN}`)
213223
.expect(200, {
214224
MID: { name: 'MID', state: 'FREE' },
215225
DCS: { name: 'DCS', state: 'FREE' },

0 commit comments

Comments
 (0)