-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into research-mode-csv-file-queues
Conflicts: tests/app/celery/test_tasks.py tests/app/notifications/rest/test_send_notification.py
- Loading branch information
Showing
14 changed files
with
586 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from app import db | ||
from app.models import Service, ServiceWhitelist | ||
|
||
|
||
def dao_fetch_service_whitelist(service_id): | ||
return ServiceWhitelist.query.filter( | ||
ServiceWhitelist.service_id == service_id).all() | ||
|
||
|
||
def dao_add_and_commit_whitelisted_contacts(objs): | ||
db.session.add_all(objs) | ||
db.session.commit() | ||
|
||
|
||
def dao_remove_service_whitelist(service_id): | ||
return ServiceWhitelist.query.filter( | ||
ServiceWhitelist.service_id == service_id).delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import itertools | ||
|
||
from app.models import ( | ||
ServiceWhitelist, | ||
MOBILE_TYPE, EMAIL_TYPE, | ||
KEY_TYPE_TEST, KEY_TYPE_TEAM, KEY_TYPE_NORMAL) | ||
|
||
from notifications_utils.recipients import allowed_to_send_to | ||
|
||
|
||
def get_recipients_from_request(request_json, key, type): | ||
return [(type, recipient) for recipient in request_json.get(key)] | ||
|
||
|
||
def get_whitelist_objects(service_id, request_json): | ||
return [ | ||
ServiceWhitelist.from_string(service_id, type, recipient) | ||
for type, recipient in ( | ||
get_recipients_from_request(request_json, | ||
'phone_numbers', | ||
MOBILE_TYPE) + | ||
get_recipients_from_request(request_json, | ||
'email_addresses', | ||
EMAIL_TYPE) | ||
) | ||
] | ||
|
||
|
||
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) | ||
|
||
if key_type == KEY_TYPE_TEAM: | ||
return allowed_to_send_to( | ||
recipient, | ||
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( | ||
recipient, | ||
itertools.chain( | ||
team_members, | ||
whitelist_members | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""add service whitelist table | ||
Revision ID: 0055_service_whitelist | ||
Revises: 0054_perform_drop_status_column | ||
Create Date: 2016-09-20 12:12:30.838095 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '0055_service_whitelist' | ||
down_revision = '0054_perform_drop_status_column' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
def upgrade(): | ||
op.create_table('service_whitelist', | ||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column('recipient_type', sa.Enum('mobile', 'email', name='recipient_type'), nullable=False), | ||
sa.Column('recipient', sa.String(length=255), nullable=True), | ||
sa.Column('created_at', sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_service_whitelist_service_id'), 'service_whitelist', ['service_id'], unique=False) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table('service_whitelist') |
Oops, something went wrong.