Skip to content

[Gap]: Store: an approved record's owner can still edit or delete it (no state-gated edits) #952

Closed

Description

@jimhoyd

From the third agent workflow trial (approval workflow task).

What you were trying to do

An approval workflow on the store, YAML only: requesters own requests (title, amount, status); submit/withdraw owner transitions; approve/reject as by: others transitions gated by a reviewers membership, stamping reviewedBy/reviewedAt.

Where it broke down

After a reviewer approves a request, its owner can still change what was approved, or delete it:

  • PATCH /api/requests/<id> with {"amount":99999} on the approved record answers 200. The record keeps status: approved and reviewedBy: rita, so the approval now vouches for an amount nobody reviewed.
  • DELETE /api/requests/<id> on the approved record answers 204, erasing the decision.
  • The same holds while it is pending: the owner can edit it under the reviewer.

There seems to be no declaration for "these properties are writable only in these states". readOnlyProperties does not help: a create stores only the default for a read-only property, so title/amount could not be entered at all. A transition's set takes constants only. docs search "immutable after create lock fields while pending" and "writable only in state" found nothing relevant.

Expected: a declarative way to freeze a record (or listed properties), and to refuse its DELETE, outside declared states. For example editableWhen: {status: draft} / deletableWhen: {status: draft}, answered with 409 like transition_conflict.

Code or YAML you had to write by hand

None: the app ships with the gap. The collection (abridged):

requests:
  mount: /api/requests
  ownership: owner
  schema:
    type: object
    additionalProperties: false
    required: [title, amount, status]
    properties:
      title: {type: string, minLength: 1, maxLength: 120}
      amount: {type: integer, minimum: 1, maximum: 100000}
      status: {type: string, enum: [draft, pending, approved, rejected]}
      reviewedBy: {type: string, maxLength: 128}
      reviewedAt: {type: string, maxLength: 32}
  defaults: {status: draft}
  readOnlyProperties: [status, reviewedBy, reviewedAt]
  readers: {mount: /api/queue, members: reviewers, showOwner: true}
  transitions:
    submit: {from: {status: draft}, set: {status: pending}}
    withdraw: {from: {status: pending}, set: {status: draft}}
    approve: {from: {status: pending}, set: {status: approved}, stamp: {reviewedBy: actor, reviewedAt: now}, by: others, mount: /api/approve, members: reviewers}
    reject: {from: {status: pending}, set: {status: rejected}, stamp: {reviewedBy: actor, reviewedAt: now}, by: others, mount: /api/reject, members: reviewers}

Probe steps, after alice's r1 was approved by rita and alice signed in again:

{"path": "/api/requests/{{r1}}", "method": "PATCH", "headers": {"origin": "{{origin}}", "content-type": "application/json"}, "body": "{\"amount\":99999}", "status": 409},
{"path": "/api/requests/{{r1}}", "method": "DELETE", "headers": {"origin": "{{origin}}"}, "status": 409}

Output (npm test):

{"event":"test","case":33,"pass":false,"method":"PATCH","path":"/api/requests/a6559cd9-…","fixturePath":"/api/requests/{{r1}}","status":200,"failures":[{"check":"status","expected":409,"actual":200,"body":"{\"id\":\"a6559cd9-…\",…,\"title\":\"Laptop\",\"amount\":99999,\"status\":\"approved\",\"reviewedBy\":\"rita\",\"revi... (235 characters)"}]}
{"event":"test","case":34,"pass":false,"method":"DELETE","path":"/api/requests/ffc349a7-…","fixturePath":"/api/requests/{{r1}}","status":204,"failures":[{"check":"status","expected":409,"actual":204}]}

What you could not verify

Whether If-Match on the approve call is meant as the whole answer for the pending case. It protects the reviewer from approving a changed version, but it doesn't stop edits after approval. An audit log (audit: true) would record the edit but not prevent it; not tried.

Runtime revision and environment

main f850492a (0.6.5). Core and add-ons packed with scripts/pack-addons.ts, a fresh urlcode init site with extensions add auth store, macOS, Node 26.10.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-first

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions