-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OGUI-1581] Split action for taking/releasing all locks in API router (…
…#2672) * Adds a pre-route which should be match for lock action `ALL` detector * Ensures for `ALL` the user has a minimum of Role.GLOBAL
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @license | ||
* Copyright 2019-2024 CERN and copyright holders of ALICE O2. | ||
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
* All rights not expressly granted are reserved. | ||
* | ||
* This software is distributed under the terms of the GNU General Public | ||
* License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
/** | ||
* Enum for detector IDs. | ||
*/ | ||
const DetectorId = Object.freeze({ | ||
ALL: 'ALL', | ||
}); | ||
|
||
exports.DetectorId = DetectorId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license | ||
* Copyright 2019-2024 CERN and copyright holders of ALICE O2. | ||
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
* All rights not expressly granted are reserved. | ||
* | ||
* This software is distributed under the terms of the GNU General Public | ||
* License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
/** | ||
* Middleware function to add detectorID to the request object | ||
* @param {Request} req - HTTP Request object | ||
* @param {Next} next - HTTP Next object to use if checks pass | ||
* @param {Response} res - HTTP Response object | ||
* @return {void} | ||
*/ | ||
const addDetectorIdMiddleware = (detectorId) => { | ||
return async (req, res, next) => { | ||
req.params.detectorId = detectorId; | ||
next(); | ||
}; | ||
} | ||
|
||
exports.addDetectorIdMiddleware = addDetectorIdMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Control/test/lib/middleware/mocha-addDetectorId.middleware.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const assert = require('assert'); | ||
const sinon = require('sinon'); | ||
|
||
// Import the middleware | ||
const { addDetectorIdMiddleware } = require('../../../lib/middleware/addDetectorId.middleware'); | ||
|
||
describe('`addDetectorIdMiddleware` test suite', () => { | ||
it('should add the specified detectorId to req.params and call next()', () => { | ||
const detectorId = '1234'; | ||
const req = { params: {} }; // Mock req object | ||
const res = {}; // Mock res object | ||
const next = sinon.stub(); // Mock next function | ||
|
||
addDetectorIdMiddleware(detectorId)(req, res, next); | ||
|
||
// Validate the detectorId is added | ||
assert.strictEqual(req.params.detectorId, detectorId); | ||
// Ensure next() is called | ||
assert.ok(next.calledOnce); | ||
}); | ||
|
||
it('should overwrite existing detectorId in req.params', () => { | ||
const detectorId = '5678'; | ||
const req = { params: { detectorId: 'original' } }; | ||
const res = {}; | ||
const next = sinon.stub(); | ||
|
||
addDetectorIdMiddleware(detectorId)(req, res, next); | ||
|
||
// Validate the detectorId is overwritten | ||
assert.strictEqual(req.params.detectorId, detectorId); | ||
assert.ok(next.calledOnce); | ||
}); | ||
|
||
}); |