Merge pull request 'Retain the political payment transaction during authority snapshots' (#533) from fix/political-debit-snapshot-20261123 into main
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m41s
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m41s
This commit is contained in:
commit
6ded0c8b75
2 changed files with 7 additions and 2 deletions
|
|
@ -21,6 +21,7 @@ const fail=(message,status=409)=>{throw Object.assign(Error(message),{status});}
|
|||
const accountsSQL='SELECT a.*,c.entity_id,e.active entity_active,p.state package_state FROM pb_accounts a JOIN pb_clients c ON c.client_number=a.client_number JOIN pb_entities e ON e.id=c.entity_id JOIN pb_packages p ON p.id=a.package_id';
|
||||
const fingerprint=x=>createHash('sha256').update(JSON.stringify(x)).digest('hex');
|
||||
const funding=d=>entityId('office',d.office==='emperor'?'emperor':'leader:'+d.office);
|
||||
export function politicalDecisionReader(tx,base){const reader=boardReadStore(tx,base);if(tx!==base)reader.readSnapshot=async work=>work(reader);return reader;}
|
||||
export function decisionInput(input){
|
||||
const d=politicalDecision(input?.decisionId),fields=d?.kind==='proclamation'?'body,confirmed,decisionId,requestId,sourceAccount,title':'citation,confirmed,decisionId,recipientId,requestId,sourceAccount';
|
||||
if(!d||!input||Object.keys(input).sort().join(',')!==fields||!validUuid(input.requestId)||input.confirmed!==true||typeof input.sourceAccount!=='string'||!/^\d{1,12}$/.test(input.sourceAccount))fail('Review and confirm a registered decision and its funding account.',400);
|
||||
|
|
@ -44,7 +45,7 @@ export function createPoliticalDecisions(db,bank,keys,deps={}){
|
|||
// Keep every transaction callback on its original connection.
|
||||
db={...boardReadStore(db,db),transaction:db.transaction.bind(db)};
|
||||
const clock=deps.clock||Date.now,banking=atomicBankAccess(db,bank,{verifyStorage:deps.verifyStorage,centralTables:['jarvis_political_decisions','political_proclamations','political_office_terms','political_office_charters','organisation_keys','organisation_key_events','codex_instance_editions','account_audit','jarvis_pol_progression_seasons','jarvis_pol_progression_accounts','jarvis_pol_progression_history','jarvis_pol_progression_outbox']});
|
||||
async function accounts(tx,actor,d){const b=banking.view(tx),r=boardReadStore(tx,db),authority=deps.authority||createPostbankAuthority(r,{bank:b,clock});const rights=await authority(actor,{bank:b});return(await b.query(accountsSQL+' WHERE c.entity_id=? AND a.system_key IS NULL ORDER BY a.id',[funding(d)])).filter(a=>ordinaryPaymentAccount(a)&&canDebitAccount(rights,a.entity_id,a.id));}
|
||||
async function accounts(tx,actor,d){const b=banking.view(tx),r=politicalDecisionReader(tx,db),authority=deps.authority||createPostbankAuthority(r,{bank:b,clock});const rights=await authority(actor,{bank:b});return(await b.query(accountsSQL+' WHERE c.entity_id=? AND a.system_key IS NULL ORDER BY a.id',[funding(d)])).filter(a=>ordinaryPaymentAccount(a)&&canDebitAccount(rights,a.entity_id,a.id));}
|
||||
async function recipients(tx,actor,d,search=''){
|
||||
if(d.kind!=='honour')return[];
|
||||
return tx.query("SELECT a.id,a.username FROM site_accounts a WHERE a.id<>? AND a.password_hash NOT LIKE '!%' AND NOT EXISTS(SELECT 1 FROM site_memorials m WHERE m.user_id=a.id) AND LOWER(a.username) LIKE ?"+(d.house?' AND EXISTS(SELECT 1 FROM site_game_links l JOIN site_character_choices c ON c.minecraft_uuid=l.minecraft_uuid WHERE l.user_id=a.id AND c.faction=?)':'')+' ORDER BY a.username LIMIT 50',[actor.id,'%'+search.toLowerCase().replace(/[\\%_]/g,'')+'%',...(d.house?[d.house]:[])]);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'node:test';import assert from 'node:assert/strict';import {randomUUID} from 'node:crypto';
|
||||
import {companyFixture} from './company-deed-fixture.mjs';
|
||||
import {STAFF_OFFICE_ACCOUNT_ID} from '../node/organisation-keys.mjs';
|
||||
import {createPoliticalDecisions,createPoliticalDecisionAPI,politicalHonours,POLITICAL_DECISION_SCHEMA,decisionInput} from '../node/political-decisions.mjs';
|
||||
import {createPoliticalDecisions,createPoliticalDecisionAPI,politicalHonours,POLITICAL_DECISION_SCHEMA,decisionInput,politicalDecisionReader} from '../node/political-decisions.mjs';
|
||||
import {initializePOLProgression,polProgressionStore} from '../node/progression-pol.mjs';
|
||||
import {PUBLIC_OFFICES} from '../node/public-government.mjs';
|
||||
import {POLITICAL_DECISIONS} from '../control-panel/public/political-decision-policy.mjs';
|
||||
|
|
@ -66,3 +66,7 @@ test('separate MySQL hosts fail before any mutation or qualified-table access',a
|
|||
test('production central adapter needs only query, prepare and transaction, without a first convenience method',async()=>{const f=await fixture();try{
|
||||
const central={...f.db,first:undefined,transaction:f.db.transaction.bind(f.db)},service=createPoliticalDecisions(central,f.db,f.keys,{verifyStorage:async()=>null,authority:f.authority,clock:()=>1000});assert.equal((await service.read(f.people.Owner,'IMP-04')).canManage,true);assert.equal((await service.execute(f.people.Owner,f.input())).ok,true);
|
||||
}finally{f.db.close();}});
|
||||
test('debit authority snapshots retain the existing transaction connection rather than opening a second pool connection',async()=>{
|
||||
const tx={query:async()=>[{id:'locked'}],first:async()=>({id:'locked'})},base={readSnapshot:async()=>{throw Error('A second connection would observe stale authority');}};
|
||||
const reader=politicalDecisionReader(tx,base);assert.equal(await reader.readSnapshot(async r=>(await r.prepare('SELECT id FROM political_office_terms').first()).id),'locked');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff