Keep ref to module on compose record
This commit is contained in:
@@ -214,6 +214,8 @@ func (svc record) lookup(ctx context.Context, namespaceID, moduleID uint64, look
|
||||
return err
|
||||
}
|
||||
|
||||
r.SetModule(m)
|
||||
|
||||
return nil
|
||||
}()
|
||||
|
||||
@@ -296,6 +298,11 @@ func (svc record) Find(ctx context.Context, filter types.RecordFilter) (set type
|
||||
return err
|
||||
}
|
||||
|
||||
_ = set.Walk(func(r *types.Record) error {
|
||||
r.SetModule(m)
|
||||
return nil
|
||||
})
|
||||
|
||||
trimUnreadableRecordFields(ctx, svc.ac, m, set...)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -3,10 +3,6 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/actionlog"
|
||||
"github.com/cortezaproject/corteza-server/pkg/corredor"
|
||||
@@ -14,6 +10,7 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza-server/pkg/healthcheck"
|
||||
"github.com/cortezaproject/corteza-server/pkg/id"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/objstore"
|
||||
"github.com/cortezaproject/corteza-server/pkg/objstore/minio"
|
||||
"github.com/cortezaproject/corteza-server/pkg/objstore/plain"
|
||||
@@ -21,6 +18,8 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/rbac"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"go.uber.org/zap"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -48,12 +48,14 @@ func Expression(ctx context.Context, m *types.Module, r *types.Record, old *type
|
||||
scope = r.Values.Dict(m.Fields)
|
||||
|
||||
// new record
|
||||
scope["new"] = r.Dict(m)
|
||||
r.SetModule(m)
|
||||
scope["new"] = r.Dict()
|
||||
|
||||
if old != nil {
|
||||
// old values on record (before update)
|
||||
// this will not be set for new records
|
||||
scope["old"] = old.Dict(m)
|
||||
old.SetModule(m)
|
||||
scope["old"] = old.Dict()
|
||||
}
|
||||
|
||||
for _, f := range m.Fields {
|
||||
@@ -104,6 +106,7 @@ func Expression(ctx context.Context, m *types.Module, r *types.Record, old *type
|
||||
}
|
||||
|
||||
// Reset $new with updated data
|
||||
scope["new"] = r.Dict(m)
|
||||
r.SetModule(m)
|
||||
scope["new"] = r.Dict()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ type (
|
||||
ID uint64 `json:"recordID,string"`
|
||||
ModuleID uint64 `json:"moduleID,string"`
|
||||
|
||||
module *Module
|
||||
|
||||
Values RecordValueSet `json:"values,omitempty"`
|
||||
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
@@ -97,6 +99,15 @@ loop:
|
||||
return
|
||||
}
|
||||
|
||||
// Sets/updates module ptr
|
||||
//
|
||||
// Only if not previously set and if matches record specs
|
||||
func (r *Record) SetModule(m *Module) {
|
||||
if (r.module == nil || r.module.ID == m.ID) && r.ModuleID == m.ID {
|
||||
r.module = m
|
||||
}
|
||||
}
|
||||
|
||||
func (r Record) Clone() *Record {
|
||||
c := &r
|
||||
c.Values = r.Values.Clone()
|
||||
@@ -118,11 +129,10 @@ func (r Record) DynamicRoles(userID uint64) []uint64 {
|
||||
)
|
||||
}
|
||||
|
||||
func (r Record) Dict(m *Module) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
func (r Record) Dict() map[string]interface{} {
|
||||
dict := map[string]interface{}{
|
||||
"ID": r.ID,
|
||||
"moduleID": r.ModuleID,
|
||||
"values": r.Values.Dict(m.Fields),
|
||||
"labels": r.Labels,
|
||||
"namespaceID": r.NamespaceID,
|
||||
"ownedBy": r.OwnedBy,
|
||||
@@ -133,6 +143,12 @@ func (r Record) Dict(m *Module) map[string]interface{} {
|
||||
"deletedAt": r.DeletedAt,
|
||||
"deletedBy": r.DeletedBy,
|
||||
}
|
||||
|
||||
if r.module != nil {
|
||||
dict["values"] = r.Values.Dict(r.module.Fields)
|
||||
}
|
||||
|
||||
return dict
|
||||
}
|
||||
|
||||
// UnmarshalJSON for custom record deserialization
|
||||
|
||||
Reference in New Issue
Block a user