openvibers/openvibe.news Commits

Staff powers from the contracts staff map (WS-D, ADR-022; Contracts 0.38.0): staff editors are staff.editorial.manage (admin, as before), not a role list; NEWS_EDITORS stays the product's own editor role. test/staff-map.test.js fails on raw role checks

OP OpenVibers committed 24 Sept 2026 · b592ef0d08 · 6 files, +38 −12


Changes

ddiff --git a/.env.example b/.env.example
iindex 63c0617..fa5ce5e 100644
---- a/.env.example
++++ b/.env.example
@@@ -29,7 +29,8 @@ OV_OAUTH_CLIENT_SECRET=
# Signs the editor-desk form tokens (CSRF). Unset: random per process.
#NEWS_FORM_SECRET=
--# Editors: Network subjects (usr_…), comma-separated. Network admins are editors too.
++# Editors: Network subjects (usr_…), comma-separated (a product role). Staff with staff.editorial.manage
++# (Network admins) are editors too.
NEWS_EDITORS=
# OpenVibe.Sources — news items (sources.item.read; optionally sources.source.read for outlet names)
ddiff --git a/package-lock.json b/package-lock.json
iindex 5e62057..0dfc362 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -15,7 +15,7 @@
"express": "^4.21.2",
"express-rate-limit": "^7.5.0",
"helmet": "^8.1.0",
-- "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.33.0",
++ "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.38.0",
"openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v0.4.0",
"openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.5.0",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v1.12.0"
@@@ -1015,9 +1015,9 @@
}
},
"node_modules/openvibe-contracts": {
-- "version": "0.33.0",
-- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.33.0",
-- "integrity": "sha512-7q8NUhcPxgb8lxrVdC3pFbiPdjzliJM1mMP/1G5a2PmOr2tJVAXwYa8+a8YgCJvYeMSeMHWijLkIEiZ9IhllOg==",
++ "version": "0.38.0",
++ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.38.0",
++ "integrity": "sha512-nHYCcKM9N4TJS+BlHOax9xwt4jU87qhXsLZ2gnuK4nOHpGlkLk2OI49PCQVvfHPe+V7bzBK7L4MKjFcTNv8ORA==",
"license": "AGPL-3.0-only",
"dependencies": {
"ajv": "^8.17.1",
ddiff --git a/package.json b/package.json
iindex 33cbf62..361d9c5 100644
---- a/package.json
++++ b/package.json
@@@ -22,7 +22,7 @@
"express": "^4.21.2",
"express-rate-limit": "^7.5.0",
"helmet": "^8.1.0",
-- "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.33.0",
++ "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.38.0",
"openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v0.4.0",
"openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.5.0",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v1.12.0"
ddiff --git a/server/auth/viewer.js b/server/auth/viewer.js
iindex b08301f..13a69cd 100644
---- a/server/auth/viewer.js
++++ b/server/auth/viewer.js
@@@ -6,7 +6,7 @@
* { kind: 'anonymous', subject: null, staff: false }
* { kind: 'user', subject: 'usr_…'|null, staff, user, token }
* A browser with the Network user JWT (ov_token cookie or Bearer). The subject comes from the
-- * token's subject_id claim. role 'admin' makes the viewer staff. X-OV-* headers are ignored.
++ * token's subject_id claim. staff = the contracts staff map's staff.editorial.manage (ADR-022). X-OV-* headers are ignored.
* { kind: 'service', service: 'svc:ai', claims, subject: 'usr_…'|null, origin: 'user'|'ai' }
* A first-party service with a Network client-credentials token for audience openvibe.news.
* X-OV-Subject names the editor it acts for; X-OV-Origin: ai marks OpenVibe.AI output
@@@ -22,8 +22,7 @@ const contracts = require('openvibe-contracts');
const { extractToken, claimsToUser, decodeJwtPayload } = require('./sso');
const { checkCapability } = require('./capabilities');
--const { ids, serviceAuth, http } = contracts;
--const STAFF_ROLES = new Set(['admin']);
++const { ids, serviceAuth, http, staff: staffMap } = contracts;
const PRINCIPAL_SUB = /^(svc|app|mod):/;
const AUDIENCE = 'openvibe.news';
@@@ -68,7 +67,7 @@ function createViewerResolver({ auth, config, people }) {
if (!claims || (typeof claims.sub === 'string' && PRINCIPAL_SUB.test(claims.sub))) return null;
const subject = ids.isSubjectId('user', claims.subject_id) ? claims.subject_id : null;
if (subject && people) { try { people.rememberClaims(subject, claims); } catch { /* display cache only */ } }
-- return { kind: 'user', subject, staff: STAFF_ROLES.has(claims.role), origin: 'user', user: claimsToUser(claims), token };
++ return { kind: 'user', subject, staff: staffMap.can(claims, 'staff.editorial.manage'), origin: 'user', user: claimsToUser(claims), token };
}
/** opts.services=false (pages) treats a service token as no identity: pages are for browsers. */
@@@ -116,4 +115,4 @@ function guard(cap) {
};
}
--module.exports = { createViewerResolver, guard, ANONYMOUS, ViewerError, STAFF_ROLES };
++module.exports = { createViewerResolver, guard, ANONYMOUS, ViewerError };
ddiff --git a/server/config.js b/server/config.js
iindex 6539f57..7674035 100644
---- a/server/config.js
++++ b/server/config.js
@@@ -45,7 +45,7 @@ function load(env = process.env) {
formSecret: env.NEWS_FORM_SECRET || '',
// Editors: Network subjects (usr_…) who may create, revise, publish and retract stories and
-- // manage clusters. Network admins are editors too (staff).
++ // manage clusters. A product role, not staff; staff with staff.editorial.manage are editors too.
editors: list(env.NEWS_EDITORS),
// OpenVibe.Sources: the news items News ingests (category=news). Reads need sources.item.read
ddiff --git a/test/staff-map.test.js b/test/staff-map.test.js
nnew file mode 100644
iindex 0000000..ff8dbdf
---- /dev/null
++++ b/test/staff-map.test.js
@@@ -0,0 +1,26 @@
++'use strict';
++// Staff powers come from the openvibe-contracts staff map (ADR-022): staff.editorial.manage makes a person an editor (NEWS_EDITORS names more).
++// No server file compares a person's role by hand.
++const assert = require('assert');
++const fs = require('fs');
++const path = require('path');
++const { staff } = require('openvibe-contracts');
++
++const CAPS = ["staff.editorial.manage"];
++for (const [claims, want] of [[{"role": "user"}, [false]], [{"role": "global_mod"}, [false]], [{"role": "admin"}, [true]], [{"role": "admin", "is_owner": true}, [true]]]) {
++ CAPS.forEach((cap, i) => assert.strictEqual(staff.can(claims, cap), want[i], `${JSON.stringify(claims)} ${cap}`));
++}
++
++const offenders = [];
++(function walk(dir) {
++ for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
++ const f = path.join(dir, e.name);
++ if (e.isDirectory()) { if (e.name !== 'node_modules') walk(f); continue; }
++ if (!/\.(js|ts)$/.test(e.name)) continue;
++ fs.readFileSync(f, 'utf8').split('\n').forEach((line, i) => {
++ if (/STAFF_ROLES|STAFF_SUBJECTS|claims\.role\s*[!=]==?|\.(has|includes)\(\s*(claims|u|user|p)\.role\b|\brole\s*[!=]==?\s*['"](admin|global_mod|moderator)['"]/.test(line)) offenders.push(`${path.relative(path.join(__dirname, '..'), f)}:${i + 1}`);
++ });
++ }
++})(path.join(__dirname, '..', "server"));
++assert.deepStrictEqual(offenders, [], 'raw role checks; ask staff.can(claims, \'staff.…\')');
++console.log('staff map: all checks passed');