예제 #1
0
def service_allowed_to_send_to(recipient, service, key_type):
    if key_type == KEY_TYPE_TEST:
        return True

    if key_type == KEY_TYPE_NORMAL and not service.restricted:
        return True

    team_members = itertools.chain.from_iterable(
        [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_NORMAL and service.restricted) or
        (key_type == KEY_TYPE_TEAM)
    ):
        return allowed_to_send_to(
            recipient,
            itertools.chain(
                team_members,
                whitelist_members
            )
        )
예제 #2
0
def service_allowed_to_send_to(recipient, service, key_type, allow_guest_list_recipients=True):
    if key_type == KEY_TYPE_TEST:
        return True

    if key_type == KEY_TYPE_NORMAL and not service.restricted:
        return True

    # Revert back to the ORM model here so we can get some things which
    # aren’t in the serialised model
    service = dao_fetch_service_by_id(service.id)

    team_members = itertools.chain.from_iterable(
        [user.mobile_number, user.email_address] for user in service.users
    )
    guest_list_members = [
        member.recipient for member in service.guest_list
        if allow_guest_list_recipients
    ]

    if (
        (key_type == KEY_TYPE_NORMAL and service.restricted) or
        (key_type == KEY_TYPE_TEAM)
    ):
        return allowed_to_send_to(
            recipient,
            itertools.chain(
                team_members,
                guest_list_members
            )
        )
예제 #3
0
def service_allowed_to_send_to(recipient,
                               service,
                               key_type,
                               allow_safelisted_recipients=True):
    members = safelisted_members(service, key_type,
                                 allow_safelisted_recipients)
    if members is None:
        return True
    return allowed_to_send_to(recipient, members)
예제 #4
0
def service_allowed_to_send_to(recipient,
                               service,
                               key_type,
                               allow_safelisted_recipients=True):
    if key_type == KEY_TYPE_TEST:
        return True

    if key_type == KEY_TYPE_NORMAL and not service.restricted:
        return True

    team_members = itertools.chain.from_iterable(
        [user.mobile_number, user.email_address] for user in service.users)
    safelist_members = [
        member.recipient for member in service.safelist
        if allow_safelisted_recipients
    ]

    if ((key_type == KEY_TYPE_NORMAL and service.restricted)
            or (key_type == KEY_TYPE_TEAM)):
        return allowed_to_send_to(
            recipient, itertools.chain(team_members, safelist_members))
예제 #5
0
def test_validates_against_whitelist_of_email_addresses(email_address):
    assert not allowed_to_send_to(email_address, ['*****@*****.**'])
예제 #6
0
def test_validates_against_whitelist_of_phone_numbers(phone_number):
    assert allowed_to_send_to(phone_number, ['07123456789', '07700900460', '*****@*****.**'])
    assert not allowed_to_send_to(phone_number, ['07700900460', '07700900461', '*****@*****.**'])
def test_validates_against_safelist_of_phone_numbers(phone_number):
    assert allowed_to_send_to(
        phone_number, ['6502532222', '07700900460', '*****@*****.**'])
    assert not allowed_to_send_to(
        phone_number, ['07700900460', '07700900461', '*****@*****.**'])
def test_validates_against_whitelist_of_email_addresses(email_address):
    assert not allowed_to_send_to(email_address, ['*****@*****.**'])
def test_validates_against_whitelist_of_phone_numbers(phone_number):
    assert allowed_to_send_to(phone_number, ['07123456789', '07700900460', '*****@*****.**'])
    assert not allowed_to_send_to(phone_number, ['07700900460', '07700900461', '*****@*****.**'])