Skip to content

Commit

Permalink
Merge pull request #1194 from nyaruka/no_more_ticketers
Browse files Browse the repository at this point in the history
Remove ticketers
  • Loading branch information
rowanseymour authored Jan 2, 2024
2 parents 90233b2 + cb23381 commit df93e29
Show file tree
Hide file tree
Showing 43 changed files with 115 additions and 1,174 deletions.
11 changes: 0 additions & 11 deletions assets/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ func TestReferences(t *testing.T) {
assert.False(t, templateRef.Variable())
assert.NoError(t, utils.Validate(templateRef))

ticketerRef := assets.NewTicketerReference("61602f3e-f603-4c70-8a8f-c477505bf4bf", "Support Tickets")
assert.Equal(t, "ticketer", ticketerRef.Type())
assert.Equal(t, "61602f3e-f603-4c70-8a8f-c477505bf4bf", ticketerRef.Identity())
assert.Equal(t, uuids.UUID("61602f3e-f603-4c70-8a8f-c477505bf4bf"), ticketerRef.GenericUUID())
assert.Equal(t, "ticketer[uuid=61602f3e-f603-4c70-8a8f-c477505bf4bf,name=Support Tickets]", ticketerRef.String())
assert.False(t, ticketerRef.Variable())
assert.NoError(t, utils.Validate(ticketerRef))

// ticketer references must always be concrete
assert.EqualError(t, utils.Validate(assets.NewTicketerReference("", "Booking")), "field 'uuid' is required")

topicRef := assets.NewTopicReference("61602f3e-f603-4c70-8a8f-c477505bf4bf", "Weather")
assert.Equal(t, "topic", topicRef.Type())
assert.Equal(t, "61602f3e-f603-4c70-8a8f-c477505bf4bf", topicRef.Identity())
Expand Down
1 change: 0 additions & 1 deletion assets/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Source interface {
OptIns() ([]OptIn, error)
Resthooks() ([]Resthook, error)
Templates() ([]Template, error)
Ticketers() ([]Ticketer, error)
Topics() ([]Topic, error)
Users() ([]User, error)
}
4 changes: 2 additions & 2 deletions assets/static/optin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func NewOptIn(uuid assets.OptInUUID, name string, channel *assets.ChannelReferen
}
}

// UUID returns the UUID of this ticketer
// UUID returns the UUID of this optin
func (t *OptIn) UUID() assets.OptInUUID { return t.UUID_ }

// Name returns the name of this ticketer
// Name returns the name of this optin
func (t *OptIn) Name() string { return t.Name_ }
10 changes: 0 additions & 10 deletions assets/static/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type StaticSource struct {
OptIns []*OptIn `json:"optins" validate:"omitempty,dive"`
Resthooks []*Resthook `json:"resthooks" validate:"omitempty,dive"`
Templates []*Template `json:"templates" validate:"omitempty,dive"`
Ticketers []*Ticketer `json:"ticketers" validate:"omitempty,dive"`
Topics []*Topic `json:"topics" validate:"omitempty,dive"`
Users []*User `json:"users" validate:"omitempty,dive"`
}
Expand Down Expand Up @@ -165,15 +164,6 @@ func (s *StaticSource) Templates() ([]assets.Template, error) {
return set, nil
}

// Ticketers returns all ticketer assets
func (s *StaticSource) Ticketers() ([]assets.Ticketer, error) {
set := make([]assets.Ticketer, len(s.s.Ticketers))
for i := range s.s.Ticketers {
set[i] = s.s.Ticketers[i]
}
return set, nil
}

// Topics returns all topic assets
func (s *StaticSource) Topics() ([]assets.Topic, error) {
set := make([]assets.Topic, len(s.s.Topics))
Expand Down
4 changes: 0 additions & 4 deletions assets/static/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ func TestSource(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, templates, 0)

ticketers, err := src.Ticketers()
assert.NoError(t, err)
assert.Len(t, ticketers, 0)

topics, err := src.Topics()
assert.NoError(t, err)
assert.Len(t, topics, 0)
Expand Down
30 changes: 0 additions & 30 deletions assets/static/ticketer.go

This file was deleted.

21 changes: 0 additions & 21 deletions assets/static/ticketer_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions assets/static/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func NewTopic(uuid assets.TopicUUID, name string) assets.Topic {
}
}

// UUID returns the UUID of this ticketer
// UUID returns the UUID of this topic
func (t *Topic) UUID() assets.TopicUUID { return t.UUID_ }

// Name returns the name of this ticketer
// Name returns the name of this topic
func (t *Topic) Name() string { return t.Name_ }
6 changes: 3 additions & 3 deletions assets/static/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestUser(t *testing.T) {
ticketer := static.NewUser("[email protected]", "Bob")
assert.Equal(t, "[email protected]", ticketer.Email())
assert.Equal(t, "Bob", ticketer.Name())
user := static.NewUser("[email protected]", "Bob")
assert.Equal(t, "[email protected]", user.Email())
assert.Equal(t, "Bob", user.Name())
}
62 changes: 0 additions & 62 deletions assets/ticketer.go

This file was deleted.

