Merge branch 'master' into schedule-api-notification

Conflicts:
	tests/app/v2/notifications/test_post_notifications.py
This commit is contained in:
Rebecca Law
2017-05-23 13:58:50 +01:00
11 changed files with 118 additions and 38 deletions

View File

@@ -292,7 +292,7 @@ class Live(Config):
NOTIFY_ENVIRONMENT = 'live'
CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload'
STATSD_ENABLED = True
FROM_NUMBER = '40604'
FROM_NUMBER = 'GOVUK'
FUNCTIONAL_TEST_PROVIDER_SERVICE_ID = '6c1d81bb-dae2-4ee9-80b0-89a4aae9f649'
FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID = 'ba9e1789-a804-40b8-871f-cc60d4c1286f'
PERFORMANCE_PLATFORM_ENABLED = True

View File

@@ -23,6 +23,7 @@ from app.celery.statistics_tasks import record_initial_job_statistics, create_in
def send_sms_to_provider(notification):
service = notification.service
if not service.active:
technical_failure(notification=notification)
return
@@ -37,7 +38,7 @@ def send_sms_to_provider(notification):
template_model.__dict__,
values=notification.personalisation,
prefix=service.name,
sender=service.sms_sender
sender=service.sms_sender not in {None, current_app.config['FROM_NUMBER']}
)
if service.research_mode or notification.key_type == KEY_TYPE_TEST:
@@ -50,7 +51,7 @@ def send_sms_to_provider(notification):
to=validate_and_format_phone_number(notification.to, international=notification.international),
content=str(template),
reference=str(notification.id),
sender=service.sms_sender
sender=service.sms_sender or current_app.config['FROM_NUMBER']
)
except Exception as e:
dao_toggle_sms_provider(provider.name)

View File

@@ -3,6 +3,7 @@ import uuid
import datetime
from flask import url_for, current_app
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.dialects.postgresql import (
UUID,
@@ -144,9 +145,9 @@ class DVLAOrganisation(db.Model):
INTERNATIONAL_SMS_TYPE = 'international_sms'
INCOMING_SMS_TYPE = 'incoming_sms'
INBOUND_SMS_TYPE = 'inbound_sms'
SERVICE_PERMISSION_TYPES = [EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, INTERNATIONAL_SMS_TYPE, INCOMING_SMS_TYPE]
SERVICE_PERMISSION_TYPES = [EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, INTERNATIONAL_SMS_TYPE, INBOUND_SMS_TYPE]
class ServicePermissionTypes(db.Model):
@@ -155,18 +156,6 @@ class ServicePermissionTypes(db.Model):
name = db.Column(db.String(255), primary_key=True)
class ServicePermission(db.Model):
__tablename__ = "service_permissions"
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'),
primary_key=True, index=True, nullable=False)
service = db.relationship('Service')
permission = db.Column(db.String(255), db.ForeignKey('service_permission_types.name'),
index=True, primary_key=True, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, nullable=False)
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
class Service(db.Model, Versioned):
__tablename__ = 'services'
@@ -199,7 +188,7 @@ class Service(db.Model, Versioned):
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
reply_to_email_address = db.Column(db.Text, index=False, unique=False, nullable=True)
letter_contact_block = db.Column(db.Text, index=False, unique=False, nullable=True)
sms_sender = db.Column(db.String(11), nullable=True)
sms_sender = db.Column(db.String(11), nullable=True, default=lambda: current_app.config['FROM_NUMBER'])
organisation_id = db.Column(UUID(as_uuid=True), db.ForeignKey('organisation.id'), index=True, nullable=True)
organisation = db.relationship('Organisation')
dvla_organisation_id = db.Column(
@@ -217,7 +206,8 @@ class Service(db.Model, Versioned):
nullable=False,
default=BRANDING_GOVUK
)
permissions = db.relationship('ServicePermission')
association_proxy('permissions', 'service_permission_types')
# This is only for backward compatibility and will be dropped when the columns are removed from the data model
def set_permissions(self):
@@ -226,6 +216,22 @@ class Service(db.Model, Versioned):
self.can_send_international_sms = INTERNATIONAL_SMS_TYPE in [p.permission for p in self.permissions]
class ServicePermission(db.Model):
__tablename__ = "service_permissions"
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'),
primary_key=True, index=True, nullable=False)
permission = db.Column(db.String(255), db.ForeignKey('service_permission_types.name'),
index=True, primary_key=True, nullable=False)
service = db.relationship("Service")
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, nullable=False)
service_permission_types = db.relationship(Service, backref=db.backref("permissions"))
def __repr__(self):
return '<{} has service permission: {}>'.format(self.service_id, self.permission)
MOBILE_TYPE = 'mobile'
EMAIL_TYPE = 'email'