Skip to content

Commit

Permalink
Remove support for delegate channels
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 11, 2023
1 parent faa31ec commit 2217fb6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 43 deletions.
1 change: 0 additions & 1 deletion assets/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Channel interface {
Address() string
Schemes() []string
Roles() []ChannelRole
Parent() *ChannelReference
Country() i18n.Country
MatchPrefixes() []string
AllowInternational() bool
Expand Down
22 changes: 8 additions & 14 deletions assets/static/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +26,6 @@ func NewChannel(uuid assets.ChannelUUID, name string, address string, schemes []
Address_: address,
Schemes_: schemes,
Roles_: roles,
Parent_: parent,
AllowInternational_: true,
}
}
Expand All @@ -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,
Expand All @@ -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_ }

Expand Down
1 change: 0 additions & 1 deletion assets/static/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions cmd/flowrunner/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
21 changes: 3 additions & 18 deletions flows/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
9 changes: 0 additions & 9 deletions flows/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2217fb6

Please sign in to comment.