Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/34401-own-permission-set-restore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/metadata-protocol': patch
---

fix(metadata-protocol): a package's rollback, commit revert or package rollback of its own permission set is no longer refused because a package of another namespace ships a set of that name

Clause-②: yes (widening) — a rollback, a commit revert or a package rollback of a package's own permission set N, refused 403 `NOT_OVERRIDABLE` ("provided by a managed package and is sealed") while a package of another namespace ships N, now restores; a delete of that set answers "Deleted permission 'N' (package=P) — it no longer exists." in place of "Customization overlay deleted (package=P) — permission/N reset to artifact default.", with `reset: true` as before; nothing the doors accepted is refused
Metadata-protocol: none

A permission set is `(package, name)` (ADR-0150 D2/D9). The save door, the draft publish and the publish undo already judge a write of a package's own set `N` by the package it is addressed to. The per-item rollback (`POST /api/v1/meta/:type/:name/rollback`), the commit revert (`POST /packages/:id/commits/:commitId/revert`) and the package rollback (`POST /packages/:id/rollback`, which reverts commit by commit) still judged the name alone: when package `crm` shipped `N`, package `hr` of another namespace could not restore an earlier version of its own `N`. The rollback answered 403 `NOT_OVERRIDABLE`, and a revert listed `N` in `failed[]`.

Those restores now read the same verdict as the save. A restore into `hr`'s own `N` is a runtime write to `hr`, so the earlier version is restored and `hr`'s grants confer it. Every package that ships the name is judged, so the answer is the same in every registration order. A restore into a row bound to no package, to the shipper, to the shipper's customization pair or to a package that shares the shipper's set of the name is refused exactly as before.

A delete of `hr`'s own `N` already succeeded, but its receipt said an overlay was deleted and `N` was reset to its artifact default. `hr` ships no `N`, so the receipt now says the set was deleted and no longer exists. A delete naming `hr` when `hr` holds no `N` answers "nothing to delete" in place of "already at artifact default". The receipts for a customization of a shipped set are unchanged.

