Skip to content

Commit

Permalink
EAS-2090 Remove Branding Code (#109)
Browse files Browse the repository at this point in the history
* initial check-in of branding code purge

* comment out objects for testing

* formatting updates due to flake8 and black upgrades

* remove commented-out code

* correct alembic version
  • Loading branch information
jonathan-owens-gds authored May 13, 2024
1 parent 042be65 commit 72a19fd
Show file tree
Hide file tree
Showing 51 changed files with 59 additions and 2,986 deletions.
10 changes: 0 additions & 10 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,11 @@ def register_blueprint(application):
from app.billing.rest import billing_blueprint
from app.broadcast_message.rest import broadcast_message_blueprint
from app.complaint.complaint_rest import complaint_blueprint
from app.email_branding.rest import email_branding_blueprint
from app.events.rest import events as events_blueprint
from app.feature_toggle.rest import feature_toggle_blueprint
from app.govuk_alerts.rest import govuk_alerts_blueprint
from app.inbound_number.rest import inbound_number_blueprint
from app.inbound_sms.rest import inbound_sms as inbound_sms_blueprint
from app.letter_branding.letter_branding_rest import (
letter_branding_blueprint,
)
from app.notifications.rest import notifications as notifications_blueprint
from app.organisation.invite_rest import organisation_invite_blueprint
from app.organisation.rest import organisation_blueprint
Expand Down Expand Up @@ -229,9 +225,6 @@ def register_blueprint(application):
provider_details_blueprint.before_request(requires_admin_auth)
application.register_blueprint(provider_details_blueprint, url_prefix="/provider-details")

email_branding_blueprint.before_request(requires_admin_auth)
application.register_blueprint(email_branding_blueprint, url_prefix="/email-branding")

billing_blueprint.before_request(requires_admin_auth)
application.register_blueprint(billing_blueprint)

Expand All @@ -253,9 +246,6 @@ def register_blueprint(application):
template_folder_blueprint.before_request(requires_admin_auth)
application.register_blueprint(template_folder_blueprint)

letter_branding_blueprint.before_request(requires_admin_auth)
application.register_blueprint(letter_branding_blueprint)

upload_blueprint.before_request(requires_admin_auth)
application.register_blueprint(upload_blueprint)

Expand Down
14 changes: 0 additions & 14 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
SMS_TYPE,
AnnualBilling,
Domain,
EmailBranding,
LetterBranding,
Notification,
Organisation,
Permission,
Expand Down Expand Up @@ -465,8 +463,6 @@ def populate_organisations_from_file(file_name):
# [2] crown:: TRUE | FALSE only
# [3] argeement_signed:: TRUE | FALSE
# [4] domains:: comma separated list of domains related to the organisation
# [5] email branding name: name of the default email branding for the org
# [6] letter branding name: name of the default letter branding for the org

# The expectation is that the organisation, organisation_to_service
# and user_to_organisation will be cleared before running this command.
Expand All @@ -484,22 +480,12 @@ def boolean_or_none(field):
for line in itertools.islice(f, 1, None):
columns = line.split("|")
print(columns)
email_branding = None
email_branding_column = columns[5].strip()
if len(email_branding_column) > 0:
email_branding = EmailBranding.query.filter(EmailBranding.name == email_branding_column).one()
letter_branding = None
letter_branding_column = columns[6].strip()
if len(letter_branding_column) > 0:
letter_branding = LetterBranding.query.filter(LetterBranding.name == letter_branding_column).one()
data = {
"name": columns[0],
"active": True,
"agreement_signed": boolean_or_none(columns[3]),
"crown": boolean_or_none(columns[2]),
"organisation_type": columns[1].lower(),
"email_branding_id": email_branding.id if email_branding else None,
"letter_branding_id": letter_branding.id if letter_branding else None,
}
org = Organisation(**data)
try:
Expand Down
42 changes: 0 additions & 42 deletions app/dao/email_branding_dao.py

This file was deleted.

29 changes: 0 additions & 29 deletions app/dao/letter_branding_dao.py

This file was deleted.

118 changes: 1 addition & 117 deletions app/dao/organisation_dao.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
from flask import current_app
from sqlalchemy import and_
from sqlalchemy.sql.expression import func

from app import db
from app.dao.dao_utils import VersionOptions, autocommit, version_class
from app.dao.email_branding_dao import dao_get_email_branding_by_id
from app.dao.letter_branding_dao import dao_get_letter_branding_by_id
from app.models import (
NHS_ORGANISATION_TYPES,
AnnualBilling,
Domain,
EmailBranding,
Organisation,
Service,
User,
)
from app.models import AnnualBilling, Domain, Organisation, Service, User
from app.utils import get_archived_db_column_value


Expand Down Expand Up @@ -79,17 +68,9 @@ def dao_get_organisation_by_service_id(service_id):

@autocommit
def dao_create_organisation(organisation):
if organisation.organisation_type in NHS_ORGANISATION_TYPES:
organisation.email_branding_id = current_app.config["NHS_EMAIL_BRANDING_ID"]
organisation.letter_branding_id = current_app.config["NHS_LETTER_BRANDING_ID"]

db.session.add(organisation)
db.session.commit()

if organisation.organisation_type in NHS_ORGANISATION_TYPES:
dao_add_email_branding_to_organisation_pool(organisation.id, organisation.email_branding_id)
dao_add_letter_branding_list_to_organisation_pool(organisation.id, [organisation.letter_branding_id])


@autocommit
def dao_update_organisation(organisation_id, **kwargs):
Expand All @@ -112,33 +93,9 @@ def dao_update_organisation(organisation_id, **kwargs):
if "crown" in kwargs:
_update_organisation_services(organisation, "crown", only_where_none=False)

if "email_branding_id" in kwargs:
_update_organisation_services(organisation, "email_branding")

if "letter_branding_id" in kwargs:
_update_organisation_services(organisation, "letter_branding")

_add_branding_to_branding_pool(organisation_id, kwargs)

return num_updated


def _add_branding_to_branding_pool(organisation_id, kwargs):
if kwargs.get("organisation_type") in NHS_ORGANISATION_TYPES:
# If we're setting the organisation_type to one of the NHS types we always want to add the NHS branding to the
# pool. This should happen regardless of whether we're changing the branding for the org.
dao_add_email_branding_to_organisation_pool(organisation_id, current_app.config["NHS_EMAIL_BRANDING_ID"])
dao_add_letter_branding_list_to_organisation_pool(
organisation_id, [current_app.config["NHS_LETTER_BRANDING_ID"]]
)
else:
if kwargs.get("email_branding_id"):
dao_add_email_branding_to_organisation_pool(organisation_id, kwargs["email_branding_id"])

if kwargs.get("letter_branding_id"):
dao_add_letter_branding_list_to_organisation_pool(organisation_id, [kwargs["letter_branding_id"]])


@version_class(
VersionOptions(Service, must_write_history=False),
)
Expand All @@ -153,9 +110,6 @@ def _update_organisation_services(organisation, attribute, only_where_none=True)
def dao_archive_organisation(organisation_id):
organisation = dao_get_organisation_by_id(organisation_id)

organisation.email_branding = None
organisation.letter_branding = None

Domain.query.filter_by(organisation_id=organisation_id).delete()

organisation.name = get_archived_db_column_value(organisation.name)
Expand Down Expand Up @@ -198,73 +152,3 @@ def dao_add_user_to_organisation(organisation_id, user_id):
@autocommit
def dao_remove_user_from_organisation(organisation, user):
organisation.users.remove(user)


@autocommit
def dao_add_email_branding_to_organisation_pool(organisation_id, email_branding_id):
organisation = dao_get_organisation_by_id(organisation_id)
email_branding = EmailBranding.query.filter_by(id=email_branding_id).one()
organisation.email_branding_pool.append(email_branding)
db.session.add(organisation)
return email_branding


@autocommit
def dao_add_email_branding_list_to_organisation_pool(organisation_id, email_branding_ids):
organisation = dao_get_organisation_by_id(organisation_id)
email_brandings = [dao_get_email_branding_by_id(branding_id) for branding_id in email_branding_ids]

organisation.email_branding_pool.extend(email_brandings)


def dao_get_email_branding_pool_for_organisation(organisation_id):
return (
db.session.query(EmailBranding)
.join(EmailBranding.organisations)
.filter(
Organisation.id == organisation_id,
)
.order_by(EmailBranding.name)
.all()
)


@autocommit
def dao_remove_email_branding_from_organisation_pool(organisation_id, email_branding_id):
organisation = dao_get_organisation_by_id(organisation_id)
email_branding = EmailBranding.query.filter_by(id=email_branding_id).one()

if organisation.email_branding_id == email_branding_id:
from app.errors import InvalidRequest

raise InvalidRequest("You cannot remove an organisation's default email branding", status_code=400)

organisation.email_branding_pool.remove(email_branding)
db.session.add(organisation)
return email_branding


def dao_get_letter_branding_pool_for_organisation(organisation_id):
organisation = dao_get_organisation_by_id(organisation_id)

return sorted(organisation.letter_branding_pool, key=lambda x: x.name)


@autocommit
def dao_add_letter_branding_list_to_organisation_pool(organisation_id, letter_branding_ids):
organisation = dao_get_organisation_by_id(organisation_id)
letter_brandings = [dao_get_letter_branding_by_id(branding_id) for branding_id in letter_branding_ids]

organisation.letter_branding_pool.extend(letter_brandings)

db.session.add(organisation)


@autocommit
def dao_remove_letter_branding_from_organisation_pool(organisation_id, letter_branding_id):
organisation = dao_get_organisation_by_id(organisation_id)
letter_branding = dao_get_letter_branding_by_id(letter_branding_id)

organisation.letter_branding_pool.remove(letter_branding)

return letter_branding
14 changes: 0 additions & 14 deletions app/dao/services_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from app import db
from app.dao.dao_utils import VersionOptions, autocommit, version_class
from app.dao.date_util import get_current_financial_year
from app.dao.email_branding_dao import dao_get_email_branding_by_name
from app.dao.letter_branding_dao import dao_get_letter_branding_by_name
from app.dao.organisation_dao import dao_get_organisation_by_email_address
from app.dao.service_sms_sender_dao import insert_service_sms_sender
from app.dao.service_user_dao import dao_get_service_user
Expand All @@ -23,7 +21,6 @@
INTERNATIONAL_SMS_TYPE,
KEY_TYPE_TEST,
LETTER_TYPE,
NHS_ORGANISATION_TYPES,
NON_CROWN_ORGANISATION_TYPES,
NOTIFICATION_PERMANENT_FAILURE,
SMS_TYPE,
Expand Down Expand Up @@ -51,7 +48,6 @@
VerifyCode,
)
from app.utils import (
email_address_is_nhs,
escape_special_characters,
get_archived_db_column_value,
get_london_midnight_in_utc,
Expand Down Expand Up @@ -316,16 +312,6 @@ def dao_create_service(
service.organisation_id = organisation.id
service.organisation_type = organisation.organisation_type

if organisation.email_branding:
service.email_branding = organisation.email_branding

if organisation.letter_branding:
service.letter_branding = organisation.letter_branding

elif service.organisation_type in NHS_ORGANISATION_TYPES 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")

if organisation:
service.crown = organisation.crown
elif service.organisation_type in CROWN_ORGANISATION_TYPES:
Expand Down
Loading

0 comments on commit 72a19fd

Please sign in to comment.