From 4c51624723f057374305ba1de1fe41e1cdac77fb Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:15:14 +0100 Subject: [PATCH] Retain organisation permission snapshots on the held Navigator reader --- website/node/owned-smuggler-routes.mjs | 5 ++++- website/tests/owned-smuggler-routes.test.mjs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/website/node/owned-smuggler-routes.mjs b/website/node/owned-smuggler-routes.mjs index 1623b5ce..ee826c62 100644 --- a/website/node/owned-smuggler-routes.mjs +++ b/website/node/owned-smuggler-routes.mjs @@ -40,7 +40,10 @@ export function createOwnedSmugglerRoutes(db,{resolve,clock=Date.now}){ // Central changes nothing. Its deed/read locks remain held through the one // atomic bank reservation/posting transaction, avoiding distributed writes. return db.transaction(async tx=>{ - const reader=boardReadStore(tx,db);reader.readSnapshot=undefined; + const reader=boardReadStore(tx,db); + // Permission resolvers use readSnapshot; stay on this already held reader + // instead of inheriting the pool method and opening another connection. + reader.readSnapshot=async read=>read(reader); await tx.query('SELECT id FROM site_accounts WHERE id=? FOR SHARE',[user.id]);await tx.query('SELECT minecraft_uuid FROM site_game_links WHERE user_id=? FOR SHARE',[user.id]); await tx.query('SELECT version FROM site_character_choices WHERE user_id=? FOR SHARE',[user.id]); const selections=await tx.query('SELECT key_id FROM jarvis_house_selections WHERE account_id=? FOR SHARE',[user.id]); diff --git a/website/tests/owned-smuggler-routes.test.mjs b/website/tests/owned-smuggler-routes.test.mjs index c18feb48..60bed180 100644 --- a/website/tests/owned-smuggler-routes.test.mjs +++ b/website/tests/owned-smuggler-routes.test.mjs @@ -4,6 +4,8 @@ import {randomUUID} from 'node:crypto'; import {companyFixture} from './company-deed-fixture.mjs'; import {initializeClans} from '../control-panel/clans.mjs'; import {createOwnedSmugglerRoutes} from '../node/owned-smuggler-routes.mjs'; +import {organisationRuntimeAccess} from '../node/organisation-runtime.mjs'; +import {DEFAULT_RANKS,NODES} from '../node/permissions.mjs'; async function fixture(){ const f=await companyFixture(),owner=f.people.Owner,uuid=randomUUID(),origin=await f.create();let now=1200000; await f.db.query('UPDATE site_game_links SET minecraft_uuid=? WHERE user_id=?',[uuid,owner.id]); @@ -42,3 +44,16 @@ test('all identity, key, deed and claim locking reads precede the first consiste let entered=false;await routes.withLock(f.user,f.input,'board',async()=>{entered=true;});assert.equal(entered,true); }finally{f.db.close();} }); + +test('activated organisation permissions resolve on the held route snapshot without another pooled reader',async()=>{ + const f=await fixture();try{ + f.db.organisationAccessEnabled=true;f.db.readSnapshot=async()=>assert.fail('Must not open a second pooled snapshot'); + f.db.sqlite.exec('CREATE TABLE org_control_principals(user_id TEXT,principal_kind TEXT);CREATE TABLE org_assignments(id TEXT,user_id TEXT,scope_type TEXT,scope_key TEXT,role_key TEXT,status TEXT,starts_at INT,ends_at INT);CREATE TABLE org_role_policies(scope_type TEXT,scope_key TEXT,role_key TEXT,permissions_json TEXT,version INT);'); + await f.routes.withLock(f.user,f.input,'board',async(ctx,user,reader)=>{ + assert.equal(reader.organisationAccessEnabled,true); + assert.equal(await reader.readSnapshot(snapshot=>snapshot),reader); + const access=await organisationRuntimeAccess(reader,user,{registry:NODES,basicRank:DEFAULT_RANKS[0],legacyRanks:[],clock:()=>1200000}); + assert.ok(access.nodes.includes('web.bank.personal.view'));assert.ok(!access.nodes.includes('web.bank.staff.manage')); + }); + }finally{f.db.close();} +});