feat(32-01): cross-plugin admin form extensions (tracer)

- pact.AdminActionExtension.Form with AdminFormExtension: a fields
  document (fields.yaml format plus before:/after:/zone: and a tabs:
  list) given as an AdminFS path or YAML bytes, Load and Save hooks,
  AdminFormLoad/Save/SaveResult, AdminFormErrors and zone constants
- cabana compileFormExtensions places extension fields at owner
  anchors at boot, regrouping an extended form by tab
- save lifts extension values before any owner path and runs Save in
  the record's transaction after the owner row; show merges Load
- TestFormExtensionTracer: c after a on a, b gives a, c, b through the
  admin API, stored in the contributor's table
This commit is contained in:
2026-10-26 21:46:43 +01:00
parent 9868838fe3
commit 0819442634
8 changed files with 1150 additions and 6 deletions

View File

@@ -252,6 +252,11 @@ func BindWritableFields(cc *CompiledController) error {
if !valueFormField(field) || protectedFillKey(field.Name) || cc.virtual[field.Name] {
continue
}
// A form extension's field is never a column of the owner's model
// (D-91): its extension loads and saves it.
if cc.extensionOf(field.Name) != nil {
continue
}
if _, known := cols[field.Name]; !known {
return errors.New("cabana: controller " + id + ": field " + field.Name + " is not a model column")
}
@@ -533,6 +538,9 @@ func (s CRUDService) ShowRecord(ctx context.Context, cc *CompiledController, id
if err := hydratePluginFields(ctx, tx, cc, s.writer, target, result.Data, "update"); err != nil {
return err
}
if err := hydrateFormExtensions(withTx(ctx, tx), tx, cc, target, result.Data, "update"); err != nil {
return err
}
result.Meta.Actions, err = s.offeredRecordActions(withTx(ctx, tx), cc, target)
return err
})
@@ -747,6 +755,9 @@ func (s CRUDService) save(ctx context.Context, cc *CompiledController, id any, i
if update {
op = "update"
}
// D-91: form extension values leave the body first, so no owner path
// (Fill, bindings, translations, attachments) ever reads them.
extensions := liftExtensionValues(cc, in.Body, op)
// Writable relation keys are lifted before scalar projection (which drops
// every nested value); only keys present in the body are applied.
relations, err := liftRelationValues(cc, in.Body, op)
@@ -925,6 +936,13 @@ func (s CRUDService) save(ctx context.Context, cc *CompiledController, id any, i
if err != nil {
return err
}
// D-91: form extensions save their own values in this transaction,
// after the owner row is written; an error rolls everything back.
extNotices, err := saveFormExtensions(ctx, tx, cc, target, extensions, !update)
if err != nil {
return err
}
notices = append(notices, extNotices...)
result, err = projectFullRecord(ctx, tx, cc, target)
if err != nil {
return err
@@ -932,7 +950,10 @@ func (s CRUDService) save(ctx context.Context, cc *CompiledController, id any, i
if err := hydrateMLRecord(ctx, tx, cc, s.writer, target, result.Data, op); err != nil {
return err
}
return hydratePluginFields(ctx, tx, cc, s.writer, target, result.Data, op)
if err := hydratePluginFields(ctx, tx, cc, s.writer, target, result.Data, op); err != nil {
return err
}
return hydrateFormExtensions(ctx, tx, cc, target, result.Data, op)
})
if err != nil {
return RecordResult{}, err