From 6fce64025b2790f1ee6382b7d00937aeeeacddab Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Tue, 7 May 2024 16:50:55 -0500 Subject: [PATCH] Remove old urn modifier which was replaced by the urns modifier --- flows/modifiers/base_test.go | 8 -- flows/modifiers/testdata/urn.json | 141 ------------------------------ flows/modifiers/urn.go | 75 ---------------- 3 files changed, 224 deletions(-) delete mode 100644 flows/modifiers/testdata/urn.json delete mode 100644 flows/modifiers/urn.go diff --git a/flows/modifiers/base_test.go b/flows/modifiers/base_test.go index fe7335d39..192c6448a 100644 --- a/flows/modifiers/base_test.go +++ b/flows/modifiers/base_test.go @@ -201,14 +201,6 @@ func TestConstructors(t *testing.T) { "timezone": "America/Los_Angeles" }`, }, - { - modifiers.NewURN(urns.URN("tel:+1234567890"), modifiers.URNAppend), - `{ - "type": "urn", - "urn": "tel:+1234567890", - "modification": "append" - }`, - }, { modifiers.NewURNs([]urns.URN{urns.URN("tel:+1234567890"), urns.URN("tel:+1234567891")}, modifiers.URNsSet), `{ diff --git a/flows/modifiers/testdata/urn.json b/flows/modifiers/testdata/urn.json deleted file mode 100644 index 3d559abc6..000000000 --- a/flows/modifiers/testdata/urn.json +++ /dev/null @@ -1,141 +0,0 @@ -[ - { - "description": "URNs changed event if URN added", - "contact_before": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "urns": [ - "tel:+17036971111" - ], - "created_on": "2018-06-20T11:40:30.123456789Z" - }, - "modifier": { - "type": "urn", - "urn": "tel:+17036972222", - "modification": "append" - }, - "contact_after": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "created_on": "2018-06-20T11:40:30.123456789Z", - "urns": [ - "tel:+17036971111", - "tel:+17036972222" - ] - }, - "events": [ - { - "type": "contact_urns_changed", - "created_on": "2018-10-18T14:20:30.000123456Z", - "urns": [ - "tel:+17036971111", - "tel:+17036972222" - ] - } - ] - }, - { - "description": "URNs changed event if URN removed", - "contact_before": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "urns": [ - "tel:+17036971111", - "tel:+17036972222" - ], - "created_on": "2018-06-20T11:40:30.123456789Z" - }, - "modifier": { - "type": "urn", - "urn": "tel:+17036972222", - "modification": "remove" - }, - "contact_after": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "created_on": "2018-06-20T11:40:30.123456789Z", - "urns": [ - "tel:+17036971111" - ] - }, - "events": [ - { - "type": "contact_urns_changed", - "created_on": "2018-10-18T14:20:30.000123456Z", - "urns": [ - "tel:+17036971111" - ] - } - ] - }, - { - "description": "URN normalized before checking existence", - "contact_before": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "urns": [ - "tel:+17010000000" - ], - "created_on": "2018-06-20T11:40:30.123456789Z" - }, - "modifier": { - "type": "urn", - "urn": "tel:+1 (701) 222 2222", - "modification": "append" - }, - "contact_after": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "created_on": "2018-06-20T11:40:30.123456789Z", - "urns": [ - "tel:+17010000000", - "tel:+17012222222" - ] - }, - "events": [ - { - "type": "contact_urns_changed", - "created_on": "2018-10-18T14:20:30.000123456Z", - "urns": [ - "tel:+17010000000", - "tel:+17012222222" - ] - } - ] - }, - { - "description": "noop if URNs unchanged", - "contact_before": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "urns": [ - "tel:+17010000000", - "tel:+17012222222" - ], - "created_on": "2018-06-20T11:40:30.123456789Z" - }, - "modifier": { - "type": "urn", - "urn": "tel:+17012222222", - "modification": "append" - }, - "contact_after": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "created_on": "2018-06-20T11:40:30.123456789Z", - "urns": [ - "tel:+17010000000", - "tel:+17012222222" - ] - }, - "events": [] - } -] \ No newline at end of file diff --git a/flows/modifiers/urn.go b/flows/modifiers/urn.go deleted file mode 100644 index 44eadc66b..000000000 --- a/flows/modifiers/urn.go +++ /dev/null @@ -1,75 +0,0 @@ -package modifiers - -import ( - "encoding/json" - - "github.com/nyaruka/gocommon/urns" - "github.com/nyaruka/goflow/assets" - "github.com/nyaruka/goflow/envs" - "github.com/nyaruka/goflow/flows" - "github.com/nyaruka/goflow/flows/events" - "github.com/nyaruka/goflow/utils" -) - -func init() { - registerType(TypeURN, readURNModifier) -} - -// TypeURN is the type of our URN modifier -const TypeURN string = "urn" - -// URNModification is the type of modification to make -type URNModification string - -// the supported types of modification -const ( - URNAppend URNModification = "append" - URNRemove URNModification = "remove" -) - -// URNModifier modifies a URN on a contact. This has been replaced by URNsModifier but is kept here for now -// to support processing of old Surveyor submissions. -type URNModifier struct { - baseModifier - - URN urns.URN `json:"urn" validate:"required"` - Modification URNModification `json:"modification" validate:"required,eq=append|eq=remove"` -} - -// NewURN creates a new name modifier -func NewURN(urn urns.URN, modification URNModification) *URNModifier { - return &URNModifier{ - baseModifier: newBaseModifier(TypeURN), - URN: urn, - Modification: modification, - } -} - -// Apply applies this modification to the given contact -func (m *URNModifier) Apply(eng flows.Engine, env envs.Environment, sa flows.SessionAssets, contact *flows.Contact, log flows.EventCallback) bool { - urn := m.URN.Normalize(string(env.DefaultCountry())) - modified := false - - if m.Modification == URNAppend { - modified = contact.AddURN(urn, nil) - } else { - modified = contact.RemoveURN(urn) - } - - if modified { - log(events.NewContactURNsChanged(contact.URNs().RawURNs())) - return true - } - return false -} - -var _ flows.Modifier = (*URNModifier)(nil) - -//------------------------------------------------------------------------------------------ -// JSON Encoding / Decoding -//------------------------------------------------------------------------------------------ - -func readURNModifier(assets flows.SessionAssets, data json.RawMessage, missing assets.MissingCallback) (flows.Modifier, error) { - m := &URNModifier{} - return m, utils.UnmarshalAndValidate(data, m) -}