From 47fca9be92b001a81ec034ba0af1368a1be31123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Thu, 23 Apr 2020 14:48:43 +0200 Subject: [PATCH] Add value formatting to record create/update steps --- compose/service/record.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/compose/service/record.go b/compose/service/record.go index c898380d7..fd9fe8a04 100644 --- a/compose/service/record.go +++ b/compose/service/record.go @@ -374,6 +374,7 @@ func (svc record) Create(new *types.Record) (rec *types.Record, err error) { return rve } + new.Values = svc.formatter.Run(m, new.Values) if err = svc.eventbus.WaitFor(svc.ctx, event.RecordBeforeCreate(new, nil, m, ns, rve)); err != nil { return } else if !rve.IsValid() { @@ -399,7 +400,10 @@ func (svc record) Create(new *types.Record) (rec *types.Record, err error) { // At this point we can return the value rec = new - defer svc.eventbus.Dispatch(svc.ctx, event.RecordAfterCreateImmutable(new, nil, m, ns, nil)) + defer func() { + new.Values = svc.formatter.Run(m, new.Values) + svc.eventbus.Dispatch(svc.ctx, event.RecordAfterCreateImmutable(new, nil, m, ns, nil)) + }() return }) } @@ -487,6 +491,9 @@ func (svc record) Update(upd *types.Record) (rec *types.Record, err error) { // to be sent to handler upd.Values = upd.Values.GetClean() + // Before we pass values to automation scripts, they should be formatted + upd.Values = svc.formatter.Run(m, upd.Values) + // Scripts can (besides simple error value) return complex record value error set // that is passed back to the UI or any other API consumer // @@ -518,7 +525,11 @@ func (svc record) Update(upd *types.Record) (rec *types.Record, err error) { // At this point we can return the value rec = upd - defer svc.eventbus.Dispatch(svc.ctx, event.RecordAfterUpdateImmutable(upd, old, m, ns, nil)) + defer func() { + // Before we pass values to automation scripts, they should be formatted + upd.Values = svc.formatter.Run(m, upd.Values) + svc.eventbus.Dispatch(svc.ctx, event.RecordAfterUpdateImmutable(upd, old, m, ns, nil)) + }() return }) }