Skip to content

Commit

Permalink
don't allow empty bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Jun 9, 2017
1 parent f13836a commit 484a32f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions flows/actions/call_webhook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actions

import (
"fmt"
"net/http"
"strings"

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions flows/actions/send_email.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package actions

import (
"fmt"

"github.com/nyaruka/goflow/excellent"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion flows/actions/send_msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package actions

import (
"fmt"

"github.com/nyaruka/goflow/excellent"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion flows/events/msg_received.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flows/events/save_contact_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flows/events/save_flow_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
2 changes: 1 addition & 1 deletion flows/events/send_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flows/events/update_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 484a32f

Please sign in to comment.