Merge pull request #2444 from alphagov/remove-domains-from-branding

Stop updating or reading domain columns on branding table
This commit is contained in:
Chris Hill-Scott
2019-04-15 15:35:09 +01:00
committed by GitHub
15 changed files with 24 additions and 220 deletions

View File

@@ -11,14 +11,6 @@ def dao_get_letter_branding_by_name(letter_branding_name):
return LetterBranding.query.filter_by(name=letter_branding_name).first()
def dao_get_letter_branding_by_domain(domain):
if not domain:
return None
return LetterBranding.query.filter(
LetterBranding.domain == domain
).first()
def dao_get_all_letter_branding():
return LetterBranding.query.order_by(LetterBranding.name).all()

View File

@@ -168,7 +168,6 @@ def dao_create_service(
user,
service_id=None,
service_permissions=None,
letter_branding=None,
):
# the default property does not appear to work when there is a difference between the sqlalchemy schema and the
# db schema (ie: during a migration), so we have to set sms_sender manually here. After the GOVUK sms_sender
@@ -198,9 +197,6 @@ def dao_create_service(
# do we just add the default - or will we get a value from FE?
insert_service_sms_sender(service, current_app.config['FROM_NUMBER'])
if letter_branding:
service.letter_branding = letter_branding
if organisation:
service.organisation = organisation
@@ -211,9 +207,8 @@ def dao_create_service(
if organisation.letter_branding and not service.letter_branding:
service.letter_branding = organisation.letter_branding
if not organisation and (
service.organisation_type == 'nhs' or email_address_is_nhs(user.email_address)
):
elif service.organisation_type == 'nhs' or email_address_is_nhs(user.email_address):
service.email_branding = dao_get_email_branding_by_name('NHS')
service.letter_branding = dao_get_letter_branding_by_name('NHS')

View File

@@ -9,7 +9,6 @@ post_create_email_branding_schema = {
"name": {"type": "string"},
"text": {"type": ["string", "null"]},
"logo": {"type": ["string", "null"]},
"domain": {"type": ["string", "null"]},
"brand_type": {"enum": BRANDING_TYPES},
},
"required": ["name"]
@@ -24,7 +23,6 @@ post_update_email_branding_schema = {
"name": {"type": ["string", "null"]},
"text": {"type": ["string", "null"]},
"logo": {"type": ["string", "null"]},
"domain": {"type": ["string", "null"]},
"brand_type": {"enum": BRANDING_TYPES},
},
"required": []

View File

@@ -1,5 +1,4 @@
from flask import Blueprint, current_app, jsonify, request
from sqlalchemy.exc import IntegrityError
from flask import Blueprint, jsonify, request
from app.dao.email_branding_dao import (
dao_create_email_branding,
@@ -19,22 +18,6 @@ email_branding_blueprint = Blueprint('email_branding', __name__)
register_errors(email_branding_blueprint)
@email_branding_blueprint.errorhandler(IntegrityError)
def handle_integrity_error(exc):
"""
Handle integrity errors caused by the unique constraint on domain
"""
if 'domain' in str(exc):
return jsonify(
result='error',
message={'name': ["Duplicate domain '{}'".format(
exc.params.get('domain')
)]}
), 400
current_app.logger.exception(exc)
return jsonify(result='error', message="Internal server error"), 500
@email_branding_blueprint.route('', methods=['GET'])
def get_email_branding_options():
email_branding_options = [o.serialize() for o in dao_get_email_branding_options()]

View File

@@ -22,7 +22,7 @@ def handle_integrity_error(exc):
"""
Handle integrity errors caused by the unique constraint
"""
for col in {'domain', 'name', 'filename'}:
for col in {'name', 'filename'}:
if 'letter_branding_{}_key'.format(col) in str(exc):
return jsonify(
result='error',

View File

@@ -5,7 +5,6 @@ post_letter_branding_schema = {
"properties": {
"name": {"type": ["string", "null"]},
"filename": {"type": ["string", "null"]},
"domain": {"type": ["string", "null"]},
},
"required": ("name", "filename")
}

View File

@@ -221,7 +221,6 @@ class EmailBranding(db.Model):
logo = db.Column(db.String(255), nullable=True)
name = db.Column(db.String(255), unique=True, nullable=False)
text = db.Column(db.String(255), nullable=True)
domain = db.Column(db.Text, unique=True, nullable=True)
brand_type = db.Column(
db.String(255),
db.ForeignKey('branding_type.name'),
@@ -237,7 +236,6 @@ class EmailBranding(db.Model):
"logo": self.logo,
"name": self.name,
"text": self.text,
"domain": self.domain,
"brand_type": self.brand_type
}
@@ -258,14 +256,12 @@ class LetterBranding(db.Model):
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = db.Column(db.String(255), unique=True, nullable=False)
filename = db.Column(db.String(255), unique=True, nullable=False)
domain = db.Column(db.Text, unique=True, nullable=True)
def serialize(self):
return {
"id": str(self.id),
"name": self.name,
"filename": self.filename,
"domain": self.domain,
}

View File

@@ -27,7 +27,6 @@ from app.dao.fact_notification_status_dao import (
fetch_stats_for_all_services_by_date_range, fetch_monthly_template_usage_for_service
)
from app.dao.inbound_numbers_dao import dao_allocate_number_for_service
from app.dao.letter_branding_dao import dao_get_letter_branding_by_domain
from app.dao.organisation_dao import dao_get_organisation_by_service_id
from app.dao.service_data_retention_dao import (
fetch_service_data_retention,
@@ -186,7 +185,8 @@ def create_service():
if not data.get('user_id'):
errors = {'user_id': ['Missing data for required field.']}
raise InvalidRequest(errors, status_code=400)
domain = data.pop('service_domain', None)
data.pop('service_domain', None)
# validate json with marshmallow
service_schema.load(data)
@@ -195,8 +195,7 @@ def create_service():
# unpack valid json into service object
valid_service = Service.from_json(data)
letter_branding = dao_get_letter_branding_by_domain(domain)
dao_create_service(valid_service, user, letter_branding=letter_branding)
dao_create_service(valid_service, user)
return jsonify(data=service_schema.dump(valid_service).data), 201