From 484a32fbfd571f2825572a414dda06e9311755bc Mon Sep 17 00:00:00 2001 From: Nic Pottier Date: Fri, 9 Jun 2017 14:35:55 -0500 Subject: [PATCH] don't allow empty bodies --- flows/actions/call_webhook.go | 5 +++++ flows/actions/send_email.go | 10 ++++++++++ flows/actions/send_msg.go | 8 +++++++- flows/events/msg_received.go | 2 +- flows/events/save_contact_field.go | 2 +- flows/events/save_flow_result.go | 2 +- flows/events/send_email.go | 2 +- flows/events/update_contact.go | 2 +- 8 files changed, 27 insertions(+), 6 deletions(-) diff --git a/flows/actions/call_webhook.go b/flows/actions/call_webhook.go index 74de82023..1d262aa22 100644 --- a/flows/actions/call_webhook.go +++ b/flows/actions/call_webhook.go @@ -1,6 +1,7 @@ package actions import ( + "fmt" "net/http" "strings" @@ -54,6 +55,10 @@ func (a *WebhookAction) Execute(run flows.FlowRun, step flows.Step) error { if err != nil { run.AddError(step, err) } + if url == "" { + run.AddError(step, fmt.Errorf("call_webhook URL evaluated to empty string, skipping")) + return nil + } // substitute any body variables body := a.Body diff --git a/flows/actions/send_email.go b/flows/actions/send_email.go index e21710103..a68c5774c 100644 --- a/flows/actions/send_email.go +++ b/flows/actions/send_email.go @@ -1,6 +1,8 @@ package actions import ( + "fmt" + "github.com/nyaruka/goflow/excellent" "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/events" @@ -47,11 +49,19 @@ func (a *EmailAction) Execute(run flows.FlowRun, step flows.Step) error { if err != nil { run.AddError(step, err) } + if email == "" { + run.AddError(step, fmt.Errorf("send_email email evaluated to empty string, skipping")) + continue + } subject, err := excellent.EvaluateTemplateAsString(run.Environment(), run.Context(), a.Subject) if err != nil { run.AddError(step, err) } + if subject == "" { + run.AddError(step, fmt.Errorf("send_email subject evaluated to empty string, skipping")) + continue + } body, err := excellent.EvaluateTemplateAsString(run.Environment(), run.Context(), a.Body) if err != nil { diff --git a/flows/actions/send_msg.go b/flows/actions/send_msg.go index 5401ab93f..984326265 100644 --- a/flows/actions/send_msg.go +++ b/flows/actions/send_msg.go @@ -1,6 +1,8 @@ package actions import ( + "fmt" + "github.com/nyaruka/goflow/excellent" "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/events" @@ -31,7 +33,7 @@ type SendMsgAction struct { URNs []flows.URN `json:"urns"` Contacts []*flows.ContactReference `json:"contacts" validate:"dive"` Groups []*flows.Group `json:"groups" validate:"dive"` - Text string `json:"text" validate:"required"` + Text string `json:"text"` } // Type returns the type of this action @@ -49,6 +51,10 @@ func (a *SendMsgAction) Execute(run flows.FlowRun, step flows.Step) error { if err != nil { run.AddError(step, err) } + if text == "" { + run.AddError(step, fmt.Errorf("send_msg text evaluated to empty string, skipping")) + return nil + } // create events for each URN for _, urn := range a.URNs { diff --git a/flows/events/msg_received.go b/flows/events/msg_received.go index 70c3ac1ed..2740b74ae 100644 --- a/flows/events/msg_received.go +++ b/flows/events/msg_received.go @@ -31,7 +31,7 @@ type MsgReceivedEvent struct { ChannelUUID flows.ChannelUUID `json:"channel_uuid" validate:"required,uuid4"` URN flows.URN `json:"urn" validate:"required"` ContactUUID flows.ContactUUID `json:"contact_uuid" validate:"required,uuid4"` - Text string `json:"text" validate:"required"` + Text string `json:"text"` } // NewMsgReceivedEvent creates a new incoming msg event for the passed in channel, contact and string diff --git a/flows/events/save_contact_field.go b/flows/events/save_contact_field.go index e6d0f248a..2543351db 100644 --- a/flows/events/save_contact_field.go +++ b/flows/events/save_contact_field.go @@ -23,7 +23,7 @@ type SaveContactFieldEvent struct { BaseEvent FieldUUID flows.FieldUUID `json:"field_uuid" validate:"required"` FieldName string `json:"field_name" validate:"required"` - Value string `json:"value" validate:"required"` + Value string `json:"value"` } // NewSaveToContact returns a new save to contact event diff --git a/flows/events/save_flow_result.go b/flows/events/save_flow_result.go index f5f56239e..a6e588c7c 100644 --- a/flows/events/save_flow_result.go +++ b/flows/events/save_flow_result.go @@ -26,7 +26,7 @@ type SaveFlowResultEvent struct { BaseEvent NodeUUID flows.NodeUUID `json:"node_uuid" validate:"required"` ResultName string `json:"result_name" validate:"required"` - Value string `json:"value" validate:"required"` + Value string `json:"value"` Category string `json:"category"` } diff --git a/flows/events/send_email.go b/flows/events/send_email.go index bd523713c..b3d9c3e1e 100644 --- a/flows/events/send_email.go +++ b/flows/events/send_email.go @@ -21,7 +21,7 @@ type SendEmailEvent struct { BaseEvent Email string `json:"email" validate:"required"` Subject string `json:"subject" validate:"required"` - Body string `json:"body" validate:"required"` + Body string `json:"body"` } // NewSendEmailEvent returns a new email event witht he passed in subject, body and emails diff --git a/flows/events/update_contact.go b/flows/events/update_contact.go index 72d04fcc8..518cf88e0 100644 --- a/flows/events/update_contact.go +++ b/flows/events/update_contact.go @@ -19,7 +19,7 @@ const TypeUpdateContact string = "update_contact" type UpdateContactEvent struct { BaseEvent FieldName string `json:"field_name" validate:"required"` - Value string `json:"value" validate:"required"` + Value string `json:"value"` } // NewUpdateContact returns a new save to contact event