Skip to content

Commit

Permalink
feat: no SMS & Whatsapp double signup validation (#15)
Browse files Browse the repository at this point in the history
* Feat:  Don't allow SMS and Whatsapp notifications to go to the same user

* Test new validation
  • Loading branch information
jonathansberry authored Jan 8, 2025
1 parent 127dce4 commit 410936d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ckanext/dataset_subscriptions/actions/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def _validate_plugin_extras(extras):
errors['activity_streams_sms_notifications'] = [
toolkit._('No phone number given')
]
if toolkit.asbool(extras.get('activity_streams_whatsapp_notifications')):
errors['activity_streams_sms_notifications'] = [
toolkit._('Please select either Whatsapp or SMS notifications - not both. ')
]
if toolkit.asbool(extras.get('activity_streams_whatsapp_notifications')):
if not extras.get('phonenumber'):
errors['activity_streams_whatsapp_notifications'] = [
Expand Down
5 changes: 3 additions & 2 deletions ckanext/dataset_subscriptions/tests/actions/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ def test_user_validate_plugin_extras_valid_phonenumber(self, client_mock, sysadm
helpers.call_action('user_create', context=sysadmin_context, **user_dict)

@pytest.mark.parametrize('phonenumber, enable_sms, enable_whatsapp, expectation', [
("", False, False, nullcontext(1)),
("+44712345678", False, False, nullcontext(1)),
("", False, True, pytest.raises(toolkit.ValidationError)),
("", True, False, pytest.raises(toolkit.ValidationError)),
("", True, True, pytest.raises(toolkit.ValidationError))
("", True, True, pytest.raises(toolkit.ValidationError)),
("+44712345678", True, True, pytest.raises(toolkit.ValidationError)),
])
def test_user_validate_plugin_extras_requires_phonenumber(self, phonenumber, enable_sms,
enable_whatsapp, expectation, sysadmin_context):
Expand Down

0 comments on commit 410936d

Please sign in to comment.