From d551e67042252dcb90dc610c6f0c336c4a50fea4 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sat, 12 Jul 2025 16:47:10 +0200 Subject: [PATCH] Add vesselOrganisations() function --- lib/www/server/lib/db/project/organisations.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/www/server/lib/db/project/organisations.js b/lib/www/server/lib/db/project/organisations.js index cf21962..f3e3041 100644 --- a/lib/www/server/lib/db/project/organisations.js +++ b/lib/www/server/lib/db/project/organisations.js @@ -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 };