Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce a limit of 50 URNs per contact #1301

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flows/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const (

// ContactStatusArchived is the contact status of archived
ContactStatusArchived ContactStatus = "archived"

// MaxContactURNs is maximum number of URNs a contact can have
MaxContactURNs = 50
)

// Contact represents a person who is interacting with the flow
Expand Down
189 changes: 189 additions & 0 deletions flows/modifiers/testdata/urns.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,194 @@
"text": "'xyz:12345' is not valid URN"
}
]
},
{
"description": "error event if too many URNs",
"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": "urns",
"urns": [
"tel:+17020000000",
"tel:+17020000001",
"tel:+17020000002",
"tel:+17020000003",
"tel:+17020000004",
"tel:+17020000005",
"tel:+17020000006",
"tel:+17020000007",
"tel:+17020000008",
"tel:+17020000009",
"tel:+17020000010",
"tel:+17020000011",
"tel:+17020000012",
"tel:+17020000013",
"tel:+17020000014",
"tel:+17020000015",
"tel:+17020000016",
"tel:+17020000017",
"tel:+17020000018",
"tel:+17020000019",
"tel:+17020000020",
"tel:+17020000021",
"tel:+17020000022",
"tel:+17020000023",
"tel:+17020000024",
"tel:+17020000025",
"tel:+17020000026",
"tel:+17020000027",
"tel:+17020000028",
"tel:+17020000029",
"tel:+17020000030",
"tel:+17020000031",
"tel:+17020000032",
"tel:+17020000033",
"tel:+17020000034",
"tel:+17020000035",
"tel:+17020000036",
"tel:+17020000037",
"tel:+17020000038",
"tel:+17020000039",
"tel:+17020000040",
"tel:+17020000041",
"tel:+17020000042",
"tel:+17020000043",
"tel:+17020000044",
"tel:+17020000045",
"tel:+17020000046",
"tel:+17020000047",
"tel:+17020000048",
"tel:+17020000049"
],
"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:+17020000000",
"tel:+17020000001",
"tel:+17020000002",
"tel:+17020000003",
"tel:+17020000004",
"tel:+17020000005",
"tel:+17020000006",
"tel:+17020000007",
"tel:+17020000008",
"tel:+17020000009",
"tel:+17020000010",
"tel:+17020000011",
"tel:+17020000012",
"tel:+17020000013",
"tel:+17020000014",
"tel:+17020000015",
"tel:+17020000016",
"tel:+17020000017",
"tel:+17020000018",
"tel:+17020000019",
"tel:+17020000020",
"tel:+17020000021",
"tel:+17020000022",
"tel:+17020000023",
"tel:+17020000024",
"tel:+17020000025",
"tel:+17020000026",
"tel:+17020000027",
"tel:+17020000028",
"tel:+17020000029",
"tel:+17020000030",
"tel:+17020000031",
"tel:+17020000032",
"tel:+17020000033",
"tel:+17020000034",
"tel:+17020000035",
"tel:+17020000036",
"tel:+17020000037",
"tel:+17020000038",
"tel:+17020000039",
"tel:+17020000040",
"tel:+17020000041",
"tel:+17020000042",
"tel:+17020000043",
"tel:+17020000044",
"tel:+17020000045",
"tel:+17020000046",
"tel:+17020000047",
"tel:+17020000048"
]
},
"events": [
{
"type": "error",
"created_on": "2018-10-18T14:20:30.000123456Z",
"text": "contact has too many URNs, limit is 50"
},
{
"type": "contact_urns_changed",
"created_on": "2018-10-18T14:20:30.000123456Z",
"urns": [
"tel:+17010000000",
"tel:+17020000000",
"tel:+17020000001",
"tel:+17020000002",
"tel:+17020000003",
"tel:+17020000004",
"tel:+17020000005",
"tel:+17020000006",
"tel:+17020000007",
"tel:+17020000008",
"tel:+17020000009",
"tel:+17020000010",
"tel:+17020000011",
"tel:+17020000012",
"tel:+17020000013",
"tel:+17020000014",
"tel:+17020000015",
"tel:+17020000016",
"tel:+17020000017",
"tel:+17020000018",
"tel:+17020000019",
"tel:+17020000020",
"tel:+17020000021",
"tel:+17020000022",
"tel:+17020000023",
"tel:+17020000024",
"tel:+17020000025",
"tel:+17020000026",
"tel:+17020000027",
"tel:+17020000028",
"tel:+17020000029",
"tel:+17020000030",
"tel:+17020000031",
"tel:+17020000032",
"tel:+17020000033",
"tel:+17020000034",
"tel:+17020000035",
"tel:+17020000036",
"tel:+17020000037",
"tel:+17020000038",
"tel:+17020000039",
"tel:+17020000040",
"tel:+17020000041",
"tel:+17020000042",
"tel:+17020000043",
"tel:+17020000044",
"tel:+17020000045",
"tel:+17020000046",
"tel:+17020000047",
"tel:+17020000048"
]
}
]
}
]
11 changes: 9 additions & 2 deletions flows/modifiers/urns.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ func (m *URNsModifier) Apply(eng flows.Engine, env envs.Environment, sa flows.Se
log(events.NewErrorf("'%s' is not valid URN", urn))
} else {
if m.Modification == URNsAppend || m.Modification == URNsSet {
modified = contact.AddURN(urn, nil)
if len(contact.URNs()) >= flows.MaxContactURNs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the error message says we allow 50 so we use > flows.MaxContactURNs and not >= flows.MaxContactURNs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is checking if the modifier should be allowed to add one more URN tho

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I think the unit test added should not be an error as that has exactly 50 urns, we need one more urn to have that as error and use > comparison

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unit test is adding 50 urns but the contact already has 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh right

log(events.NewErrorf("contact has too many URNs, limit is %d", flows.MaxContactURNs))
break
} else if contact.AddURN(urn, nil) {
modified = true
}
} else {
modified = contact.RemoveURN(urn)
if contact.RemoveURN(urn) {
modified = true
}
}
}
}
Expand Down
Loading