diff --git a/app/__init__.py b/app/__init__.py index d952d67b0..51c98808d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -161,8 +161,6 @@ def register_blueprint(application): email_branding_blueprint.before_request(requires_admin_auth) application.register_blueprint(email_branding_blueprint, url_prefix='/email-branding') - # TODO: remove this route after admin is updated to refer to email branding - application.register_blueprint(email_branding_blueprint, url_prefix='/organisation') dvla_organisation_blueprint.before_request(requires_admin_auth) application.register_blueprint(dvla_organisation_blueprint, url_prefix='/dvla_organisations') diff --git a/app/email_branding/rest.py b/app/email_branding/rest.py index 9ff339158..277d27714 100644 --- a/app/email_branding/rest.py +++ b/app/email_branding/rest.py @@ -21,17 +21,13 @@ register_errors(email_branding_blueprint) @email_branding_blueprint.route('', methods=['GET']) def get_email_branding_options(): email_branding_options = [o.serialize() for o in dao_get_email_branding_options()] - key = 'organisations' if request.path.startswith('/organisation') else 'email_branding' - return jsonify(**{key: email_branding_options}) return jsonify(email_branding=email_branding_options) @email_branding_blueprint.route('/', methods=['GET']) def get_email_branding_by_id(email_branding_id): email_branding = dao_get_email_branding_by_id(email_branding_id) - # TODO: remove this switch after admin is updated to refer to email branding - key = 'organisation' if request.path.startswith('/organisation') else 'email_branding' - return jsonify(**{key: email_branding.serialize()}) + return jsonify(email_branding=email_branding.serialize()) @email_branding_blueprint.route('', methods=['POST']) diff --git a/app/models.py b/app/models.py index 5a1682aff..580626b4b 100644 --- a/app/models.py +++ b/app/models.py @@ -148,25 +148,6 @@ class BrandingTypes(db.Model): name = db.Column(db.String(255), primary_key=True) -# TODO: remove this model after admin is updated to refer to email branding -class Organisation(db.Model): - __tablename__ = 'organisation' - id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) - colour = db.Column(db.String(7), nullable=True) - logo = db.Column(db.String(255), nullable=True) - name = db.Column(db.String(255), nullable=True) - - def serialize(self): - serialized = { - "id": str(self.id), - "colour": self.colour, - "logo": self.logo, - "name": self.name, - } - - return serialized - - class EmailBranding(db.Model): __tablename__ = 'email_branding' id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) @@ -257,8 +238,6 @@ class Service(db.Model, Versioned): created_by = db.relationship('User') created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False) prefix_sms = db.Column(db.Boolean, nullable=False, default=True) - 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( db.String, db.ForeignKey('dvla_organisation.id'), diff --git a/app/schemas.py b/app/schemas.py index a79eddf57..49c4eb7b9 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -203,8 +203,6 @@ class ServiceSchema(BaseSchema): branding = field_for(models.Service, 'branding') dvla_organisation = field_for(models.Service, 'dvla_organisation') permissions = fields.Method("service_permissions") - # TODO: remove this variable after admin is updated to refer to email branding - organisation = field_for(models.Service, 'organisation') email_branding = field_for(models.Service, 'email_branding') override_flag = False reply_to_email_address = fields.Method(method_name="get_reply_to_email_address") @@ -285,8 +283,6 @@ class DetailedServiceSchema(BaseSchema): 'template_statistics', 'service_provider_stats', 'service_notification_stats', - # TODO: remove this field after admin is updated to refer to email branding - 'organisation', 'email_branding', 'service_sms_senders', 'monthly_billing', diff --git a/app/service/rest.py b/app/service/rest.py index f3d4d8ac3..cab1cb645 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -184,11 +184,6 @@ def update_service(service_id): if org_type: service.crown = org_type == 'central' - # TODO: remove this block after admin is updated to refer to email branding - if 'organisation' in req_json: - org_id = req_json['organisation'] - service.email_branding = None if not org_id else EmailBranding.query.get(org_id) - if 'email_branding' in req_json: email_branding_id = req_json['email_branding'] service.email_branding = None if not email_branding_id else EmailBranding.query.get(email_branding_id) diff --git a/tests/app/email_branding/test_rest.py b/tests/app/email_branding/test_rest.py index d624dd2dd..19294e5ab 100644 --- a/tests/app/email_branding/test_rest.py +++ b/tests/app/email_branding/test_rest.py @@ -1,11 +1,7 @@ -import json - import pytest from app.models import EmailBranding -from tests import create_authorization_header - def test_get_email_branding_options(admin_request, notify_db, notify_db_session): email_branding1 = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='Org1') @@ -25,29 +21,6 @@ def test_get_email_branding_options(admin_request, notify_db, notify_db_session) } -def test_get_email_branding_options_from_old_endpoint(client, notify_db, notify_db_session): - email_branding1 = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='Org1') - email_branding2 = EmailBranding(colour='#000000', logo='/path/other.png', name='Org2') - notify_db.session.add_all([email_branding1, email_branding2]) - notify_db.session.commit() - - response = client.get( - '/organisation', - headers=[create_authorization_header()] - ) - assert response.status_code == 200 - json_resp = json.loads(response.get_data(as_text=True)) - - email_branding = json_resp['organisations'] - - assert len(email_branding) == 2 - assert { - email_branding['id'] for email_branding in email_branding - } == { - str(email_branding1.id), str(email_branding2.id) - } - - def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session): email_branding = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='My Org') notify_db.session.add(email_branding) @@ -66,21 +39,6 @@ def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session): assert response['email_branding']['id'] == str(email_branding.id) -def test_get_email_branding_by_id_from_old_endpoint(client, notify_db, notify_db_session): - email_branding = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='My Org') - notify_db.session.add(email_branding) - notify_db.session.commit() - - response = client.get( - '/organisation/{}'.format(email_branding.id), - headers=[create_authorization_header()] - ) - assert response.status_code == 200 - json_resp = json.loads(response.get_data(as_text=True)) - - assert json_resp['organisation']['id'] == str(email_branding.id) - - def test_post_create_email_branding(admin_request, notify_db_session): data = { 'name': 'test email_branding', diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 9a30d7e17..7a0b81031 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -16,7 +16,6 @@ from app.models import ( EmailBranding, InboundNumber, Notification, - Organisation, Service, ServiceEmailReplyTo, ServiceLetterContact, @@ -134,7 +133,7 @@ def test_get_service_by_id(admin_request, sample_service): assert json_resp['data']['name'] == sample_service.name assert json_resp['data']['id'] == str(sample_service.id) assert not json_resp['data']['research_mode'] - assert json_resp['data']['organisation'] is None + assert json_resp['data']['email_branding'] is None assert json_resp['data']['branding'] == 'govuk' assert json_resp['data']['dvla_organisation'] == '001' assert json_resp['data']['sms_sender'] == current_app.config['FROM_NUMBER'] @@ -407,30 +406,17 @@ def test_create_service_should_throw_duplicate_key_constraint_for_existing_email def test_update_service(client, notify_db, sample_service): - org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League') - notify_db.session.add(org) - notify_db.session.commit() - # Need to set this up manually until org->email_branding migration is complete :( - brand = EmailBranding(id=org.id, colour='#000000', logo='justice-league.png', name='Justice League') + brand = EmailBranding(colour='#000000', logo='justice-league.png', name='Justice League') notify_db.session.add(brand) notify_db.session.commit() - auth_header = create_authorization_header() - resp = client.get( - '/service/{}'.format(sample_service.id), - headers=[auth_header] - ) - json_resp = json.loads(resp.get_data(as_text=True)) - assert resp.status_code == 200 - assert json_resp['data']['name'] == sample_service.name - assert json_resp['data']['organisation'] is None - assert json_resp['data']['email_branding'] is None + assert sample_service.email_branding is None data = { 'name': 'updated service name', 'email_from': 'updated.service.name', 'created_by': str(sample_service.created_by.id), - 'organisation': str(org.id), + 'email_branding': str(brand.id), 'dvla_organisation': DVLA_ORG_LAND_REGISTRY, 'organisation_type': 'foo', } @@ -446,46 +432,36 @@ def test_update_service(client, notify_db, sample_service): assert resp.status_code == 200 assert result['data']['name'] == 'updated service name' assert result['data']['email_from'] == 'updated.service.name' - assert result['data']['organisation'] == str(org.id) - assert result['data']['email_branding'] == str(org.id) + assert result['data']['email_branding'] == str(brand.id) assert result['data']['dvla_organisation'] == DVLA_ORG_LAND_REGISTRY assert result['data']['organisation_type'] == 'foo' -def test_update_service_remove_org(admin_request, notify_db, sample_service): - org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League') - notify_db.session.add(org) - notify_db.session.commit() - # Need to set this up manually until org->email_branding migration is complete :( - brand = EmailBranding(id=org.id, colour='#000000', logo='justice-league.png', name='Justice League') - sample_service.organisation = org +def test_update_service_remove_email_branding(admin_request, notify_db, sample_service): + brand = EmailBranding(colour='#000000', logo='justice-league.png', name='Justice League') sample_service.email_branding = brand notify_db.session.commit() - resp = admin_request.post('service.update_service', service_id=sample_service.id, _data={'organisation': None}) - assert resp['data']['organisation'] is None + resp = admin_request.post( + 'service.update_service', + service_id=sample_service.id, + _data={'email_branding': None} + ) assert resp['data']['email_branding'] is None -def test_update_service_change_org(admin_request, notify_db, sample_service): - org1 = Organisation(colour='#000000', logo='justice-league.png', name='Justice League') - org2 = Organisation(colour='#111111', logo='avengers.png', name='Avengers') - notify_db.session.add_all([org1, org2]) - notify_db.session.commit() - # Need to set this up manually until org->email_branding migration is complete :( - brand1 = EmailBranding(id=org1.id, colour='#000000', logo='justice-league.png', name='Justice League') - brand2 = EmailBranding(id=org2.id, colour='#111111', logo='avengers.png', name='Avengers') +def test_update_service_change_email_branding(admin_request, notify_db, sample_service): + brand1 = EmailBranding(colour='#000000', logo='justice-league.png', name='Justice League') + brand2 = EmailBranding(colour='#111111', logo='avengers.png', name='Avengers') notify_db.session.add_all([brand1, brand2]) - sample_service.organisation = org1 sample_service.email_branding = brand1 notify_db.session.commit() resp = admin_request.post( 'service.update_service', service_id=sample_service.id, - _data={'organisation': str(org2.id)} + _data={'email_branding': str(brand2.id)} ) - assert resp['data']['organisation'] == str(org2.id) assert resp['data']['email_branding'] == str(brand2.id)