diff --git a/.changeset/38924-own-field-rows-beside-modify-all.md b/.changeset/38924-own-field-rows-beside-modify-all.md new file mode 100644 index 00000000000..3911eaabeca --- /dev/null +++ b/.changeset/38924-own-field-rows-beside-modify-all.md @@ -0,0 +1,28 @@ +--- +'@objectstack/spec': patch +'@objectstack/cli': patch +'@objectstack/metadata-protocol': patch +--- + +fix(cli): `os migrate meta --from 18` names each own field row beside Modify All that protocol 19 narrows + +Clause-②: yes (widening) +Metadata-protocol: none + +Widened: `@objectstack/spec` exports `ownFieldRowsBesideModifyAll` and the types `OwnFieldRowBesideModifyAll`, `OwnFieldRowProtocol18Outcome` and `OwnFieldRowProtocol19Outcome`; `os migrate meta --from N --json` gains the key `ownFieldRowNarrowing`, present only when the list is not empty; `StoredViewAllFieldsReview` (`os migrate meta --stored --json`) gains the optional member `ownFieldRows`, and `@objectstack/metadata-protocol` exports its element type `StoredOwnFieldRow`. Nothing a metadata author writes changes. + +The upgrade text no longer says that the `viewAllFields: true` written beside View All or Modify All keeps every field read. It keeps the field reads the bits cast, except a field the set's own `readable: false` row hides beside Modify All, and it keeps no edit Modify All cast. The protocol-19 behaviour itself is unchanged. + +`os migrate meta --from 18` now lists each own field row beside a Modify All bit that the run writes `viewAllFields: true` beside, where the row's answer changes on protocol 19. Each line names the permission set, the `objects` entry and the field row; what the set's holders got on protocol 18 (read and edit: Modify All voted over the set's own rows); what they get on 19 through that set (`hidden`, `read-only`, `read-only-where-when-matches` for a row-conditioned lock, or `edit-only-where-when-matches` for a row-conditioned edit); and the choice: change the row to keep the protocol-18 answer, or accept the narrowing. Following the choice takes the row off the list. A set that already carries `viewAllFields` beside the bit (a source the edit was applied to) is not listed; review its own rows beside Modify All by hand. Example, for a set with View All and Modify All on `contact` and its own `'contact.salary': { readable: false }` row: + +```text + 1 own field row(s) beside Modify All that protocol 19 narrows — the `viewAllFields: true` written beside the bit does not keep them: + ⚠ permission set 'hr_manager' (permissions[0]), objects entry 'contact', field row 'contact.salary' + protocol 18: read and edit (Modify All voted over the set's own row) + protocol 19: hidden, no read and no edit (the set's own `readable: false` row binds) + choice: to keep the protocol-18 read and edit, change the row to `readable: true, editable: true`; otherwise accept the narrowing. +``` + +`--json` carries the same list under `ownFieldRowNarrowing` (`set`, `at`, `object`, `field`, `protocol18`, `protocol19`, `choice`); no other key changes. + +`os migrate meta --stored` names the same rows of a stored permission set under its entry in the View All Fields review list, and its `--json` entries carry them as `ownFieldRows`. View All alone is never listed: on 18.6.0 a set's own row already bound beside its own View All. Protocol 18 here means 18.6.0, the release the card measured. diff --git a/packages/cli/src/commands/migrate/meta.ts b/packages/cli/src/commands/migrate/meta.ts index 5494bbbeff1..8d2ebee6b4b 100644 --- a/packages/cli/src/commands/migrate/meta.ts +++ b/packages/cli/src/commands/migrate/meta.ts @@ -38,6 +38,7 @@ import { import { bootSchemaStack } from '../../utils/schema-migrate.js'; import { buildDataMigrationPlugins } from '../../utils/data-migration-plugins.js'; import { absentTableReads } from '../../utils/absent-table-reads.js'; +import { ownFieldRowNarrowingSites, printOwnFieldRowNarrowing, type OwnFieldRowNarrowingSite } from '../../utils/own-field-row-narrowing.js'; import type { StoredMigrationReport } from '@objectstack/metadata-protocol'; import { OCCUPANCY_HINT, probeMigrationTarget } from '../../utils/migrate-occupancy-gate.js'; import { describeOccupancy, JOURNAL_MODE_SWITCH_NOTE } from '../../utils/sqlite-occupancy.js'; @@ -1056,6 +1057,8 @@ export interface MigrationReport { elapsed: string; /** The per-site edits the protocol-19 form move left ({@link formMoveSites}); absent or empty when none. */ formMoveSites?: readonly FormMoveSite[]; + /** The own field rows beside Modify All protocol 19 narrows ({@link ownFieldRowNarrowingSites}); absent or empty when none. */ + ownFieldRowNarrowing?: readonly OwnFieldRowNarrowingSite[]; /** The committed access matrix's drift `os build` will report, and whose sources it is about; absent when none. */ accessMatrix?: { drift: AccessMatrixDrift; subject: AccessMatrixDriftSubject }; } @@ -1301,6 +1304,8 @@ export function printMigrationReport(report: MigrationReport): void { if (result.applied.length > 0) printAppliedEdits(result, report.write !== undefined); // ②b The sites the protocol-19 form move left in place or owes an edit. printFormMoveSites(report.formMoveSites ?? []); + // ②c The own field rows beside Modify All the `viewAllFields: true` above does not keep. + printOwnFieldRowNarrowing(report.ownFieldRowNarrowing ?? []); // Per-hop checkpoints. if (report.step) { @@ -1555,6 +1560,8 @@ export default class MigrateMeta extends Command { const result = applyMetaMigrationsToPackages(normalized, fromMajor, toMajor); // [ADR-0159, #37112] The per-site edits the protocol-19 form move leaves. const formSites = formMoveSites(normalized, fromMajor, toMajor); + // The own field rows beside Modify All that protocol 19 narrows (named, never rewritten). + const ownRowSites = ownFieldRowNarrowingSites(normalized, fromMajor, toMajor); // Prove the migrated stack is schema-valid — the "generated, provably valid // diff" the consumer agent reviews (ADR-0087 D3/D5). @@ -1618,6 +1625,8 @@ export default class MigrateMeta extends Command { // Only when the run crosses into protocol 19 and the form move // left a site: without one the payload is what it always was. ...(formSites.length > 0 ? { formMoveSites: formSites } : {}), + // Only when the run crosses into protocol 19 and an own field row narrows. + ...(ownRowSites.length > 0 ? { ownFieldRowNarrowing: ownRowSites } : {}), hops: flags.step ? result.hops.map((h) => ({ toMajor: h.toMajor, @@ -1676,6 +1685,7 @@ export default class MigrateMeta extends Command { ...(range ? { range } : {}), elapsed: timer.display(), formMoveSites: formSites, + ownFieldRowNarrowing: ownRowSites, ...(matrixDrift ? { accessMatrix: { diff --git a/packages/cli/src/utils/own-field-row-narrowing.ts b/packages/cli/src/utils/own-field-row-narrowing.ts new file mode 100644 index 00000000000..a3379afd4c4 --- /dev/null +++ b/packages/cli/src/utils/own-field-row-narrowing.ts @@ -0,0 +1,120 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `os migrate meta --from N` — the own field rows beside Modify All that the + * protocol-19 field-axis split narrows although the chain writes + * `viewAllFields: true` beside the bit (ruling of record 6912661484, step 3). + * + * The edit line the chain prints for such an entry is right: the bit keeps the + * reads Modify All cast on every field the set's own rows leave alone. What it + * cannot keep is Modify All's vote OVER the set's own rows: up to protocol 18 a + * set with Modify All on `contact` and its own `'contact.salary': + * { readable: false }` row read and edited `salary`; from 19 that row binds + * and the field is hidden from the set's holders. Validate and build stay + * green either way, so without a line naming the row the upgrade takes the + * field away silently. The predicate is the spec's + * ({@link ownFieldRowsBesideModifyAll}), shared with the `--stored` review + * list; this module only walks a source stack for it and prints it. + */ + +import chalk from 'chalk'; +import { + ALL_CONVERSIONS, + ownFieldRowsBesideModifyAll, + type OwnFieldRowBesideModifyAll, + type OwnFieldRowProtocol18Outcome, + type OwnFieldRowProtocol19Outcome, +} from '@objectstack/spec'; +import { applyMetaMigrations } from '@objectstack/spec/migrations'; + +/** The conversion whose rewritten entries the list is read beside. */ +const CONVERSION_ID = 'permission-view-all-fields-beside-record-bypass'; + +/** One narrowed own field row of one source permission set. */ +export interface OwnFieldRowNarrowingSite extends OwnFieldRowBesideModifyAll { + /** The permission set's `name`. */ + set: string; + /** Where the set sits in the stack the chain replays: `permissions[0]`, or `packages[1].manifest.permissions[0]`. */ + at: string; +} + +function isPlainRecord(value: unknown): value is Record { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} + +/** + * Every narrowed own field row of the stack's permission sets, read over the + * stack as it enters the conversion's hop (the chain replayed up to the major + * below it first, where `--from` is lower), and over each + * `packages[].manifest` body of an assembled stack the same way. Empty when the + * run does not cross into the conversion's major. + */ +export function ownFieldRowNarrowingSites( + stack: Record, + fromMajor: number, + toMajor: number, +): OwnFieldRowNarrowingSite[] { + const conversion = ALL_CONVERSIONS.find((c) => c.id === CONVERSION_ID); + if (!conversion) return []; + const major = conversion.toMajor; + if (!(fromMajor < major && toMajor >= major)) return []; + + const bodies: Array<{ prefix: string; body: Record }> = [{ prefix: '', body: stack }]; + if (Array.isArray(stack.packages)) { + stack.packages.forEach((entry, i) => { + if (isPlainRecord(entry) && isPlainRecord(entry.manifest)) bodies.push({ prefix: `packages[${i}].manifest.`, body: entry.manifest }); + }); + } + + const sites: OwnFieldRowNarrowingSite[] = []; + for (const { prefix, body } of bodies) { + const entering = fromMajor < major - 1 ? applyMetaMigrations(body, fromMajor, major - 1).stack : body; + const sets = (entering as { permissions?: unknown }).permissions; + if (!Array.isArray(sets)) continue; + sets.forEach((set, i) => { + if (!isPlainRecord(set)) return; + for (const row of ownFieldRowsBesideModifyAll(set)) { + sites.push({ set: String(set.name ?? ''), at: `${prefix}permissions[${i}]`, ...row }); + } + }); + } + return sites; +} + +const PROTOCOL_18: Record = { + 'read-and-edit': 'read and edit (Modify All voted over the set\'s own row)', +}; + +const PROTOCOL_19: Record = { + hidden: 'hidden, no read and no edit (the set\'s own `readable: false` row binds)', + 'read-only': 'read only (the set\'s own row binds, and it grants no edit)', + 'read-only-where-when-matches': + 'read, and locked on the rows the row\'s `when` matches (elsewhere the row votes nothing and the field ' + + 'follows the other sets and the object grant)', + 'edit-only-where-when-matches': + 'read, and this set votes the edit only on the rows the row\'s `when` matches (elsewhere the field follows ' + + 'the other sets and the object grant, and another set\'s lock is no longer out-voted)', +}; + +/** + * Group ②c — the narrowed own field rows, after the applied edits and the form + * move sites, before the semantic notices: each names the set, the entry, the + * row, the protocol-18 and protocol-19 answer through that set, and the choice. + */ +export function printOwnFieldRowNarrowing(sites: readonly OwnFieldRowNarrowingSite[]): void { + if (sites.length === 0) return; + console.log(chalk.bold(chalk.yellow( + ` ${sites.length} own field row(s) beside Modify All that protocol 19 narrows — ` + + 'the `viewAllFields: true` written beside the bit does not keep them:', + ))); + for (const site of sites) { + console.log( + ` ${chalk.yellow('⚠')} permission set '${site.set}' (${site.at}), objects entry '${site.object}', ` + + `field row '${site.field}'`, + ); + console.log(chalk.dim(` protocol 18: ${PROTOCOL_18[site.protocol18]}`)); + console.log(chalk.dim(` protocol 19: ${PROTOCOL_19[site.protocol19]}`)); + console.log(chalk.dim(` choice: ${site.choice}`)); + } + console.log(''); +} diff --git a/packages/cli/test/migrate-meta-own-field-row-38924.test.ts b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts new file mode 100644 index 00000000000..e285b3c4326 --- /dev/null +++ b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts @@ -0,0 +1,186 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `os migrate meta --from 18` names each own field row beside Modify All that + * protocol 19 narrows, and no longer says every field read is kept (#38924). + * + * ## The defect these pin + * + * Up to protocol 18 Modify All voted read and edit on every field of its + * object OVER the set's own field rows, so a set with View All + Modify All on + * `contact` and its own `'contact.salary': { readable: false }` row read and + * edited `salary`. From 19 the chain writes `viewAllFields: true` beside the + * bit, and an own row beats it: the field is hidden from the set's holders. + * The dry run said the addition kept the set's field reads and named no entry, + * so the upgrade took the field away behind a green validate and build. + * + * Pinned through the public door, `MigrateMeta.run`, in process (no process is + * spawned and no kernel is booted, so this file sits in the `unit` tier by + * behaviour): + * - the fixture set is named with its row, its protocol-19 answer and the + * choice, and the "field reads are kept" wording is absent; + * - the control, a set with View All only and no field row of its own, keeps + * its plain edit line and is not named; + * - `--json` carries the list under one new key, present only when non-empty, + * and the payload's other keys are exactly what they were. + * + * ⛔ No major is hard-coded: the range is read off the conversion's own + * `toMajor`, so the file stays true for as long as the chain carries it. + */ + +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { stripVTControlCharacters } from 'node:util'; +import { ALL_CONVERSIONS } from '@objectstack/spec'; +// The packages the command reaches through dynamic imports, loaded at module top so the +// first load is paid during collection, never inside a clocked case (`check:test-source-alias`). +import '@objectstack/cloud-connection'; +import '@objectstack/driver-sql'; +import '@objectstack/driver-turso'; +import '@objectstack/metadata'; +import '@objectstack/metadata-protocol'; +import '@objectstack/platform-objects/plugin'; +import '@objectstack/plugin-hono-server'; +import '@objectstack/plugin-security'; +import '@objectstack/rest'; +import '@objectstack/service-automation'; +import '@objectstack/service-datasource'; +import '@objectstack/service-settings'; +import '@objectstack/service-storage'; +import MigrateMeta from '../src/commands/migrate/meta.js'; +import { ownFieldRowNarrowingSites } from '../src/utils/own-field-row-narrowing.js'; + +const CLI_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..'); + +const CONVERSION_ID = 'permission-view-all-fields-beside-record-bypass'; +const MAJOR = ALL_CONVERSIONS.find((c) => c.id === CONVERSION_ID)!.toMajor; +const FROM = String(MAJOR - 1); + +const OBJECTS = ` + objects: [ + { name: 'contact', label: 'Contact', fields: { name: { type: 'text', label: 'Name' }, salary: { type: 'currency', label: 'Salary' } } }, + { name: 'account', label: 'Account', fields: { name: { type: 'text', label: 'Name' } } }, + ],`; + +/** The control alone: View All on `account`, no field row of its own. */ +const CONTROL_SET = ` + { name: 'auditor', label: 'Auditor', objects: { account: { allowRead: true, viewAllRecords: true } } },`; + +/** The card's fixture: View All + Modify All on `contact`, and its own row hiding `salary`. */ +const FIXTURE_SET = ` + { + name: 'hr_manager', label: 'HR Manager', + objects: { contact: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, + fields: { 'contact.salary': { readable: false } }, + },`; + +const config = (id: string, sets: string) => ` +export default { + manifest: { id: 'com.example.${id}', name: 'Own Row', version: '1.0.0', type: 'app' },${OBJECTS} + permissions: [${sets} + ], +}; +`; + +/** Every member a replay's payload carried before this change, in order. */ +const REPLAY_KEYS = [ + 'from', 'to', 'protocolVersion', 'applied', 'todos', 'absentTodos', + 'specChanges', 'schemaValid', 'dataMigrations', 'duration', +]; + +let dir: string; + +async function runMeta(app: 'fixture' | 'control', flags: string[]): Promise { + const out: string[] = []; + const priorExitCode = process.exitCode; + const write = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown, ...rest: unknown[]) => { + out.push(String(chunk)); + const done = rest.find((r) => typeof r === 'function') as (() => void) | undefined; + done?.(); + return true; + }) as never); + const log = vi.spyOn(console, 'log').mockImplementation((...a: unknown[]) => { out.push(a.join(' ')); }); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + const error = vi.spyOn(console, 'error').mockImplementation(() => {}); + try { + await MigrateMeta.run([join(dir, app, 'objectstack.config.ts'), '--from', FROM, ...flags], { root: CLI_ROOT }); + } finally { + write.mockRestore(); + log.mockRestore(); + warn.mockRestore(); + error.mockRestore(); + process.exitCode = priorExitCode; + } + return stripVTControlCharacters(out.join('\n')); +} + +beforeAll(() => { + dir = mkdtempSync(join(tmpdir(), 'os-migrate-own-row-')); + mkdirSync(join(dir, 'fixture')); + mkdirSync(join(dir, 'control')); + writeFileSync(join(dir, 'fixture', 'objectstack.config.ts'), config('own-row-fixture', FIXTURE_SET + CONTROL_SET)); + writeFileSync(join(dir, 'control', 'objectstack.config.ts'), config('own-row-control', CONTROL_SET)); +}); + +afterAll(() => { + rmSync(dir, { recursive: true, force: true }); +}); + +describe('os migrate meta --from 18 — the own field rows beside Modify All protocol 19 narrows (#38924)', () => { + it('names the fixture set, its row and its protocol-19 answer, and says no more that field reads are kept', async () => { + const text = await runMeta('fixture', []); + + expect(text).toContain("permission set 'hr_manager' (permissions[0]), objects entry 'contact', field row 'contact.salary'"); + expect(text).toContain('protocol 18: read and edit'); + expect(text).toContain('protocol 19: hidden, no read and no edit'); + expect(text).toMatch(/choice: to keep the protocol-18 read and edit, .*otherwise accept the narrowing\./); + expect(text).not.toContain('so their field reads are kept'); + // The control set rides in the same stack and is not named. + expect(text).not.toContain("permission set 'auditor'"); + }, 60_000); + + it('the control (View All only, no field row of its own) keeps its plain edit line and names nothing', async () => { + const text = await runMeta('control', []); + + expect(text).toContain( + `permissions[0].objects.account.viewAllFields: viewAllFields absent beside viewAllRecords: true (the bit voted on every field) → true (${CONVERSION_ID})`, + ); + expect(text).not.toContain('own field row(s) beside Modify All'); + }, 60_000); + + it('reads each package body of an assembled stack under its own prefix, as the chain reports its edits', () => { + const set = { + name: 'hr_manager', + objects: { contact: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'contact.salary': { readable: false } }, + }; + const sites = ownFieldRowNarrowingSites({ packages: [{ manifest: { permissions: [set] } }] }, MAJOR - 1, MAJOR); + expect(sites.map((s) => [s.at, s.set, s.field, s.protocol19])).toEqual([ + ['packages[0].manifest.permissions[0]', 'hr_manager', 'contact.salary', 'hidden'], + ]); + // A run that does not cross into the conversion's major names nothing. + expect(ownFieldRowNarrowingSites({ permissions: [set] }, MAJOR, MAJOR)).toEqual([]); + }); + + it('--json carries the list under `ownFieldRowNarrowing` only when non-empty; every other key is unchanged', async () => { + const withRows = JSON.parse(await runMeta('fixture', ['--json'])); + const without = JSON.parse(await runMeta('control', ['--json'])); + + expect(Object.keys(without)).toEqual(REPLAY_KEYS); + expect(Object.keys(withRows)).toEqual([...REPLAY_KEYS.slice(0, 6), 'ownFieldRowNarrowing', ...REPLAY_KEYS.slice(6)]); + expect(withRows.ownFieldRowNarrowing).toEqual([ + { + set: 'hr_manager', + at: 'permissions[0]', + object: 'contact', + field: 'contact.salary', + protocol18: 'read-and-edit', + protocol19: 'hidden', + choice: expect.stringMatching(/otherwise accept the narrowing\.$/), + }, + ]); + }, 60_000); +}); diff --git a/packages/cli/test/normalized-call-sites.test.ts b/packages/cli/test/normalized-call-sites.test.ts index 5b96a0ef216..ec3bd109b17 100644 --- a/packages/cli/test/normalized-call-sites.test.ts +++ b/packages/cli/test/normalized-call-sites.test.ts @@ -148,6 +148,10 @@ const SITES: Readonly> = { reads: 'packages', why: 'the protocol-19 form move\'s per-site lines (#37112): asks the move and its translation companion over the stack entering the 19 hop and over each `packages[i].manifest` body, each under its own prefix, as `applyMetaMigrationsToPackages` reports edits. Measured on an assembled stack in `meta.form-move-sites.test.ts` (a body\'s site reads `packages[0].manifest.views[0].formViews.other`).', }, + 'migrate/meta.ts :: ownFieldRowNarrowingSites(normalized': { + reads: 'packages', + why: 'the own field rows beside Modify All that protocol 19 narrows (#38924): read over the stack entering the 19 hop and over each `packages[i].manifest` body, each under its own prefix, as `formMoveSites` reads them. Measured on an assembled stack in `migrate-meta-own-field-row-38924.test.ts` (a body\'s site reads `packages[0].manifest.permissions[0]`).', + }, 'migrate/meta.ts :: planProtocolRange(normalized': { reads: 'top-level', why: 'reads the handshake range off `manifest`, where the load seam reads it (`AppPlugin`: `bundle.manifest || bundle`); a `preserve` artifact keeps `manifest` at the top level.', diff --git a/packages/metadata-protocol/src/index.ts b/packages/metadata-protocol/src/index.ts index 15f630d3a35..fd43dd623aa 100644 --- a/packages/metadata-protocol/src/index.ts +++ b/packages/metadata-protocol/src/index.ts @@ -263,6 +263,7 @@ export type { StoredMigrationTodo, StoredViewAllFieldsReview, } from './stored-migration.js'; +export type { StoredOwnFieldRow } from './stored-own-field-rows.js'; export { computeMetadataDiagnostics, diff --git a/packages/metadata-protocol/src/stored-migration.ts b/packages/metadata-protocol/src/stored-migration.ts index 6ab6dd64fb7..2734a9be0fa 100644 --- a/packages/metadata-protocol/src/stored-migration.ts +++ b/packages/metadata-protocol/src/stored-migration.ts @@ -37,6 +37,7 @@ */ import { ALL_CONVERSIONS } from '@objectstack/spec'; +import { formatStoredOwnFieldRows, storedOwnFieldRows, type StoredOwnFieldRow } from './stored-own-field-rows.js'; /** * What a caller with a live automation engine hands back for a stored `flow` @@ -317,6 +318,8 @@ export interface StoredViewAllFieldsReview { object: string; /** The record-bypass bits the entry carries, in this order: `viewAllRecords`, then `modifyAllRecords`. */ bits: Array<'viewAllRecords' | 'modifyAllRecords'>; + /** Beside Modify All, the set's own field rows protocol 19 narrows ({@link storedOwnFieldRows}); absent when none. */ + ownFieldRows?: StoredOwnFieldRow[]; } /** @@ -465,7 +468,7 @@ export const VIEW_ALL_FIELDS_REVIEW_CONVERSION_ID = 'permission-view-all-fields- */ export function collectViewAllFieldsReview( body: unknown, -): Array<{ object: string; bits: Array<'viewAllRecords' | 'modifyAllRecords'> }> { +): Array> { if (body === null || typeof body !== 'object' || Array.isArray(body)) return []; const entry = ALL_CONVERSIONS.find((c) => c.id === VIEW_ALL_FIELDS_REVIEW_CONVERSION_ID); if (!entry) { @@ -500,7 +503,7 @@ export function collectViewAllFieldsReview( const bits: Array<'viewAllRecords' | 'modifyAllRecords'> = []; if (objectEntry.viewAllRecords === true) bits.push('viewAllRecords'); if (objectEntry.modifyAllRecords === true) bits.push('modifyAllRecords'); - return { object, bits }; + return { object, bits, ...storedOwnFieldRows(body, object) }; }); } @@ -633,6 +636,7 @@ export function formatStoredMigrationReport(report: StoredMigrationReport): stri ); for (const r of viewAll) { lines.push(` • permission/${r.name} ${describeScope(r)} — objects entry '${r.object}' (${r.bits.join(', ')})`); + lines.push(...formatStoredOwnFieldRows(r)); } lines.push( ' Before protocol 19 View All and Modify All also opened every field of the object; they now widen ' + diff --git a/packages/metadata-protocol/src/stored-own-field-rows.test.ts b/packages/metadata-protocol/src/stored-own-field-rows.test.ts new file mode 100644 index 00000000000..ecd1c544529 --- /dev/null +++ b/packages/metadata-protocol/src/stored-own-field-rows.test.ts @@ -0,0 +1,70 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The View All Fields review list of `os migrate meta --stored` names, under an + * entry with Modify All, each own field row protocol 19 narrows beside it — the + * same shape `os migrate meta --from 18` names in a source. A stored set is + * never rewritten, and adding `viewAllFields: true` through the API does not + * restore such a row, so the list says so per row. An entry with no such row + * keeps the shape and the line it always had. + */ + +import { describe, expect, it } from 'vitest'; +import { collectViewAllFieldsReview, formatStoredMigrationReport, type StoredMigrationReport } from './stored-migration.js'; + +const SET = { + name: 'hr_manager', + objects: { + contact: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true }, + account: { allowRead: true, viewAllRecords: true }, + }, + fields: { + 'contact.salary': { readable: false }, + 'contact.grade': { readable: true }, + // View All alone: the own row bound on 18 already, so nothing to name. + 'account.revenue': { readable: false }, + }, +}; + +const report = (viewAllFieldsReview: StoredMigrationReport['viewAllFieldsReview']): StoredMigrationReport => ({ + apply: false, + protocol: '19.0.0', + scanned: 1, + canonical: 1, + pending: 0, + rewritten: 0, + skipped: 0, + failed: 0, + servedInvalid: 0, + rows: [], + decisionModeReview: [], + viewAllFieldsReview, +}); + +describe('the stored View All Fields review list names the own field rows beside Modify All', () => { + it('carries `ownFieldRows` on the Modify All entry only, with the protocol-19 answer of each row', () => { + const entries = collectViewAllFieldsReview(SET); + expect(entries).toEqual([ + { + object: 'contact', + bits: ['viewAllRecords', 'modifyAllRecords'], + ownFieldRows: [ + expect.objectContaining({ field: 'contact.salary', protocol18: 'read-and-edit', protocol19: 'hidden' }), + expect.objectContaining({ field: 'contact.grade', protocol18: 'read-and-edit', protocol19: 'read-only' }), + ], + }, + // No own row narrows beside View All: the member is absent, not empty. + { object: 'account', bits: ['viewAllRecords'] }, + ]); + }); + + it('prints each narrowed row under its entry, and nothing extra under an entry without one', () => { + const scope = { id: 'r_1', name: 'hr_manager', organizationId: null, packageId: null, state: 'active' as const }; + const lines = formatStoredMigrationReport(report(collectViewAllFieldsReview(SET).map((e) => ({ ...scope, ...e })))); + const contact = lines.findIndex((l) => l.includes("objects entry 'contact'")); + expect(lines[contact + 1]).toContain("own field row 'contact.salary' beside Modify All: protocol 18 read and edit, protocol 19 hidden"); + expect(lines[contact + 2]).toContain("own field row 'contact.grade' beside Modify All: protocol 18 read and edit, protocol 19 read only"); + const account = lines.findIndex((l) => l.includes("objects entry 'account'")); + expect(lines[account + 1]).not.toContain('own field row'); + }); +}); diff --git a/packages/metadata-protocol/src/stored-own-field-rows.ts b/packages/metadata-protocol/src/stored-own-field-rows.ts new file mode 100644 index 00000000000..a220584c5ae --- /dev/null +++ b/packages/metadata-protocol/src/stored-own-field-rows.ts @@ -0,0 +1,51 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The own field rows of a STORED permission set that protocol 19 narrows + * beside its Modify All — the rows the View All Fields review list + * (`StoredViewAllFieldsReview`) names under the entry they sit beside. + * + * A stored set is read with the 19 meaning and never rewritten (ruling of + * record 7177446075, option A); the operator restores its reads by adding + * `viewAllFields: true` to the entry through the metadata API. Beside Modify + * All that does not restore a field the set's own row hides or locks: up to + * protocol 18 Modify All voted read and edit over the set's own rows, and from + * 19 an own row beats `viewAllFields`. So each such row is named with its + * protocol-18 and protocol-19 answer and the choice. The predicate is the + * spec's ({@link ownFieldRowsBesideModifyAll}), the one `os migrate meta + * --from 18` reads over a source; this module only selects one entry's rows + * and renders them. + */ + +import { ownFieldRowsBesideModifyAll, type OwnFieldRowBesideModifyAll } from '@objectstack/spec'; + +/** One own field row beside a listed entry's Modify All that protocol 19 narrows. */ +export type StoredOwnFieldRow = Omit; + +/** + * The narrowed own field rows of `body` beside its `objects` entry `object`, + * as the member the review entry carries: absent when there is none, so an + * entry without one keeps the shape it always had. + */ +export function storedOwnFieldRows(body: unknown, object: string): { ownFieldRows?: StoredOwnFieldRow[] } { + const rows = ownFieldRowsBesideModifyAll(body) + .filter((row) => row.object === object) + .map(({ object: _object, ...row }) => row); + return rows.length > 0 ? { ownFieldRows: rows } : {}; +} + +const PROTOCOL_19: Record = { + hidden: 'hidden, no read and no edit', + 'read-only': 'read only', + 'read-only-where-when-matches': 'read, and locked on the rows its `when` matches', + 'edit-only-where-when-matches': 'read, and this set votes the edit only on the rows its `when` matches', +}; + +/** The lines naming one review entry's narrowed own field rows, nested under the entry's line. */ +export function formatStoredOwnFieldRows(entry: { ownFieldRows?: readonly StoredOwnFieldRow[] }): string[] { + return (entry.ownFieldRows ?? []).map( + (row) => + ` own field row '${row.field}' beside Modify All: protocol 18 read and edit, protocol 19 ` + + `${PROTOCOL_19[row.protocol19]} (adding \`viewAllFields: true\` does not change it); ${row.choice}`, + ); +} diff --git a/packages/spec/api-surface/root.json b/packages/spec/api-surface/root.json index aaac8b3f738..52a7ea52732 100644 --- a/packages/spec/api-surface/root.json +++ b/packages/spec/api-surface/root.json @@ -113,6 +113,9 @@ "ObjectStackDefinitionParsed (type)", "ObjectStackDefinitionSchema (const)", "ObjectStackSchema (const)", + "OwnFieldRowBesideModifyAll (interface)", + "OwnFieldRowProtocol18Outcome (type)", + "OwnFieldRowProtocol19Outcome (type)", "P (const)", "PLATFORM_ALWAYS_ON_CAPABILITIES (const)", "PLATFORM_CAPABILITY_PROVIDERS (const)", @@ -201,6 +204,7 @@ "normalizePluginMetadata (function)", "normalizeStackInput (function)", "objectStackErrorMap (const)", + "ownFieldRowsBesideModifyAll (function)", "partitionAssembledViewArtifacts (function)", "safeParsePretty (function)", "stackConversionsOf (function)", diff --git a/packages/spec/export-origins/root.json b/packages/spec/export-origins/root.json index e853c4b68da..d0505bf4b67 100644 --- a/packages/spec/export-origins/root.json +++ b/packages/spec/export-origins/root.json @@ -112,6 +112,9 @@ "ObjectStackDefinitionParsed": "src/stack.zod.ts#ObjectStackDefinitionParsed (type)", "ObjectStackDefinitionSchema": "src/stack.zod.ts#ObjectStackDefinitionSchema (const)", "ObjectStackSchema": "src/stack.zod.ts#ObjectStackSchema (const)", + "OwnFieldRowBesideModifyAll": "src/conversions/own-field-rows-beside-modify-all.ts#OwnFieldRowBesideModifyAll (interface)", + "OwnFieldRowProtocol18Outcome": "src/conversions/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol18Outcome (type)", + "OwnFieldRowProtocol19Outcome": "src/conversions/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol19Outcome (type)", "P": "src/shared/expression.zod.ts#P (const)", "PLATFORM_ALWAYS_ON_CAPABILITIES": "src/kernel/platform-capabilities.ts#PLATFORM_ALWAYS_ON_CAPABILITIES (const)", "PLATFORM_CAPABILITY_PROVIDERS": "src/kernel/platform-capabilities.ts#PLATFORM_CAPABILITY_PROVIDERS (const)", @@ -200,6 +203,7 @@ "normalizePluginMetadata": "src/shared/metadata-collection.zod.ts#normalizePluginMetadata (function)", "normalizeStackInput": "src/shared/metadata-collection.zod.ts#normalizeStackInput (function)", "objectStackErrorMap": "src/shared/error-map.zod.ts#objectStackErrorMap (const)", + "ownFieldRowsBesideModifyAll": "src/conversions/own-field-rows-beside-modify-all.ts#ownFieldRowsBesideModifyAll (function)", "partitionAssembledViewArtifacts": "src/ui/assembled-views.zod.ts#partitionAssembledViewArtifacts (function)", "safeParsePretty": "src/shared/error-map.zod.ts#safeParsePretty (function)", "stackConversionsOf": "src/stack-provenance.ts#stackConversionsOf (function)", diff --git a/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts b/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts index 53a0d6c2935..09d3d3c8d47 100644 --- a/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts +++ b/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts @@ -28,7 +28,8 @@ import { isDict } from '../shared.js'; * Every `objects` entry of every permission set, the `'*'` entry included, * that carries `viewAllRecords: true` or `modifyAllRecords: true` and has no * `viewAllFields` key gets `viewAllFields: true`, so a source written while the - * bits read every field keeps every read they cast. An entry whose author + * bits read every field keeps the reads they cast, except the two losses + * listed below. An entry whose author * already wrote `viewAllFields` — either value — has spoken and is left alone, * which is also what makes a second replay a no-op. * @@ -78,8 +79,9 @@ const permissionViewAllFieldsBesideRecordBypass: MetadataConversion = { summary: "object-permission entry ('*' included) with 'viewAllRecords: true' or 'modifyAllRecords: true' and no " + "'viewAllFields': 'viewAllFields: true' written beside it (from protocol 19 View All and Modify All widen " - + 'records only and cast no field vote; the bit keeps every field read they cast. Modify All\'s edit vote ' - + 'is not kept, and the set\'s own readable: false rows now bind)', + + 'records only and cast no field vote; the bit keeps the field reads they cast, except a field the set\'s ' + + 'own readable: false row hides beside Modify All, which that row now binds. Modify All\'s edit vote is not ' + + 'kept)', apply(stack, emit) { return mapCollection(stack, 'permissions', (ps, path) => { const objects = (ps as { objects?: unknown }).objects; diff --git a/packages/spec/src/conversions/index.ts b/packages/spec/src/conversions/index.ts index 630ed35fa95..2babb86c0aa 100644 --- a/packages/spec/src/conversions/index.ts +++ b/packages/spec/src/conversions/index.ts @@ -31,3 +31,9 @@ export { applyConversionsToStoredItem, type StoredConversionOptions, } from './stored.js'; +export { + ownFieldRowsBesideModifyAll, + type OwnFieldRowBesideModifyAll, + type OwnFieldRowProtocol18Outcome, + type OwnFieldRowProtocol19Outcome, +} from './own-field-rows-beside-modify-all.js'; diff --git a/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts b/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts new file mode 100644 index 00000000000..49fa4f1b8ca --- /dev/null +++ b/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts @@ -0,0 +1,126 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `ownFieldRowsBesideModifyAll` — the own field rows beside Modify All that + * protocol 19 narrows although `viewAllFields: true` is written beside the bit. + * One predicate for `os migrate meta --from 18` and the `--stored` review list: + * each listed case, and each shape that answers on 19 as it did on 18, is + * pinned here. + */ + +import { describe, expect, it } from 'vitest'; +import { ownFieldRowsBesideModifyAll } from './own-field-rows-beside-modify-all.js'; + +const MODIFY_ALL = { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true }; + +describe('ownFieldRowsBesideModifyAll', () => { + it('names an own readable: false row beside Modify All: read and edit on 18, hidden on 19', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'hr_manager', + objects: { contact: MODIFY_ALL }, + fields: { 'contact.salary': { readable: false } }, + }); + expect(rows).toEqual([ + expect.objectContaining({ object: 'contact', field: 'contact.salary', protocol18: 'read-and-edit', protocol19: 'hidden' }), + ]); + expect(rows[0]!.choice).toMatch(/otherwise accept the narrowing\.$/); + }); + + it('names a row with no editable: true as read-only, and an editable row with a `when` as a conditional edit', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'hr_manager', + objects: { contact: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { + 'contact.grade': { readable: true }, + 'contact.bonus': { readable: true, editable: false }, + 'contact.notes': { readable: true, editable: true, when: 'status == "open"' }, + // What 18 gave through this set: not listed. + 'contact.phone': { readable: true, editable: true }, + }, + }); + expect(rows.map((r) => [r.field, r.protocol19])).toEqual([ + ['contact.grade', 'read-only'], + ['contact.bonus', 'read-only'], + ['contact.notes', 'edit-only-where-when-matches'], + ]); + }); + + it('names a row-conditioned lock (a `when`, no editable: true) as a lock on the matching rows only, not read-only', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'deal_desk', + objects: { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'deal.amount': { readable: true, when: 'stage in ["approved"]' } }, + }); + expect(rows.map((r) => [r.field, r.protocol19])).toEqual([['deal.amount', 'read-only-where-when-matches']]); + }); + + it('each choice leads to a row the list no longer names, so the next run is quiet', () => { + // The row each choice spells, by outcome: the one shape 19 answers as 18 did. + const followed: Record> = { + hidden: { readable: true, editable: true }, + 'read-only': { readable: true, editable: true }, + 'read-only-where-when-matches': { readable: true, editable: true }, + 'edit-only-where-when-matches': { readable: true, editable: true }, + }; + const before = { + 'contact.a': { readable: false }, + 'contact.b': { readable: true }, + 'contact.c': { readable: true, when: 'status == "open"' }, + 'contact.d': { readable: true, editable: true, when: 'status == "open"' }, + }; + const listed = ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL }, fields: before }); + expect(listed.map((r) => r.protocol19)).toEqual([ + 'hidden', 'read-only', 'read-only-where-when-matches', 'edit-only-where-when-matches', + ]); + for (const row of listed) { + expect(row.choice).toMatch(/`readable: true, editable: true`|add `editable: true`|remove the row's `when`/); + } + const after = Object.fromEntries(listed.map((r) => [r.field, followed[r.protocol19]])); + expect(ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL }, fields: after })).toEqual([]); + }); + + it('never lists a `*.FIELD` row: no merge reads a wildcard field key', () => { + expect(ownFieldRowsBesideModifyAll({ + name: 'ops_admin', + objects: { '*': MODIFY_ALL }, + fields: { '*.salary': { readable: false } }, + })).toEqual([]); + }); + + it('reads a row of an object the set does not name against its `*` entry', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'ops_admin', + objects: { '*': MODIFY_ALL, account: { allowRead: true } }, + fields: { + 'contact.salary': { readable: false }, + // The explicit entry is the set's whole answer for `account`: no Modify All there. + 'account.revenue': { readable: false }, + }, + }); + expect(rows.map((r) => [r.object, r.field])).toEqual([['*', 'contact.salary']]); + }); + + it('lists nothing for View All alone: its own rows already bound on 18', () => { + expect(ownFieldRowsBesideModifyAll({ + name: 'auditor', + objects: { contact: { allowRead: true, viewAllRecords: true } }, + fields: { 'contact.salary': { readable: false }, 'contact.grade': { readable: true } }, + })).toEqual([]); + }); + + it('lists nothing for an entry whose author already wrote `viewAllFields`, either way: the conversion leaves it alone', () => { + for (const viewAllFields of [true, false]) { + expect(ownFieldRowsBesideModifyAll({ + name: 'hr_manager', + objects: { contact: { ...MODIFY_ALL, viewAllFields } }, + fields: { 'contact.salary': { readable: false } }, + })).toEqual([]); + } + }); + + it('answers an empty list for a body that is not a set, or a set with no field rows', () => { + expect(ownFieldRowsBesideModifyAll(null)).toEqual([]); + expect(ownFieldRowsBesideModifyAll([])).toEqual([]); + expect(ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL } })).toEqual([]); + }); +}); diff --git a/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts b/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts new file mode 100644 index 00000000000..4400123e4ea --- /dev/null +++ b/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts @@ -0,0 +1,161 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The permission-set field rows the protocol-19 field-axis split narrows + * although `viewAllFields: true` is written beside the bit — one predicate, + * read by `os migrate meta --from 18` over a source and by + * `os migrate meta --stored` over a stored set. + * + * ## The shape + * + * Up to protocol 18 Modify All (`modifyAllRecords`) voted `readable: true` and + * `editable: true` on every field of its object, OVER the set's own field rows: + * a set holding Modify All on `contact` and its own `'contact.salary': + * { readable: false }` row still read and edited `salary`. From 19 the bit + * casts no field vote; the conversion `permission-view-all-fields-beside-record-bypass` + * writes `viewAllFields: true` beside it, which votes read only, and an own row + * of the same set beats it (specific beats general, ruling of record + * 6912661484). So beside Modify All an own row is the set's whole say on its + * field, and its holders get, through this set: + * + * - `readable: false`: no read and no edit (`hidden`); + * - `readable` true, no `editable: true` (an omitted `editable` is `false`) + * and no `when`: the read only, on every row (`read-only`); + * - `readable` true, no `editable: true`, beside a `when`: a lock on the + * rows the condition matches only (`read-only-where-when-matches`). The + * read vote is row-blind, but the entry votes nothing on a row its `when` + * does not match (`fieldPermissionVote` answers `null`), so there the field + * answers as it did on 18 when no other set names it; + * - `editable: true` beside a `when`: this set's edit vote on the rows the + * condition matches only (`edit-only-where-when-matches`). On the other rows + * the entry is absent and the field follows the other sets and the object + * grant; what changes is the row-blind reading of the set's lock and the + * answer beside another set's lock, which Modify All out-voted on 18; + * - `editable: true` and no `when`: what protocol 18 gave — not listed. + * + * Each `choice` names the row that answers as protocol 18 did, which this + * list never names, so following the choice takes the row off the list. + * + * A row keyed `'*.FIELD'` is never listed: no merge reads a wildcard field + * key (field rows have no wildcard, ruling of record 6912661484), so it is + * inert on both sides of the split. + * + * View All (`viewAllRecords`) alone is not this shape: up to 18 the set's own + * row already beat its own View All (ADR-0066 D2 ⑧, note of 2026-11-15), and + * View All never voted an edit, so its own rows give the same answer on both + * sides of the split. + * + * ## Which entries + * + * Exactly the entries the conversion rewrites (it is run here, its emitted + * paths kept, its returned stack discarded), narrowed to those holding Modify + * All: an `objects` entry, the `'*'` entry included, with + * `modifyAllRecords: true` and no `viewAllFields` key. An entry whose author + * already wrote `viewAllFields` either way is left alone by the conversion and + * by this list. A field row `OBJECT.FIELD` belongs to the set's own entry for + * `OBJECT` when it has one and to its `'*'` entry otherwise: the lookup the + * field merge takes (`holdsSuperuserBypass`, `viewAllFieldsReadVote`). + * + * The answer is per SET: another set the same holder carries can still grant + * the field (union across sets is unchanged). + * + * It lives beside the conversion layer, on the package root, and not on the + * `@objectstack/spec/migrations` entry: the stored-row reader in + * `@objectstack/metadata-protocol` is runtime code, and that entry pins the + * whole `os migrate meta` guidance registry into whatever imports it. + */ + +import { permissionViewAllFieldsBesideRecordBypass } from './entries/19/permission-view-all-fields-beside-record-bypass.js'; + +/** What a holder of the set read and edited on the field through this set on protocol 18. */ +export type OwnFieldRowProtocol18Outcome = 'read-and-edit'; + +/** What a holder of the set reads and edits on the field through this set on protocol 19. */ +export type OwnFieldRowProtocol19Outcome = + | 'hidden' + | 'read-only' + | 'read-only-where-when-matches' + | 'edit-only-where-when-matches'; + +/** One own field row beside Modify All whose answer protocol 19 narrows. */ +export interface OwnFieldRowBesideModifyAll { + /** The `objects` key whose Modify All covered the row: the object name, or `'*'`. */ + object: string; + /** The row's key in the set's `fields`, as written: `OBJECT.FIELD`. */ + field: string; + protocol18: OwnFieldRowProtocol18Outcome; + protocol19: OwnFieldRowProtocol19Outcome; + /** The one-line choice: change the row to keep the protocol-18 answer, or accept the narrowing. */ + choice: string; +} + +// Every choice leads to `readable: true, editable: true` with no `when`, the +// one row shape this list never names, so a run after following it is quiet. +const CHOICE: Record = { + hidden: + 'to keep the protocol-18 read and edit, change the row to `readable: true, editable: true`; ' + + 'otherwise accept the narrowing.', + 'read-only': + 'to keep the protocol-18 edit, add `editable: true` to the row; otherwise accept the narrowing.', + 'read-only-where-when-matches': + 'to keep the protocol-18 edit on every row, change the row to `readable: true, editable: true` with no ' + + '`when`; otherwise accept the narrowing.', + 'edit-only-where-when-matches': + 'to keep the protocol-18 edit on every row, remove the row\'s `when`; otherwise accept the narrowing.', +}; + +function isDict(value: unknown): value is Record { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} + +/** The narrowed outcome of one own row beside Modify All, or `undefined` when 19 answers as 18 did. */ +function narrowedOutcome(row: Record): OwnFieldRowProtocol19Outcome | undefined { + if (row.readable === false) return 'hidden'; + const conditioned = typeof row.when === 'string' && row.when.trim() !== ''; + if (row.editable !== true) return conditioned ? 'read-only-where-when-matches' : 'read-only'; + if (conditioned) return 'edit-only-where-when-matches'; + return undefined; +} + +/** + * The own field rows of ONE permission-set body that protocol 19 narrows beside + * the set's Modify All — see the module header for the shape. In `fields` + * order; empty when the body is not a set or nothing is narrowed. + * + * ⛔ Throws when the conversion names a path of a shape this reader does not + * know: a list that silently came back empty would tell an upgrader that no + * row of the set narrows. + */ +export function ownFieldRowsBesideModifyAll(set: unknown): OwnFieldRowBesideModifyAll[] { + if (!isDict(set) || !isDict(set.objects) || !isDict(set.fields)) return []; + const objects = set.objects; + const pathToObject = new Map( + Object.keys(objects).map((name): [string, string] => [`permissions[0].objects.${name}.viewAllFields`, name]), + ); + const rewritten = new Set(); + permissionViewAllFieldsBesideRecordBypass.apply({ permissions: [set] }, (detail) => { + const object = pathToObject.get(detail.path); + if (object === undefined) { + throw new Error( + `the conversion '${permissionViewAllFieldsBesideRecordBypass.id}' reported a path of an unknown shape ` + + `('${detail.path}'), so the own field rows beside Modify All cannot be named.`, + ); + } + rewritten.add(object); + }); + + const out: OwnFieldRowBesideModifyAll[] = []; + for (const [field, row] of Object.entries(set.fields)) { + const dot = field.indexOf('.'); + if (dot <= 0 || !isDict(row)) continue; + const objectName = field.slice(0, dot); + if (objectName === '*') continue; // no merge reads a wildcard field key + const covering = objects[objectName] ? objectName : '*'; + const entry = objects[covering]; + if (!rewritten.has(covering) || !isDict(entry) || entry.modifyAllRecords !== true) continue; + const protocol19 = narrowedOutcome(row); + if (!protocol19) continue; + out.push({ object: covering, field, protocol18: 'read-and-edit', protocol19, choice: CHOICE[protocol19] }); + } + return out; +} diff --git a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts index dbe6dddee48..3f839a01ca5 100644 --- a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts +++ b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts @@ -6,8 +6,9 @@ import type { SemanticMigration } from '../../types.js'; // All and Modify All stop voting on fields, and `viewAllFields` is the one // "every field" bit. The D2 conversion // `permission-view-all-fields-beside-record-bypass` writes `viewAllFields: true` -// beside the two bits in a SOURCE that predates the switch, which keeps every -// field read they cast; this entry names what changes anyway, and what a +// beside the two bits in a SOURCE that predates the switch, which keeps the +// field reads they cast but a field the set's own row hides beside Modify All; +// this entry names what changes anyway, and what a // deployment owes for the permission sets it STORES, which the conversion never // rewrites (ruling of record 7177446075, option A: stored sets are read with // the 19 meaning). No `relevantWhen`: a stack with no authored permission set @@ -51,16 +52,24 @@ export const entry: SemanticMigration = { + 'every sharing and RLS reader folds through, and any field no set names, which still follows the ' + 'object grant.\n\n' + 'SOURCE permission sets: `os migrate meta --from 18 --write` adds `viewAllFields: true` beside every ' - + 'such bit (the D2 conversion `permission-view-all-fields-beside-record-bypass`), so their field reads ' - + 'are kept. The conversion replays only there: it is a default flip, retired from the load path, so the ' - + 'authoring funnel skips it, and the artifact-ingestion door and every stored-row read ' - + '(`applyConversionsToStoredItem`) refuse it by id.\n\n' + + 'such bit (the D2 conversion `permission-view-all-fields-beside-record-bypass`), which keeps the field ' + + 'reads the bits cast, except a field the set\'s own `readable: false` row hides beside its Modify All: that ' + + 'row now binds. It keeps no edit Modify All cast. The same command, with or without `--write`, names each ' + + 'own field row beside a Modify All bit it writes `viewAllFields: true` beside in that run, where the row ' + + 'now hides its field, locks it (on every row or on the rows its `when` matches) or limits its edit to the ' + + 'rows its `when` matches, with its protocol-18 and protocol-19 answer and the choice: change the row to ' + + 'keep the protocol-18 answer, or accept the narrowing. It names no row beside an entry that already ' + + 'carries `viewAllFields` (a source the edit was applied to, by `--write` or by hand): review those rows ' + + 'against the criteria below. The conversion replays only there: it is a default flip, ' + + 'retired from the load path, so the authoring funnel skips it, and the artifact-ingestion door and every ' + + 'stored-row read (`applyConversionsToStoredItem`) refuse it by id.\n\n' + 'STORED permission sets (Studio-saved, in `sys_metadata`): they are NOT rewritten on upgrade and are ' + 'read with the 19 meaning, by maintainer ruling. Studio\'s permission matrix has no `viewAllFields` ' + 'control today (it keeps the key when it saves a set that already carries it), so restore a stored ' + 'set\'s reads by adding `viewAllFields: true` to its entry through the metadata API. ' + '`os migrate meta --stored` lists every affected entry of a stored set (`viewAllFieldsReview`, read-only: ' - + 'it writes nothing). The error direction is fewer fields seen, never a field opened.', + + 'it writes nothing), and under an entry with Modify All each own field row protocol 19 narrows beside it. ' + + 'The error direction is fewer fields seen, never a field opened.', acceptanceCriteria: 'Before or after moving a deployment to protocol 19, the one-step check, for every permission set in ' + 'source and every one stored in the deployment: the set is ' @@ -82,6 +91,7 @@ export const entry: SemanticMigration = { + '`security-cross-set-field-reopen` on a field one set hides that another set\'s `viewAllFields` ' + 're-opens, so a bit added where the hide was meant is visible there.', // The edits this entry judges: every `viewAllFields: true` that conversion - // writes keeps a read; the criteria above say when to delete it instead. + // writes keeps the reads the bit cast but a field the set's own row hides + // beside Modify All; the criteria above say when to delete it instead. conversionIds: ['permission-view-all-fields-beside-record-bypass'], };