Nothing to migrate.
14 changes: 11 additions & 3 deletions packages/metadata-protocol/src/protocol-class-head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import type { IObjectQLEngine, IPubSub } from '@objectstack/spec/contracts';
import { isPairOf } from '@objectstack/metadata-core';
import { installedManifestsOfEngine } from './installed-manifests.js';
import { someShipperOf } from './protocol-environment-rows.js';
import { overrideWriteRefusalError } from './protocol-packaged-base-refusal.js';
import { isOwnPermissionSetWrite, overrideWriteRefusalError } from './protocol-packaged-base-refusal.js';
import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js';
import type { ObjectExtensionRegistry } from './protocol-object-extension-item.js';
import { canonicalMetaType } from './protocol-meta-type-schema.js';
Expand Down Expand Up @@ -201,19 +201,27 @@ export class ProtocolClassHeadFacet {
* `deriveRestoredBody`, so nothing is written. Any other binding: the
* caller's `artifactBacked` decides the intent, and the body writer is
* {@link restoredBodyWriter}'s alone.
*
* [ADR-0150 D2, #34401] A restore into a package's OWN permission set,
* beside sets other namespaces' packages ship, overrides no shipped set,
* so the name-wide `artifactBacked` is narrowed by the verdict the save,
* publish and undo doors read ({@link isOwnPermissionSetWrite}): the
* store is told a runtime-only write, as that package's save is. Every
* restore that does override a shipped set keeps the intent it had.
*/
static restoreWriteFor(host: Pick<ProtocolHost, 'engine' | 'overrideWriteVerdict' | 'packagedArtifactOwner' | 'restoredBodyWriter' | 'shippedArtifactsOf'>, singularType: string,
name: string,
binding: string | null,
artifactBacked: boolean,
source: string,): { intent: 'override-artifact' | 'runtime-only'; deriveRestoredBody: (historyBody: unknown) => Promise<unknown> } {
const overridesShipped = artifactBacked && !isOwnPermissionSetWrite(host.engine, singularType, name, binding);
// [ADR-0150 D4, #32552] The binding is judged against every package
// that ships the name ({@link someShipperOf}): each namespace's holder
// has its own pair, never only the shipper registered first.
const installed = installedManifestsOfEngine(host.engine);
const pairRow = artifactBacked && someShipperOf(host, singularType, name,
const pairRow = overridesShipped && someShipperOf(host, singularType, name,
(owner) => owner !== undefined && isPairOf(binding, owner, installed));
const intent: 'override-artifact' | 'runtime-only' = artifactBacked && !pairRow ? 'override-artifact' : 'runtime-only';
const intent: 'override-artifact' | 'runtime-only' = overridesShipped && !pairRow ? 'override-artifact' : 'runtime-only';
const writeRestored = host.restoredBodyWriter(singularType, name, binding, source);
const deriveRestoredBody = pairRow
? async (historyBody: unknown): Promise<unknown> => {
Expand Down
13 changes: 10 additions & 3 deletions packages/metadata-protocol/src/protocol-diff-delete-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import type { ServedOverrideRow } from './served-override.js';
import { REFERENCE_SITES } from './reference-sites.js';
import { computeMetadataDiagnostics } from './metadata-diagnostics.js';
import { hasMetadataRedactor, redactMetadataItem } from './metadata-redaction.js';
import { isPairRowRemoval } from './protocol-packaged-base-refusal.js';
import { isOwnPermissionSetWrite, isPairRowRemoval } from './protocol-packaged-base-refusal.js';
import { canonicalMetaType, canonicalizeMetaRequestType } from './protocol-meta-type-schema.js';
import { boundPackageOf, servesSealedOverrideRow } from './protocol-package-bindings.js';
import { remainingRowsPhrase } from './protocol-authoring-refusals.js';
Expand Down Expand Up @@ -750,6 +750,13 @@ export class ProtocolDiffDeleteLoadFacet {
}
const packageId: string | null = request.packageId
?? (draftAddress !== undefined ? draftAddress.key : rowsAtAddress.packageId);
// [ADR-0150 D2, #34401] Whether a code-shipped item sits under
// THIS address, which the two receipts below claim: a package's
// own permission set beside sets other namespaces' packages ship
// has none ({@link isOwnPermissionSetWrite}, the verdict its save
// reads), so removing it removes the set, never resets one.
const shippedUnderAddress = artifactBacked
&& !isOwnPermissionSetWrite(host.engine, singularTypeForRepo, request.name, packageId);
// Probe first — "no overlay exists" is a success/no-op, not
// a conflict. The repo would otherwise throw ConflictError.
const current = await repo.get(ref, { state: targetState, packageId, ...memberOption(member) });
Expand Down Expand Up @@ -817,7 +824,7 @@ export class ProtocolDiffDeleteLoadFacet {
// unchanged, verbatim.
message: targetState === 'draft'
? `No pending draft for ${request.type}/${request.name}.`
: artifactBacked
: shippedUnderAddress
? `No customization overlay found for ${request.type}/${request.name} — already at artifact default.`
: `No ${singularTypeForRepo} '${request.name}' found — nothing to delete.`,
};
Expand Down Expand Up @@ -1005,7 +1012,7 @@ export class ProtocolDiffDeleteLoadFacet {
// discard reads byte for byte as before.
message: (request.state === 'draft')
? `Draft discarded${deletedPackage} — ${request.type}/${request.name}. [seq=${result.seq}]`
: artifactBacked
: shippedUnderAddress
? (remains
? `Customization overlay deleted${deletedPackage} — ${request.type}/${request.name} still carries another overlay: ${remainingRowsPhrase(remainingPackages, unboundRemains, 'row')}. [seq=${result.seq}]`
: `Customization overlay deleted${deletedPackage} — ${request.type}/${request.name} reset to artifact default. [seq=${result.seq}]`)
Expand Down
Loading
Loading