mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Fix automatic inheritance of org’s branding
When creating a service it should inherit it’s organisation’s branding, if that organisation has branding. This wasn’t working because we were referring to the ID of the branding when making the association, not the branding itself.
This commit is contained in:
@@ -194,11 +194,11 @@ def dao_create_service(
|
||||
|
||||
service.organisation = organisation
|
||||
|
||||
if organisation.email_branding_id:
|
||||
service.email_branding = organisation.email_branding_id
|
||||
if organisation.email_branding:
|
||||
service.email_branding = organisation.email_branding
|
||||
|
||||
if organisation.letter_branding_id and not service.letter_branding:
|
||||
service.letter_branding = organisation.letter_branding_id
|
||||
if organisation.letter_branding and not service.letter_branding:
|
||||
service.letter_branding = organisation.letter_branding
|
||||
|
||||
db.session.add(service)
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ from tests.app.db import (
|
||||
create_letter_branding,
|
||||
create_organisation,
|
||||
create_domain,
|
||||
create_email_branding,
|
||||
)
|
||||
from tests.app.db import create_user
|
||||
|
||||
@@ -306,6 +307,37 @@ def test_create_service_with_domain_sets_organisation(
|
||||
assert json_resp['data']['organisation'] is None
|
||||
|
||||
|
||||
def test_create_service_inherits_branding_from_organisation(
|
||||
admin_request,
|
||||
sample_user,
|
||||
):
|
||||
|
||||
org = create_organisation()
|
||||
email_branding = create_email_branding()
|
||||
org.email_branding = email_branding
|
||||
letter_branding = create_letter_branding()
|
||||
org.letter_branding = letter_branding
|
||||
create_domain('example.gov.uk', org.id)
|
||||
sample_user.email_address = 'test@example.gov.uk'
|
||||
|
||||
json_resp = admin_request.post(
|
||||
'service.create_service',
|
||||
_data={
|
||||
'name': 'created service',
|
||||
'user_id': str(sample_user.id),
|
||||
'message_limit': 1000,
|
||||
'restricted': False,
|
||||
'active': False,
|
||||
'email_from': 'created.service',
|
||||
'created_by': str(sample_user.id),
|
||||
},
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
assert json_resp['data']['email_branding'] == str(email_branding.id)
|
||||
assert json_resp['data']['letter_branding'] == str(letter_branding.id)
|
||||
|
||||
|
||||
def test_create_service_with_domain_sets_letter_branding(admin_request, sample_user):
|
||||
letter_branding = create_letter_branding(
|
||||
name='test domain', filename='test-domain', domain='test.domain'
|
||||
|
||||
Reference in New Issue
Block a user