fix(db): publish gate fires only on transition into public, not re-set

Preserves the documented set-to-current idempotent no-op: re-setting an
already-public object's visibility no longer rejects when a required field
was introduced after publish. Adds a regression test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 23:40:10 +02:00
parent e96f74f47a
commit 8cfcf07387
2 changed files with 51 additions and 3 deletions
+4 -3
View File
@@ -370,10 +370,11 @@ pub async fn set_visibility(
let new_visibility = object.visibility.transition_to(target)?;
// The publish gate: a record may only become public once every required field
// The publish gate: a record may only *become* public once every required field
// has a value. The typed inventory-minimum columns are already NOT NULL, so only
// the flexible required fields need checking here.
if new_visibility == Visibility::Public {
// the flexible required fields need checking here. Gated on an actual transition
// into public so a set-to-current no-op stays a no-op (never a late rejection).
if new_visibility == Visibility::Public && object.visibility != Visibility::Public {
let missing = missing_required_fields(&mut *conn, &object.fields).await?;
if !missing.is_empty() {