games_app/backend/dist-test-faq/scripts/setForbidSelfApprove.js

72 lines
3.3 KiB
JavaScript

"use strict";
/**
* Break-glass: set forbid_self_approve on all (or matched) approval_policies.
* No on-chain activity. Use when a solo Super Admin cannot approve their own policy change.
*
* VPS:
* sudo docker compose run --rm --no-deps --build backend \
* node dist/scripts/setForbidSelfApprove.js --allow=true --confirm=YES
*
* Optional: --operation-type=treasury_hot_to_cold (only that op; default = all policies)
*/
Object.defineProperty(exports, "__esModule", { value: true });
require("./loadEnv");
const connection_1 = require("../db/connection");
function arg(name) {
const prefix = `--${name}=`;
const hit = process.argv.find((a) => a.startsWith(prefix));
return hit ? hit.slice(prefix.length) : undefined;
}
function hasFlag(name) {
return process.argv.includes(`--${name}`);
}
async function main() {
const allowRaw = (arg('allow') ?? '').toLowerCase();
const allow = allowRaw === 'true' || allowRaw === '1' || allowRaw === 'yes';
const deny = allowRaw === 'false' || allowRaw === '0' || allowRaw === 'no';
if (!allow && !deny) {
console.error('Usage: --allow=true|false --confirm=YES [--operation-type=...]');
process.exit(1);
}
const forbidSelf = deny; // allow=true → forbid_self_approve=false
if (arg('confirm') !== 'YES' && !hasFlag('confirm=YES')) {
console.error('Refusing to run without --confirm=YES');
process.exit(1);
}
const opType = arg('operation-type') || null;
const existing = await (0, connection_1.query)(opType
? `SELECT id, name, operation_type, decision FROM approval_policies WHERE operation_type = $1 OR ($1 IS NULL AND operation_type IS NULL)`
: `SELECT id, name, operation_type, decision FROM approval_policies`, opType ? [opType] : []);
if (!existing.length) {
console.error('No approval_policies rows found. Run migrations / smokeApprovalPolicies first.');
process.exit(1);
}
console.log(`Updating ${existing.length} polic(y/ies): forbid_self_approve → ${forbidSelf}`);
for (const row of existing) {
const decision = row.decision && typeof row.decision === 'object'
? { ...row.decision }
: {};
decision.forbid_self_approve = forbidSelf;
if (!Array.isArray(decision.quorum)) {
decision.quorum = [{ role: 'super_admin', count: 1 }];
}
if (!decision.mode)
decision.mode = 'require_approvals';
await (0, connection_1.query)(`UPDATE approval_policies
SET decision = $2::jsonb, version = version + 1, updated_at = NOW()
WHERE id = $1`, [row.id, JSON.stringify(decision)]);
console.log(` OK ${row.name} (${row.operation_type ?? 'any'}) forbid_self_approve=${forbidSelf}`);
}
await (0, connection_1.query)(`INSERT INTO approval_policy_revisions (actor_id, before_snapshot, after_snapshot, note)
VALUES (NULL, '[]'::jsonb, $1::jsonb, $2)`, [
JSON.stringify({ action: 'setForbidSelfApprove', forbid_self_approve: forbidSelf, count: existing.length }),
`CLI setForbidSelfApprove forbid_self_approve=${forbidSelf}`,
]);
console.log('\nDone. Reload /admin/approval-policies (hard refresh). No on-chain txs.');
process.exit(0);
}
main().catch((e) => {
console.error(e instanceof Error ? e.message : e);
process.exit(1);
});
//# sourceMappingURL=setForbidSelfApprove.js.map