From 2217fb63cd43c7edf9fe2e848da2a796fee8adec Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 11 Sep 2023 14:18:00 -0500 Subject: [PATCH] Remove support for delegate channels --- assets/channel.go | 1 - assets/static/channel.go | 22 ++++++++-------------- assets/static/channel_test.go | 1 - cmd/flowrunner/main_test.go | 4 ++++ flows/channel.go | 21 +++------------------ flows/channel_test.go | 9 --------- 6 files changed, 15 insertions(+), 43 deletions(-) diff --git a/assets/channel.go b/assets/channel.go index c46ddbf9c..f9f08e5a9 100644 --- a/assets/channel.go +++ b/assets/channel.go @@ -40,7 +40,6 @@ type Channel interface { Address() string Schemes() []string Roles() []ChannelRole - Parent() *ChannelReference Country() i18n.Country MatchPrefixes() []string AllowInternational() bool diff --git a/assets/static/channel.go b/assets/static/channel.go index 63e8c7ec5..1c5aa5d07 100644 --- a/assets/static/channel.go +++ b/assets/static/channel.go @@ -8,15 +8,14 @@ import ( // Channel is a JSON serializable implementation of a channel asset type Channel struct { - UUID_ assets.ChannelUUID `json:"uuid" validate:"required,uuid"` - Name_ string `json:"name"` - Address_ string `json:"address"` - Schemes_ []string `json:"schemes" validate:"min=1"` - Roles_ []assets.ChannelRole `json:"roles" validate:"min=1,dive,eq=send|eq=receive|eq=call|eq=answer|eq=ussd"` - Parent_ *assets.ChannelReference `json:"parent" validate:"omitempty,dive"` - Country_ i18n.Country `json:"country,omitempty"` - MatchPrefixes_ []string `json:"match_prefixes,omitempty"` - AllowInternational_ bool `json:"allow_international,omitempty"` + UUID_ assets.ChannelUUID `json:"uuid" validate:"required,uuid"` + Name_ string `json:"name"` + Address_ string `json:"address"` + Schemes_ []string `json:"schemes" validate:"min=1"` + Roles_ []assets.ChannelRole `json:"roles" validate:"min=1,dive,eq=send|eq=receive|eq=call|eq=answer|eq=ussd"` + Country_ i18n.Country `json:"country,omitempty"` + MatchPrefixes_ []string `json:"match_prefixes,omitempty"` + AllowInternational_ bool `json:"allow_international,omitempty"` } // NewChannel creates a new channel @@ -27,7 +26,6 @@ func NewChannel(uuid assets.ChannelUUID, name string, address string, schemes [] Address_: address, Schemes_: schemes, Roles_: roles, - Parent_: parent, AllowInternational_: true, } } @@ -40,7 +38,6 @@ func NewTelChannel(uuid assets.ChannelUUID, name string, address string, roles [ Address_: address, Schemes_: []string{urns.TelScheme}, Roles_: roles, - Parent_: parent, Country_: country, MatchPrefixes_: matchPrefixes, AllowInternational_: allowInternational, @@ -62,9 +59,6 @@ func (c *Channel) Schemes() []string { return c.Schemes_ } // Roles returns the roles of this channel func (c *Channel) Roles() []assets.ChannelRole { return c.Roles_ } -// Parent returns a reference to this channel's parent (if any) -func (c *Channel) Parent() *assets.ChannelReference { return c.Parent_ } - // Country returns this channel's associated country code (if any) func (c *Channel) Country() i18n.Country { return c.Country_ } diff --git a/assets/static/channel_test.go b/assets/static/channel_test.go index 0e2b4878c..476a75c53 100644 --- a/assets/static/channel_test.go +++ b/assets/static/channel_test.go @@ -25,7 +25,6 @@ func TestChannel(t *testing.T) { assert.Equal(t, "+234151", channel.Address()) assert.Equal(t, []string{"tel"}, channel.Schemes()) assert.Equal(t, []assets.ChannelRole{assets.ChannelRoleSend}, channel.Roles()) - assert.Nil(t, channel.Parent()) assert.Equal(t, i18n.NilCountry, channel.Country()) assert.Nil(t, channel.MatchPrefixes()) assert.True(t, channel.AllowInternational()) diff --git a/cmd/flowrunner/main_test.go b/cmd/flowrunner/main_test.go index fe380a026..b635850ad 100644 --- a/cmd/flowrunner/main_test.go +++ b/cmd/flowrunner/main_test.go @@ -94,3 +94,7 @@ func TestPrintEvent(t *testing.T) { assert.Equal(t, tc.expected, out.String(), "event print mismatch for event type '%s'", tc.event.Type()) } } + +func TestFoo(t *testing.T) { + test.CreateTestSession("", envs.RedactionPolicyNone) +} diff --git a/flows/channel.go b/flows/channel.go index 230770602..c5c07b547 100644 --- a/flows/channel.go +++ b/flows/channel.go @@ -53,11 +53,6 @@ func (c *Channel) HasRole(role assets.ChannelRole) bool { return false } -// HasParent returns whether this channel has a parent -func (c *Channel) HasParent() bool { - return c.Parent() != nil -} - // Context returns the properties available in expressions // // __default__:text -> the name @@ -108,7 +103,7 @@ func (s *ChannelAssets) Get(uuid assets.ChannelUUID) *Channel { func (s *ChannelAssets) GetForURN(urn *ContactURN, role assets.ChannelRole) *Channel { // if caller has told us which channel to use for this URN, use that if urn.Channel() != nil && urn.Channel().HasRole(role) { - return s.getDelegate(urn.Channel(), role) + return urn.Channel() } // tel is a special case because we do number based matching @@ -155,7 +150,7 @@ func (s *ChannelAssets) GetForURN(urn *ContactURN, role assets.ChannelRole) *Cha } if channel != nil { - return s.getDelegate(channel, role) + return channel } return nil @@ -167,18 +162,8 @@ func (s *ChannelAssets) GetForURN(urn *ContactURN, role assets.ChannelRole) *Cha func (s *ChannelAssets) getForSchemeAndRole(scheme string, role assets.ChannelRole) *Channel { for _, ch := range s.all { if ch.HasRole(role) && ch.SupportsScheme(scheme) { - return s.getDelegate(ch, role) - } - } - return nil -} - -// looks for a delegate for the given channel and defaults to the channel itself -func (s *ChannelAssets) getDelegate(channel *Channel, role assets.ChannelRole) *Channel { - for _, ch := range s.all { - if ch.HasParent() && ch.Parent().UUID == channel.UUID() && ch.HasRole(role) { return ch } } - return channel + return nil } diff --git a/flows/channel_test.go b/flows/channel_test.go index 2cc42458f..ae93e2065 100644 --- a/flows/channel_test.go +++ b/flows/channel_test.go @@ -99,15 +99,6 @@ func TestChannelSetGetForURN(t *testing.T) { // if there's no overlap, then last/newest channel wins assert.Equal(t, tigo, all.GetForURN(flows.NewContactURN(urns.URN("tel:+250962222222"), nil), assets.ChannelRoleSend)) - // channels can be delegates for other channels - android := test.NewChannel("Android", "+250723333333", []string{"tel"}, rolesDefault, nil) - bulk := test.NewChannel("Bulk Sender", "1234", []string{"tel"}, rolesSend, android.Reference()) - all = flows.NewChannelAssets([]assets.Channel{android.Asset(), bulk.Asset()}) - - // delegate will always be used if it has the requested role - assert.Equal(t, android, all.GetForURN(flows.NewContactURN(urns.URN("tel:+250721234567"), nil), assets.ChannelRoleReceive)) - assert.Equal(t, bulk, all.GetForURN(flows.NewContactURN(urns.URN("tel:+250721234567"), nil), assets.ChannelRoleSend)) - // matching prefixes can be explicitly set too short1 := test.NewTelChannel("Shortcode 1", "1234", rolesSend, nil, "RW", []string{"25078", "25077"}, false) short2 := test.NewTelChannel("Shortcode 2", "1235", rolesSend, nil, "RW", []string{"25072"}, false)