Retain organisation permission snapshots on the held Navigator reader
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m17s
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m17s
This commit is contained in:
parent
51121e7b1d
commit
4c51624723
2 changed files with 19 additions and 1 deletions
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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();}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff