mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 16:12:32 -05:00
Let team key send to whitelist
There is an overlap between team key/trial mode/whitelist. But it’s not a complete overlap. So it’s hard to understand all the different permutations of which key lets you send to which people when. This commit tries to reduce the differences between these concepts. So for a user of the API **In trial mode** - You can send to anyone in your team or whitelist, using the team key - You can simulate sending to anyone, using the simulate key **When you’re live** - You can send to anyone in your team or whitelist, using the team key - You can simulate sending to anyone, using the simulate key - You can send to anyone with the live key So doing a `git diff` on that list, the only difference between being in trial mode and live mode is now: `+` You can send to anyone with the live key **(How trial mode used to work)** - You can send to anyone in your team or whitelist, using the normal key - You can simulate sending to anyone, using the simulate key - You can send to _just_ people in your team using the team key
This commit is contained in:
@@ -34,16 +34,16 @@ def service_allowed_to_send_to(recipient, service, key_type):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
team_members = itertools.chain.from_iterable(
|
team_members = itertools.chain.from_iterable(
|
||||||
[user.mobile_number, user.email_address] for user in service.users)
|
[user.mobile_number, user.email_address] for user in service.users
|
||||||
|
)
|
||||||
|
whitelist_members = [
|
||||||
|
member.recipient for member in service.whitelist
|
||||||
|
]
|
||||||
|
|
||||||
if key_type == KEY_TYPE_TEAM:
|
if (
|
||||||
return allowed_to_send_to(
|
(key_type == KEY_TYPE_NORMAL and service.restricted) or
|
||||||
recipient,
|
(key_type == KEY_TYPE_TEAM)
|
||||||
team_members
|
):
|
||||||
)
|
|
||||||
|
|
||||||
if key_type == KEY_TYPE_NORMAL and service.restricted:
|
|
||||||
whitelist_members = [member.recipient for member in service.whitelist]
|
|
||||||
return allowed_to_send_to(
|
return allowed_to_send_to(
|
||||||
recipient,
|
recipient,
|
||||||
itertools.chain(
|
itertools.chain(
|
||||||
|
|||||||
@@ -819,23 +819,34 @@ def test_should_not_send_notification_to_non_whitelist_recipient_in_trial_mode(c
|
|||||||
apply_async.assert_not_called()
|
apply_async.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('notification_type,to', [
|
@pytest.mark.parametrize('service_restricted', [
|
||||||
('sms', '07123123123'),
|
True, False
|
||||||
('email', 'whitelist_recipient@mail.com')])
|
])
|
||||||
def test_should_send_notification_to_whitelist_recipient_in_trial_mode_with_live_key(client,
|
@pytest.mark.parametrize('key_type', [
|
||||||
notify_db,
|
KEY_TYPE_NORMAL, KEY_TYPE_TEAM
|
||||||
notify_db_session,
|
])
|
||||||
notification_type,
|
@pytest.mark.parametrize('notification_type, to, _create_sample_template', [
|
||||||
to,
|
('sms', '07123123123', create_sample_template),
|
||||||
mocker):
|
('email', 'whitelist_recipient@mail.com', create_sample_email_template)]
|
||||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
)
|
||||||
|
def test_should_send_notification_to_whitelist_recipient(
|
||||||
|
client,
|
||||||
|
notify_db,
|
||||||
|
notify_db_session,
|
||||||
|
notification_type,
|
||||||
|
to,
|
||||||
|
_create_sample_template,
|
||||||
|
key_type,
|
||||||
|
service_restricted,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=service_restricted)
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
|
apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
|
||||||
|
template = _create_sample_template(notify_db, notify_db_session, service=service)
|
||||||
if notification_type == 'sms':
|
if notification_type == 'sms':
|
||||||
template = create_sample_template(notify_db, notify_db_session, service=service)
|
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
||||||
service=service, mobile_number=to)
|
service=service, mobile_number=to)
|
||||||
elif notification_type == 'email':
|
elif notification_type == 'email':
|
||||||
template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
||||||
service=service, email_address=to)
|
service=service, email_address=to)
|
||||||
|
|
||||||
@@ -849,8 +860,8 @@ def test_should_send_notification_to_whitelist_recipient_in_trial_mode_with_live
|
|||||||
'template': str(template.id)
|
'template': str(template.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
sample_live_key = create_sample_api_key(notify_db, notify_db_session, service)
|
sample_key = create_sample_api_key(notify_db, notify_db_session, service, key_type=key_type)
|
||||||
auth_header = create_jwt_token(secret=sample_live_key.unsigned_secret, client_id=str(sample_live_key.service_id))
|
auth_header = create_jwt_token(secret=sample_key.unsigned_secret, client_id=str(sample_key.service_id))
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path='/notifications/{}'.format(notification_type),
|
path='/notifications/{}'.format(notification_type),
|
||||||
|
|||||||
Reference in New Issue
Block a user