Add vesselOrganisations() function

This commit is contained in:
D. Berge
2025-07-12 16:47:10 +02:00
parent 6b216f7406
commit d551e67042

View File

@@ -1,6 +1,7 @@
const { setSurvey, pool } = require('../connection');
const { ALERT, ERROR, WARNING, NOTICE, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
const { vessel } = require('../vesel');
const { access } = require('../../organisations');
const { ALERT, ERROR, WARNING, NOTICE, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
// Cache the per-project organisations access here
let projectsCache;
@@ -41,7 +42,14 @@ async function projectOrganisations (pid) {
return projectsCache[pid] ?? {}; // Every project should have an `organisations` property, but…
}
/** Check whether a user has access to the project given by `pid`
/*
* Returns organisations associated with a vessel.
* If no `vesselID` is provided, returns own vessel.
*/
async function vesselOrganisations (vesselID) {
return (await vessel.info(vesselID))?.organisations ?? {};
}
*/
async function orgAccess (userOrgs, pid, operation) {
const projectOrgs = await projectOrganisations(pid);
@@ -64,6 +72,7 @@ function orgFilter (userOrgs, list, operation, fn = (item) => item.organisations
module.exports = {
setCache,
projectOrganisations,
vesselOrganisations,
orgAccess,
orgFilter
};