- pact.RecordSaved/RecordDeleted/RecordChange, fired as pointers after commit - pact.ContentDescriptor and request/result types; MenuItemType.Content - AdminFormSave.Changes carries the owner's changes to extension Save - cabana.EmitRecordSaved/EmitRecordDeleted; admin save snapshots columns and translated values and fires RecordSaved through lagoon.AfterCommit - signpost validates Content and gains ContentTypes, ContentTypeForModel, Describe
55 lines
2.3 KiB
Go
55 lines
2.3 KiB
Go
package pact
|
|
|
|
// RecordChange is one changed attribute of a saved record. Attribute is the
|
|
// column or form field name. Locale is "" for a value stored on the record's
|
|
// own row, and the locale code for a translated value stored elsewhere (a
|
|
// translatable field's non-default locales); a translated slug therefore
|
|
// appears once per changed locale. Old is nil on create and for a
|
|
// translation that did not exist before; New is the value after the save.
|
|
// Values are as the model holds them (string, number, bool, *time.Time and
|
|
// so on), not formatted.
|
|
type RecordChange struct {
|
|
Attribute string
|
|
Locale string
|
|
Old any
|
|
New any
|
|
}
|
|
|
|
// RecordSaved is fired through the application's event bus (app.Events)
|
|
// after a record is created or updated, once the write has committed: a
|
|
// rolled-back save fires nothing. It is fired and listened to as a pointer:
|
|
//
|
|
// app.Events.Listen("acme.audit", func(ctx context.Context, ev *pact.RecordSaved) error { ... })
|
|
//
|
|
// The admin framework fires it for every admin write; plugin code that
|
|
// writes records directly fires it through cabana.EmitRecordSaved. A
|
|
// listener's error is logged and never fails the write that caused it.
|
|
//
|
|
// Controller is the ID of the admin controller that saved the record, ""
|
|
// for a write outside the admin forms. Model is the record's morph type
|
|
// (lagoon.MorphType: the model's MorphName, else its table name), the same
|
|
// value a content type declares in ContentDescriptor.Model. ID is the
|
|
// primary key as text. Locale is the request's content locale, "" when it
|
|
// has none. Created is true on create. Changes lists the attributes the save
|
|
// changed with their old and new values; on create it lists every written
|
|
// column with a nil Old. A save that changed nothing still fires, with an
|
|
// empty Changes, so subscribers may re-check what they derive from the
|
|
// record.
|
|
type RecordSaved struct {
|
|
Controller string
|
|
Model string
|
|
ID string
|
|
Locale string
|
|
Created bool
|
|
Changes []RecordChange
|
|
}
|
|
|
|
// RecordDeleted is fired like RecordSaved after a record is deleted and the
|
|
// delete has committed, once per record (a bulk delete fires one event per
|
|
// row). Controller, Model and ID follow RecordSaved.
|
|
type RecordDeleted struct {
|
|
Controller string
|
|
Model string
|
|
ID string
|
|
}
|