mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:07:08 +00:00
Check permissions against vessel if not on a project endpoint
This commit is contained in:
@@ -3,21 +3,16 @@ const { projectOrganisations, orgAccess } = require('../../../lib/db/project/org
|
||||
/** Second-order function.
|
||||
* Returns a middleware that checks if the user has access to
|
||||
* `operation` in the project identified by `req.params.project`
|
||||
* or, if `req.params.project` is not defined, against the vessel
|
||||
* access permissions.
|
||||
*/
|
||||
function operation (operation) {
|
||||
return async function (req, res, next) {
|
||||
if (req.user) {
|
||||
if (req.params.project) {
|
||||
if (await orgAccess(req.user.organisations, req.params.project, operation)) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if (await orgAccess(req.user?.organisations, req.params.project ?? null, operation)) {
|
||||
next();
|
||||
} else {
|
||||
next({status: 403, message: "Access denied"});
|
||||
}
|
||||
next({status: 403, message: "Access denied"});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user