Merge branch 'master' into remove-nasty-query-from-dashboard

This commit is contained in:
Martyn Inglis
2017-05-23 13:55:30 +01:00
15 changed files with 143 additions and 126 deletions

View File

@@ -1,5 +1,3 @@
import random
from datetime import (datetime)
from collections import namedtuple
@@ -361,21 +359,20 @@ def get_template_class(template_type):
@statsd(namespace="tasks")
def update_letter_notifications_statuses(self, filename):
bucket_location = '{}-ftp'.format(current_app.config['NOTIFY_EMAIL_DOMAIN'])
response_file = s3.get_s3_file(bucket_location, filename)
response_file_content = s3.get_s3_file(bucket_location, filename)
try:
NotificationUpdate = namedtuple('NotificationUpdate', ['reference', 'status', 'page_count', 'cost_threshold'])
notification_updates = [NotificationUpdate(*line.split('|')) for line in response_file.splitlines()]
notification_updates = process_updates_from_file(response_file_content)
except TypeError:
current_app.logger.exception('DVLA response file: {} has an invalid format'.format(filename))
raise
else:
if notification_updates:
for update in notification_updates:
current_app.logger.info('DVLA update: {}'.format(str(update)))
# TODO: Update notifications with desired status
return notification_updates
else:
current_app.logger.exception('DVLA response file contained no updates')
for update in notification_updates:
current_app.logger.info('DVLA update: {}'.format(str(update)))
# TODO: Update notifications with desired status
def process_updates_from_file(response_file):
NotificationUpdate = namedtuple('NotificationUpdate', ['reference', 'status', 'page_count', 'cost_threshold'])
notification_updates = [NotificationUpdate(*line.split('|')) for line in response_file.splitlines()]
return notification_updates

View File

@@ -287,7 +287,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'

View File

@@ -1,3 +1,5 @@
import json
from functools import wraps
from flask import (
@@ -48,7 +50,8 @@ def process_letter_response():
current_app.logger.info('Received SNS callback: {}'.format(req_json))
if not autoconfirm_subscription(req_json):
# The callback should have one record for an S3 Put Event.
filename = req_json['Message']['Records'][0]['s3']['object']['key']
message = json.loads(req_json['Message'])
filename = message['Records'][0]['s3']['object']['key']
current_app.logger.info('Received file from DVLA: {}'.format(filename))
current_app.logger.info('DVLA callback: Calling task to update letter notifications')
update_letter_notifications_statuses.apply_async([filename], queue='notify')