12 changes: 1 addition & 11 deletions flows/actions/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/nyaruka/goflow/test"
"github.com/nyaruka/goflow/utils"
"github.com/nyaruka/goflow/utils/smtpx"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -173,9 +172,8 @@ func testActionType(t *testing.T, assetsJSON json.RawMessage, typeName string) {
require.NoError(t, err)

if tc.HasTicket {
ticketer := sa.Ticketers().Get("d605bb96-258d-4097-ad0a-080937db2212")
topic := sa.Topics().Get("0d9a2c56-6fc2-4f27-93c5-a6322e26b740")
contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", ticketer, topic, "Help", "", nil))
contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", topic, "Help", nil))
}

// and switch their language
Expand Down Expand Up @@ -231,9 +229,6 @@ func testActionType(t *testing.T, assetsJSON json.RawMessage, typeName string) {
}
return nil, errors.Errorf("no classification service available for %s", c.Reference())
}).
WithTicketServiceFactory(func(t *flows.Ticketer) (flows.TicketService, error) {
return test.NewTicketService(t), nil
}).
WithAirtimeServiceFactory(func(flows.SessionAssets) (flows.AirtimeService, error) {
return dtone.NewService(http.DefaultClient, nil, "nyaruka", "123456789"), nil
}).
Expand Down Expand Up @@ -443,7 +438,6 @@ func TestConstructors(t *testing.T) {
{
actions.NewOpenTicket(
actionUUID,
assets.NewTicketerReference(assets.TicketerUUID("0baee364-07a7-4c93-9778-9f55a35903bb"), "Support Tickets"),
assets.NewTopicReference("472a7a73-96cb-4736-b567-056d987cc5b4", "Weather"),
"Where are my cookies?",
assets.NewUserReference("[email protected]", "Bob McTickets"),
Expand All @@ -452,10 +446,6 @@ func TestConstructors(t *testing.T) {
`{
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"type": "open_ticket",
"ticketer": {
"uuid": "0baee364-07a7-4c93-9778-9f55a35903bb",
"name": "Support Tickets"
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
Expand Down
28 changes: 8 additions & 20 deletions flows/actions/open_ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const TypeOpenTicket string = "open_ticket"
// {
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "type": "open_ticket",
// "ticketer": {
// "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5",
// "name": "Support Tickets"
// },
// "topic": {
// "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
// "name": "Weather"
Expand All @@ -37,18 +33,16 @@ type OpenTicketAction struct {
baseAction
onlineAction

Ticketer *assets.TicketerReference `json:"ticketer" validate:"required"`
Topic *assets.TopicReference `json:"topic" validate:"omitempty"`
Body string `json:"body" engine:"evaluated"`
Assignee *assets.UserReference `json:"assignee" validate:"omitempty"`
ResultName string `json:"result_name" validate:"required"`
Topic *assets.TopicReference `json:"topic" validate:"omitempty"`
Body string `json:"body" engine:"evaluated"`
Assignee *assets.UserReference `json:"assignee" validate:"omitempty"`
ResultName string `json:"result_name" validate:"required"`
}

// NewOpenTicket creates a new open ticket action
func NewOpenTicket(uuid flows.ActionUUID, ticketer *assets.TicketerReference, topic *assets.TopicReference, body string, assignee *assets.UserReference, resultName string) *OpenTicketAction {
func NewOpenTicket(uuid flows.ActionUUID, topic *assets.TopicReference, body string, assignee *assets.UserReference, resultName string) *OpenTicketAction {
return &OpenTicketAction{
baseAction: newBaseAction(TypeOpenTicket, uuid),
Ticketer: ticketer,
Topic: topic,
Body: body,
Assignee: assignee,
Expand All @@ -60,8 +54,6 @@ func NewOpenTicket(uuid flows.ActionUUID, ticketer *assets.TicketerReference, to
func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
sa := run.Session().Assets()

ticketer := sa.Ticketers().Get(a.Ticketer.UUID)

var topic *flows.Topic
if a.Topic != nil {
topic = sa.Topics().Get(a.Topic.UUID)
Expand All @@ -78,7 +70,7 @@ func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier f
logEvent(events.NewError(err))
}

ticket := a.open(run, step, ticketer, topic, evaluatedBody, assignee, logModifier, logEvent)
ticket := a.open(run, step, topic, evaluatedBody, assignee, logModifier, logEvent)
if ticket != nil {
a.saveResult(run, step, a.ResultName, string(ticket.UUID()), CategorySuccess, "", "", nil, logEvent)
} else {
Expand All @@ -88,22 +80,18 @@ func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier f
return nil
}

func (a *OpenTicketAction) open(run flows.Run, step flows.Step, ticketer *flows.Ticketer, topic *flows.Topic, body string, assignee *flows.User, logModifier flows.ModifierCallback, logEvent flows.EventCallback) *flows.Ticket {
func (a *OpenTicketAction) open(run flows.Run, step flows.Step, topic *flows.Topic, body string, assignee *flows.User, logModifier flows.ModifierCallback, logEvent flows.EventCallback) *flows.Ticket {
if run.Session().BatchStart() {
logEvent(events.NewErrorf("can't open tickets during batch starts"))
return nil
}

if ticketer == nil {
logEvent(events.NewDependencyError(a.Ticketer))
return nil
}
if a.Topic != nil && topic == nil {
logEvent(events.NewDependencyError(a.Topic))
return nil
}

mod := modifiers.NewTicket(ticketer, topic, body, assignee)
mod := modifiers.NewTicket(topic, body, assignee)

if a.applyModifier(run, mod, logModifier, logEvent) {
// if we were able to open a ticket, return it
Expand Down
7 changes: 0 additions & 7 deletions flows/actions/testdata/_assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,6 @@
]
}
],
"ticketers": [
{
"uuid": "d605bb96-258d-4097-ad0a-080937db2212",
"name": "Support Tickets",
"type": "mailgun"
}
],
"topics": [
{
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
Expand Down
Loading

0 comments on commit df93e29

Please sign in to comment.