mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
Move branding choices logic into utility module
This was a lot of code to be in a form and it's going to get even more complicated with email branding pools. Moving it out means we can also simplify the tests that target this code.
This commit is contained in:
@@ -67,7 +67,7 @@ from app.main.validators import (
|
||||
)
|
||||
from app.models.feedback import PROBLEM_TICKET_TYPE, QUESTION_TICKET_TYPE
|
||||
from app.models.organisation import Organisation
|
||||
from app.utils import merge_jsonlike
|
||||
from app.utils import branding, merge_jsonlike
|
||||
from app.utils.user import distinct_email_addresses
|
||||
from app.utils.user_permissions import (
|
||||
all_ui_permissions,
|
||||
@@ -2198,57 +2198,10 @@ class ChooseBrandingForm(StripWhitespaceForm):
|
||||
|
||||
@staticmethod
|
||||
def get_available_choices(service, branding_type):
|
||||
if branding_type == "email":
|
||||
organisation_branding_id = service.organisation.email_branding_id if service.organisation else None
|
||||
service_branding_id = service.email_branding_id
|
||||
service_branding_name = service.email_branding_name
|
||||
elif branding_type == "letter":
|
||||
organisation_branding_id = service.organisation.letter_branding_id if service.organisation else None
|
||||
service_branding_id = service.letter_branding_id
|
||||
service_branding_name = service.letter_branding_name
|
||||
|
||||
if (
|
||||
service.organisation_type == Organisation.TYPE_CENTRAL
|
||||
and organisation_branding_id is None
|
||||
and service_branding_id is not None
|
||||
and branding_type == "email"
|
||||
):
|
||||
yield ('govuk', 'GOV.UK')
|
||||
|
||||
if (
|
||||
service.organisation_type == Organisation.TYPE_CENTRAL
|
||||
and service.organisation
|
||||
and organisation_branding_id is None
|
||||
and service_branding_name.lower() != 'GOV.UK and {}'.format(service.organisation.name).lower()
|
||||
and branding_type == "email"
|
||||
):
|
||||
yield ('govuk_and_org', 'GOV.UK and {}'.format(service.organisation.name))
|
||||
|
||||
if (
|
||||
service.organisation_type in {
|
||||
Organisation.TYPE_NHS_CENTRAL,
|
||||
Organisation.TYPE_NHS_LOCAL,
|
||||
Organisation.TYPE_NHS_GP,
|
||||
}
|
||||
and service_branding_name != 'NHS'
|
||||
):
|
||||
yield ('nhs', 'NHS')
|
||||
|
||||
if (
|
||||
service.organisation
|
||||
and service.organisation_type not in {
|
||||
Organisation.TYPE_NHS_LOCAL,
|
||||
Organisation.TYPE_NHS_CENTRAL,
|
||||
Organisation.TYPE_NHS_GP,
|
||||
}
|
||||
and (
|
||||
service_branding_id is None
|
||||
or service_branding_id != organisation_branding_id
|
||||
)
|
||||
):
|
||||
yield ('organisation', service.organisation.name)
|
||||
|
||||
yield ChooseBrandingForm.FALLBACK_OPTION
|
||||
return (
|
||||
list(branding.get_available_choices(service, branding_type)) +
|
||||
[ChooseBrandingForm.FALLBACK_OPTION]
|
||||
)
|
||||
|
||||
@property
|
||||
def something_else_is_only_option(self):
|
||||
|
||||
53
app/utils/branding.py
Normal file
53
app/utils/branding.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from app.models.organisation import Organisation
|
||||
|
||||
|
||||
def get_available_choices(service, branding_type):
|
||||
if branding_type == "email":
|
||||
organisation_branding_id = service.organisation.email_branding_id if service.organisation else None
|
||||
service_branding_id = service.email_branding_id
|
||||
service_branding_name = service.email_branding_name
|
||||
elif branding_type == "letter":
|
||||
organisation_branding_id = service.organisation.letter_branding_id if service.organisation else None
|
||||
service_branding_id = service.letter_branding_id
|
||||
service_branding_name = service.letter_branding_name
|
||||
|
||||
if (
|
||||
service.organisation_type == Organisation.TYPE_CENTRAL
|
||||
and organisation_branding_id is None
|
||||
and service_branding_id is not None
|
||||
and branding_type == "email"
|
||||
):
|
||||
yield ('govuk', 'GOV.UK')
|
||||
|
||||
if (
|
||||
service.organisation_type == Organisation.TYPE_CENTRAL
|
||||
and service.organisation
|
||||
and organisation_branding_id is None
|
||||
and service_branding_name.lower() != 'GOV.UK and {}'.format(service.organisation.name).lower()
|
||||
and branding_type == "email"
|
||||
):
|
||||
yield ('govuk_and_org', 'GOV.UK and {}'.format(service.organisation.name))
|
||||
|
||||
if (
|
||||
service.organisation_type in {
|
||||
Organisation.TYPE_NHS_CENTRAL,
|
||||
Organisation.TYPE_NHS_LOCAL,
|
||||
Organisation.TYPE_NHS_GP,
|
||||
}
|
||||
and service_branding_name != 'NHS'
|
||||
):
|
||||
yield ('nhs', 'NHS')
|
||||
|
||||
if (
|
||||
service.organisation
|
||||
and service.organisation_type not in {
|
||||
Organisation.TYPE_NHS_LOCAL,
|
||||
Organisation.TYPE_NHS_CENTRAL,
|
||||
Organisation.TYPE_NHS_GP,
|
||||
}
|
||||
and (
|
||||
service_branding_id is None
|
||||
or service_branding_id != organisation_branding_id
|
||||
)
|
||||
):
|
||||
yield ('organisation', service.organisation.name)
|
||||
Reference in New Issue
Block a user