hub-evaluator-may-approve.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Per-user "evaluator may approve" map (self-hosted Hub data dir). |
| 3 | * Hosted uses bridge blob `hub_evaluator_may_approve`; same JSON shape: { evaluator_may_approve: { "sub": true, ... } }. |
| 4 | */ |
| 5 | |
| 6 | import fs from 'fs'; |
| 7 | import path from 'path'; |
| 8 | |
| 9 | const FILE = 'hub_evaluator_may_approve.json'; |
| 10 | |
| 11 | /** |
| 12 | * @param {string} dataDir |
| 13 | * @returns {Record<string, boolean>} |
| 14 | */ |
| 15 | export function readEvaluatorMayApprove(dataDir) { |
| 16 | if (!dataDir) return {}; |
| 17 | const filePath = path.join(dataDir, FILE); |
| 18 | try { |
| 19 | if (!fs.existsSync(filePath)) return {}; |
| 20 | const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); |
| 21 | const m = data?.evaluator_may_approve != null ? data.evaluator_may_approve : data; |
| 22 | if (typeof m !== 'object' || m === null) return {}; |
| 23 | const out = {}; |
| 24 | for (const [k, v] of Object.entries(m)) { |
| 25 | if (typeof k === 'string' && k.trim()) out[k.trim()] = Boolean(v); |
| 26 | } |
| 27 | return out; |
| 28 | } catch { |
| 29 | return {}; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param {string} dataDir |
| 35 | * @param {Record<string, boolean>} map |
| 36 | */ |
| 37 | export function writeEvaluatorMayApprove(dataDir, map) { |
| 38 | if (!dataDir) throw new Error('data_dir required'); |
| 39 | const filePath = path.join(dataDir, FILE); |
| 40 | const obj = {}; |
| 41 | for (const [k, v] of Object.entries(map)) { |
| 42 | if (typeof k === 'string' && k.trim()) obj[k.trim()] = Boolean(v); |
| 43 | } |
| 44 | fs.mkdirSync(dataDir, { recursive: true }); |
| 45 | fs.writeFileSync(filePath, JSON.stringify({ evaluator_may_approve: obj }, null, 2), 'utf8'); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Whether the actor may approve proposals (admin always; evaluator from map + env fallback). |
| 50 | * @param {string} sub |
| 51 | * @param {string} role - effective role (admin, editor, viewer, evaluator, member) |
| 52 | * @param {Record<string, boolean>} mayMap |
| 53 | * @param {boolean} envFallback - HUB_EVALUATOR_MAY_APPROVE === '1' |
| 54 | */ |
| 55 | export function actorMayApproveProposals(sub, role, mayMap, envFallback) { |
| 56 | if (role === 'admin') return true; |
| 57 | if (role !== 'evaluator') return false; |
| 58 | if (Object.prototype.hasOwnProperty.call(mayMap, sub)) return Boolean(mayMap[sub]); |
| 59 | return envFallback; |
| 60 | } |
File History
4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
30 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91
fix: repair endpoint now sets has_active_subscription when …
Human
minor
⚠
49 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
82 days ago