diff --git a/app/main/forms.py b/app/main/forms.py index d303b3673..60ee4df05 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -538,6 +538,20 @@ class ServiceBrandingOrg(Form): ) +class LetterBranding(Form): + + def __init__(self, choices=[], *args, **kwargs): + super().__init__(*args, **kwargs) + self.dvla_org_id.choices = choices + + dvla_org_id = RadioField( + 'Which logo should this service’s letter have?', + validators=[ + DataRequired() + ] + ) + + class Whitelist(Form): def populate(self, email_addresses, phone_numbers): diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index abc6dd620..d19abab1c 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -26,7 +26,8 @@ from app.main.forms import ( ServiceReplyToEmailFrom, ServiceSmsSender, ServiceLetterContactBlock, - ServiceBrandingOrg + ServiceBrandingOrg, + LetterBranding, ) from app import user_api_client, current_service, organisations_client @@ -35,13 +36,17 @@ from app import user_api_client, current_service, organisations_client @login_required @user_has_permissions('manage_settings', admin_override=True) def service_settings(service_id): + letter_branding_organisations = organisations_client.get_letter_organisations() if current_service['organisation']: organisation = organisations_client.get_organisation(current_service['organisation'])['organisation'] else: organisation = None return render_template( 'views/service-settings.html', - organisation=organisation + organisation=organisation, + letter_branding=letter_branding_organisations.get( + current_service.get('dvla_org_id', '001') + ) ) @@ -314,6 +319,28 @@ def service_set_branding_and_org(service_id): ) +@main.route("/services//service-settings/set-letter-branding", methods=['GET', 'POST']) +@login_required +@user_has_permissions(admin_override=True) +def set_letter_branding(service_id): + + form = LetterBranding(choices=organisations_client.get_letter_organisations().items()) + + if form.validate_on_submit(): + service_api_client.update_service( + service_id, + dvla_organisation=form.dvla_org_id.data + ) + return redirect(url_for('.service_settings', service_id=service_id)) + + form.dvla_org_id.data = current_service.get('dvla_organisation', '001') + + return render_template( + 'views/service-settings/set-letter-branding.html', + form=form, + ) + + def get_branding_as_value_and_label(organisations): return [ (organisation['id'], organisation['name']) diff --git a/app/notify_client/organisations_client.py b/app/notify_client/organisations_client.py index 58eb418f9..d18b9e66f 100644 --- a/app/notify_client/organisations_client.py +++ b/app/notify_client/organisations_client.py @@ -16,3 +16,6 @@ class OrganisationsClient(NotifyAdminAPIClient): def get_organisations(self): return self.get(url='/organisation')['organisations'] + + def get_letter_organisations(self): + return self.get(url='/dvla_organisations') diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 72d489a2d..d172176cd 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -91,7 +91,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): 'created_by', 'branding', 'organisation', - 'letter_contact_block' + 'letter_contact_block', + 'dvla_org_id', } if disallowed_attributes: raise TypeError('Not allowed to update service attributes: {}'.format( diff --git a/app/template_previews.py b/app/template_previews.py index e3b5adf6c..466b60a31 100644 --- a/app/template_previews.py +++ b/app/template_previews.py @@ -10,7 +10,8 @@ class TemplatePreview: data = { 'letter_contact_block': current_service['letter_contact_block'], 'template': template, - 'values': values + 'values': values, + 'dvla_org_id': current_service['dvla_organisation'], } resp = requests.post( '{}/preview.{}'.format(current_app.config['TEMPLATE_PREVIEW_API_HOST'], filetype), diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html index b25b93875..78f0db7a1 100644 --- a/app/templates/views/service-settings.html +++ b/app/templates/views/service-settings.html @@ -103,6 +103,11 @@ {% endcall %} {{ edit_field('Change', url_for('.service_set_branding_and_org', service_id=current_service.id)) }} {% endcall %} + {% call row() %} + {{ text_field('Letter branding')}} + {{ text_field(letter_branding) }} + {{ edit_field('Change', url_for('.set_letter_branding', service_id=current_service.id)) }} + {% endcall %} {% endcall %}