add redact to notification with template schema.

So that when the admin gets notifications, the template they return
also has a "redact_personalisation" boolean attached to it. Note, it
won't do the redacting on the api - that'll be part of the admin.

Under the hood, this uses an association_proxy, which is essentially
black magic. But it proxies the `redact_personalisation` property of
`TemplateRedacted` onto the `Template` object, so that Marshmallow
can pick it up.

Note: NOT currently added to NotificationWithTemplateHistory
This commit is contained in:
Leo Hemsted
2017-06-28 16:10:22 +01:00
parent 29fc81090e
commit bd71ee9d02
3 changed files with 44 additions and 2 deletions

View File

@@ -443,6 +443,8 @@ class Template(db.Model):
default=NORMAL
)
redact_personalisation = association_proxy('template_redacted', 'redact_personalisation')
def get_link(self):
# TODO: use "/v2/" route once available
return url_for(

View File

@@ -297,6 +297,11 @@ class BaseTemplateSchema(BaseSchema):
strict = True
class TemplateRedactedSchema(BaseSchema):
class Meta:
model = models.TemplateRedacted
class TemplateSchema(BaseTemplateSchema):
created_by = field_for(models.Template, 'created_by', required=True)
@@ -440,7 +445,7 @@ class NotificationWithTemplateSchema(BaseSchema):
template = fields.Nested(
TemplateSchema,
only=['id', 'version', 'name', 'template_type', 'content', 'subject'],
only=['id', 'version', 'name', 'template_type', 'content', 'subject', 'redact_personalisation'],
dump_only=True
)
job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)