diff --git a/automation/service/trigger.go b/automation/service/trigger.go index 5583977b7..a932b4c03 100644 --- a/automation/service/trigger.go +++ b/automation/service/trigger.go @@ -616,12 +616,24 @@ func (svc *trigger) unregisterTriggers(tt ...*types.Trigger) { } } -func loadTrigger(ctx context.Context, s store.Storer, workflowID uint64) (res *types.Trigger, err error) { +func loadTrigger(ctx context.Context, s store.Storer, triggerID uint64) (res *types.Trigger, err error) { + if triggerID == 0 { + return nil, TriggerErrInvalidID() + } + + if res, err = store.LookupAutomationTriggerByID(ctx, s, triggerID); errors.IsNotFound(err) { + return nil, TriggerErrNotFound() + } + + return +} + +func loadWorkflowTriggers(ctx context.Context, s store.Storer, workflowID uint64) (tt types.TriggerSet, err error) { if workflowID == 0 { return nil, TriggerErrInvalidID() } - if res, err = store.LookupAutomationTriggerByID(ctx, s, workflowID); errors.IsNotFound(err) { + if tt, _, err = store.SearchAutomationTriggers(ctx, s, types.TriggerFilter{WorkflowID: []uint64{workflowID}}); errors.IsNotFound(err) { return nil, TriggerErrNotFound() } diff --git a/automation/service/workflow.go b/automation/service/workflow.go index 127a44b5f..dc852151a 100644 --- a/automation/service/workflow.go +++ b/automation/service/workflow.go @@ -521,7 +521,9 @@ func (svc *workflow) Exec(ctx context.Context, workflowID uint64, p types.Workfl // Find the trigger. t, err = func() (*types.Trigger, error) { var tt types.TriggerSet - tt, _, err = svc.triggers.Search(ctx, types.TriggerFilter{WorkflowID: []uint64{workflowID}}) + // Load triggers directly from the store. At this point we do not care + // about trigger search or read permissions + tt, err = loadWorkflowTriggers(ctx, svc.store, workflowID) if err != nil { return nil, err } @@ -539,6 +541,10 @@ func (svc *workflow) Exec(ctx context.Context, workflowID uint64, p types.Workfl return nil, nil }() + if err != nil { + return + } + // Start with workflow scope scope := wf.Scope.MustMerge()