Add audited Owner roster operation using shared membership acceptance

This commit is contained in:
unimatrixgit 2026-11-29 20:24:54 +01:00
commit d9877dfd9c
2 changed files with 146 additions and 11 deletions

View file

@ -0,0 +1,13 @@
# Explicit Owner roster additions
`add-owner-roster-members.mjs` plans or applies a named set of ordinary members to the verified Owner's single active owned clan and company. It runs only from its exact immutable CI release and resolves existing active Minecraft-linked accounts. It creates no accounts, sessions, applicant consent, staff ranks, ownership changes, recruitment advertisements or financial entries.
The operator reuses the original clan/company acceptance statement builders. Existing application-review routes use those same builders. The operator refuses pending applications, membership elsewhere, protected institutions, ambiguous organisations, insufficient capacity and stale links/deeds. It checks authority again under the held transaction, locks the accounts and deeds, and commits all requested additions plus the Owner audit together. A failed audit rolls back the roster changes. A stable operation UUID is bound to the exact accounts and organisations; a retry never resets their joining dates.
Run the built helper first without `--apply`:
```sh
node current/ops/add-owner-roster-members.mjs --source=REVIEWED_COMMIT --request-id=OPERATION_UUID --targets=REGISTERED_USERNAME,REGISTERED_USERNAME
```
After reviewing the plan, repeat the same invocation with `--apply`. The helper saves the private reviewed plan and result under `/root/dunerealms-owner-roster-backups/OPERATION_UUID`. Check the actual authoritative rosters and subsequent native projections; do not claim game synchronization from an application build alone. Removal uses the existing member-removal domain flow, preserving later independent roster changes.

View file

@ -0,0 +1,30 @@
import {readFile,writeFile,mkdir,realpath} from 'node:fs/promises';
import {fileURLToPath,pathToFileURL} from 'node:url';
import {resolve} from 'node:path';
import mysql from 'mysql2/promise';
import {ownerRosterPlan,applyOwnerRosterAdditions} from '../node/owner-roster-additions.mjs';
async function main(){
const args=process.argv.slice(2),value=name=>args.find(a=>a.startsWith('--'+name+'='))?.slice(name.length+3),source=value('source'),requestId=value('request-id'),targets=(value('targets')||'').split(',');
if(!/^[a-f0-9]{40}$/.test(source||'')||args.some(a=>a!=='--apply'&&!/^--(?:source|request-id|targets)=/.test(a)))throw Error('Reviewed source, stable request ID and explicit registered usernames required');
const release=await realpath(fileURLToPath(new URL('..',import.meta.url)));if(!release.endsWith('/releases/ci-'+source))throw Error('Run only the exact immutable reviewed release helper');
process.loadEnvFile('/home/dunerealms/.config/dunerealms.env');const e=process.env;
const c=await mysql.createConnection({host:e.DB_HOST||'127.0.0.1',port:Number(e.DB_PORT||3306),user:e.DB_USER,password:e.DB_PASSWORD,database:e.DB_NAME,multipleStatements:false});let inTransaction=false;
const db={companyDeedsEnabled:true,clanDeedsEnabled:true,organisationAccessEnabled:e.ORGANISATION_ACCESS_ENABLED==='true',
query:async(sql,v=[])=> (await c.execute(sql,v))[0],
prepare(sql){let values=[];return {bind(...v){values=v;return this;},async first(){return (await c.execute(sql,values))[0][0]||null;},async all(){return {results:(await c.execute(sql,values))[0]};},async run(connection=c){return {meta:{changes:(await connection.execute(sql,values))[0].affectedRows}};}};},
async readSnapshot(work){if(inTransaction)return work(db);await c.query('START TRANSACTION READ ONLY');try{const result=await work(db);await c.commit();return result;}catch(error){await c.rollback();throw error;}},
async batch(statements){if(inTransaction)throw Error('Nested membership transaction refused');await c.beginTransaction();inTransaction=true;try{const results=[];for(const s of statements)results.push(await s.run(c));await c.commit();return results;}catch(error){await c.rollback();throw error;}finally{inTransaction=false;}}
};
try{
const plan=await ownerRosterPlan(db,targets),summary={source,requestId,clan:plan.clan.name,company:plan.company.name,targets:plan.targets.map(t=>({username:t.username,addClan:t.addClan,addCompany:t.addCompany})),role:'member',financialTransactions:false};
if(!args.includes('--apply')){console.log(JSON.stringify({applied:false,...summary}));return;}
const backup=resolve('/root/dunerealms-owner-roster-backups',requestId||'invalid');if(!/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(requestId||''))throw Error('Stable operation UUID required');
await mkdir(backup,{recursive:true,mode:0o700});
try{await writeFile(resolve(backup,'plan.before.json'),JSON.stringify(plan),{mode:0o600,flag:'wx'});}catch(error){if(error.code!=='EEXIST')throw error;const prior=JSON.parse(await readFile(resolve(backup,'plan.before.json'),'utf8'));if(prior.actor.id!==plan.actor.id||prior.clan.id!==plan.clan.id||prior.company.id!==plan.company.id||JSON.stringify(prior.targets.map(t=>[t.id,t.minecraftUuid]))!==JSON.stringify(plan.targets.map(t=>[t.id,t.minecraftUuid])))throw Error('Private operation backup belongs to different input');}
const result=await applyOwnerRosterAdditions(db,plan,{requestId});
await writeFile(resolve(backup,'result.json'),JSON.stringify({source,...result}),{mode:0o600});
console.log(JSON.stringify({...summary,applied:result.applied,replayed:!!result.replayed,alreadyMembers:!!result.alreadyMembers,backup}));
}finally{await c.end();}
}
if(process.argv[1]&&import.meta.url===pathToFileURL(await realpath(resolve(process.argv[1]))).href)await main();