Merge pull request #2908 from alphagov/fix-template-history-created-by

Fix template history created by
This commit is contained in:
Chris Hill-Scott
2020-06-29 13:12:44 +01:00
committed by GitHub
2 changed files with 15 additions and 6 deletions

View File

@@ -356,9 +356,7 @@ class BaseTemplateSchema(BaseSchema):
class TemplateSchema(BaseTemplateSchema, UUIDsAsStringsMixin):
created_by_id = field_for(
models.Template, 'created_by_id', dump_to='created_by', dump_only=True
)
created_by = field_for(models.Template, 'created_by', required=True)
process_type = field_for(models.Template, 'process_type')
redact_personalisation = fields.Method("redact")
@@ -372,9 +370,6 @@ class TemplateSchema(BaseTemplateSchema, UUIDsAsStringsMixin):
if not subject or subject.strip() == '':
raise ValidationError('Invalid template subject', 'subject')
class Meta(BaseTemplateSchema.Meta):
exclude = BaseTemplateSchema.Meta.exclude + ('created_by',)
class TemplateSchemaNoDetail(TemplateSchema):
class Meta(TemplateSchema.Meta):
@@ -382,6 +377,7 @@ class TemplateSchemaNoDetail(TemplateSchema):
'archived',
'content',
'created_at',
'created_by',
'created_by_id',
'hidden',
'postage',

View File

@@ -340,8 +340,13 @@ def test_must_have_a_subject_on_an_email_or_letter_template(client, sample_user,
def test_update_should_update_a_template(client, sample_user):
service = create_service(service_permissions=[LETTER_TYPE])
template = create_template(service, template_type="letter", postage="second")
assert template.created_by == service.created_by
assert template.created_by != sample_user
data = {
'content': 'my template has new content, swell!',
'created_by': str(sample_user.id),
@@ -366,6 +371,14 @@ def test_update_should_update_a_template(client, sample_user):
assert update_json_resp['data']['template_type'] == template.template_type
assert update_json_resp['data']['version'] == 2
assert update_json_resp['data']['created_by'] == str(sample_user.id)
assert [
template.created_by_id for template in TemplateHistory.query.all()
] == [
service.created_by.id,
sample_user.id,
]
def test_should_be_able_to_archive_template(client, sample_template):
data = {