mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-02 15:11:13 -04:00
Refactor organisation branding into model
This is the same way we handle lazy-loading the branding in the service model.
This commit is contained in:
@@ -222,25 +222,8 @@ def cancel_invited_org_user(org_id, invited_user_id):
|
||||
@main.route("/organisations/<org_id>/settings/", methods=['GET'])
|
||||
@user_is_platform_admin
|
||||
def organisation_settings(org_id):
|
||||
|
||||
email_branding = 'GOV.UK'
|
||||
|
||||
if current_organisation.email_branding_id:
|
||||
email_branding = email_branding_client.get_email_branding(
|
||||
current_organisation.email_branding_id
|
||||
)['email_branding']['name']
|
||||
|
||||
letter_branding = None
|
||||
|
||||
if current_organisation.letter_branding_id:
|
||||
letter_branding = letter_branding_client.get_letter_branding(
|
||||
current_organisation.letter_branding_id
|
||||
)['name']
|
||||
|
||||
return render_template(
|
||||
'views/organisations/organisation/settings/index.html',
|
||||
email_branding=email_branding,
|
||||
letter_branding=letter_branding,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ from flask import abort
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel, ModelList
|
||||
from app.notify_client.email_branding_client import email_branding_client
|
||||
from app.notify_client.letter_branding_client import letter_branding_client
|
||||
from app.notify_client.organisations_api_client import organisations_client
|
||||
|
||||
|
||||
@@ -148,6 +150,26 @@ class Organisation(JSONModel):
|
||||
key=lambda user: user.email_address.lower(),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def email_branding(self):
|
||||
if self.email_branding_id:
|
||||
return email_branding_client.get_email_branding(
|
||||
self.email_branding_id
|
||||
)['email_branding']
|
||||
|
||||
@property
|
||||
def email_branding_name(self):
|
||||
if self.email_branding_id:
|
||||
return self.email_branding['name']
|
||||
return 'GOV.UK'
|
||||
|
||||
@cached_property
|
||||
def letter_branding(self):
|
||||
if self.letter_branding_id:
|
||||
return letter_branding_client.get_letter_branding(
|
||||
self.letter_branding_id
|
||||
)
|
||||
|
||||
def update(self, **kwargs):
|
||||
response = organisations_client.update_organisation(self.id, **kwargs)
|
||||
self.__init__(response)
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
{% endcall %}
|
||||
{% call row() %}
|
||||
{{ text_field('Default email branding') }}
|
||||
{{ text_field(email_branding) }}
|
||||
{{ text_field(current_org.email_branding_name) }}
|
||||
{{ edit_field(
|
||||
'Change',
|
||||
url_for('.edit_organisation_email_branding', org_id=current_org.id)
|
||||
@@ -83,7 +83,7 @@
|
||||
{% call row() %}
|
||||
{{ text_field('Default letter branding') }}
|
||||
{{ optional_text_field(
|
||||
letter_branding,
|
||||
current_org.letter_branding.name,
|
||||
default='No branding'
|
||||
) }}
|
||||
{{ edit_field(
|
||||
|
||||
Reference in New Issue
Block a user