Improve onManual trigger for all resources
This commit is contained in:
parent
1e096d1abc
commit
ded83ff5db
@ -1035,6 +1035,12 @@
|
||||
"type": "string",
|
||||
"title": "Script to execute",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "types.RecordValueSet",
|
||||
"name": "values",
|
||||
"required": true,
|
||||
"title": "Record values"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -333,6 +333,12 @@
|
||||
"required": true,
|
||||
"title": "Script to execute",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "values",
|
||||
"required": true,
|
||||
"title": "Record values",
|
||||
"type": "types.RecordValueSet"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -150,7 +150,9 @@ func (ctrl *Module) TriggerScript(ctx context.Context, r *request.ModuleTriggerS
|
||||
return
|
||||
}
|
||||
|
||||
return resputil.OK(), corredor.Service().ExecOnManual(ctx, r.Script, event.ModuleOnManual(module, nil, namespace))
|
||||
// @todo implement same behaviour as we have on record - module+oldModule
|
||||
err = corredor.Service().ExecOnManual(ctx, r.Script, event.ModuleOnManual(module, module, namespace))
|
||||
return ctrl.makePayload(ctx, module, err)
|
||||
}
|
||||
|
||||
func (ctrl Module) makePayload(ctx context.Context, m *types.Module, err error) (*modulePayload, error) {
|
||||
|
||||
@ -133,7 +133,8 @@ func (ctrl *Namespace) TriggerScript(ctx context.Context, r *request.NamespaceTr
|
||||
return
|
||||
}
|
||||
|
||||
return resputil.OK(), corredor.Service().ExecOnManual(ctx, r.Script, event.NamespaceOnManual(namespace, nil))
|
||||
err = corredor.Service().ExecOnManual(ctx, r.Script, event.NamespaceOnManual(namespace, nil))
|
||||
return ctrl.makePayload(ctx, namespace, err)
|
||||
}
|
||||
|
||||
func (ctrl Namespace) makePayload(ctx context.Context, ns *types.Namespace, err error) (*namespacePayload, error) {
|
||||
|
||||
@ -170,7 +170,9 @@ func (ctrl *Page) TriggerScript(ctx context.Context, r *request.PageTriggerScrip
|
||||
return
|
||||
}
|
||||
|
||||
return resputil.OK(), corredor.Service().ExecOnManual(ctx, r.Script, event.PageOnManual(page, nil, namespace))
|
||||
// @todo implement same behaviour as we have on record - page+oldPage
|
||||
err = corredor.Service().ExecOnManual(ctx, r.Script, event.PageOnManual(page, page, namespace))
|
||||
return ctrl.makePayload(ctx, page, err)
|
||||
}
|
||||
|
||||
func (ctrl Page) makePayload(ctx context.Context, c *types.Page, err error) (*pagePayload, error) {
|
||||
|
||||
@ -379,11 +379,12 @@ func (ctrl Record) Exec(ctx context.Context, r *request.RecordExec) (interface{}
|
||||
func (ctrl *Record) TriggerScript(ctx context.Context, r *request.RecordTriggerScript) (rsp interface{}, err error) {
|
||||
var (
|
||||
record *types.Record
|
||||
oldRecord *types.Record
|
||||
module *types.Module
|
||||
namespace *types.Namespace
|
||||
)
|
||||
|
||||
if record, err = ctrl.record.With(ctx).FindByID(r.NamespaceID, r.RecordID); err != nil {
|
||||
if oldRecord, err = ctrl.record.With(ctx).FindByID(r.NamespaceID, r.RecordID); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -395,15 +396,13 @@ func (ctrl *Record) TriggerScript(ctx context.Context, r *request.RecordTriggerS
|
||||
return
|
||||
}
|
||||
|
||||
record = oldRecord
|
||||
record.Values = r.Values
|
||||
|
||||
err = corredor.Service().ExecOnManual(
|
||||
ctx,
|
||||
r.Script,
|
||||
event.RecordOnManual(
|
||||
record,
|
||||
nil,
|
||||
module,
|
||||
namespace,
|
||||
),
|
||||
event.RecordOnManual(record, oldRecord, module, namespace),
|
||||
)
|
||||
|
||||
// Script can return modified record and we'll pass it on to the caller
|
||||
|
||||
@ -801,6 +801,7 @@ type RecordTriggerScript struct {
|
||||
NamespaceID uint64 `json:",string"`
|
||||
ModuleID uint64 `json:",string"`
|
||||
Script string
|
||||
Values types.RecordValueSet
|
||||
}
|
||||
|
||||
func NewRecordTriggerScript() *RecordTriggerScript {
|
||||
@ -814,6 +815,7 @@ func (r RecordTriggerScript) Auditable() map[string]interface{} {
|
||||
out["namespaceID"] = r.NamespaceID
|
||||
out["moduleID"] = r.ModuleID
|
||||
out["script"] = r.Script
|
||||
out["values"] = r.Values
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
@ -1028,6 +1028,7 @@ Compose records
|
||||
| namespaceID | uint64 | PATH | Namespace ID | N/A | YES |
|
||||
| moduleID | uint64 | PATH | Module ID | N/A | YES |
|
||||
| script | string | POST | Script to execute | N/A | YES |
|
||||
| values | types.RecordValueSet | POST | Record values | N/A | YES |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -129,7 +129,9 @@ func (ctrl *Application) TriggerScript(ctx context.Context, r *request.Applicati
|
||||
return
|
||||
}
|
||||
|
||||
return resputil.OK(), corredor.Service().ExecOnManual(ctx, r.Script, event.ApplicationOnManual(application, nil))
|
||||
// @todo implement same behaviour as we have on record - Application+oldApplication
|
||||
err = corredor.Service().ExecOnManual(ctx, r.Script, event.ApplicationOnManual(application, application))
|
||||
return application, err
|
||||
}
|
||||
|
||||
func (ctrl Application) makePayload(ctx context.Context, m *types.Application, err error) (*applicationPayload, error) {
|
||||
|
||||
@ -185,7 +185,9 @@ func (ctrl *Role) TriggerScript(ctx context.Context, r *request.RoleTriggerScrip
|
||||
return
|
||||
}
|
||||
|
||||
return resputil.OK(), corredor.Service().ExecOnManual(ctx, r.Script, event.RoleOnManual(role, nil))
|
||||
// @todo implement same behaviour as we have on record - role+oldRole
|
||||
err = corredor.Service().ExecOnManual(ctx, r.Script, event.RoleOnManual(role, role))
|
||||
return role, err
|
||||
}
|
||||
|
||||
func (ctrl Role) makePayload(ctx context.Context, m *types.Role, err error) (*rolePayload, error) {
|
||||
|
||||
@ -141,7 +141,10 @@ func (ctrl *User) TriggerScript(ctx context.Context, r *request.UserTriggerScrip
|
||||
return
|
||||
}
|
||||
|
||||
return resputil.OK(), corredor.Service().ExecOnManual(ctx, r.Script, event.UserOnManual(user, nil))
|
||||
// @todo implement same behaviour as we have on record - user+oldUser
|
||||
err = corredor.Service().ExecOnManual(ctx, r.Script, event.UserOnManual(user, user))
|
||||
return user, err
|
||||
|
||||
}
|
||||
|
||||
func (ctrl User) makeFilterPayload(ctx context.Context, uu types.UserSet, f types.UserFilter, err error) (*userSetPayload, error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user