Add details of API key to notifications

We want to show developers a log of notifications they’ve sent using the
API in the admin app. In order to indentify a notification it’s probably
helpful to know:

- who the notification was sent to (which we expose)
- when the notification was created (which we expose)
- which key was used to create the notification (which we expose, but
  only as the `id` of the key)

Developers don’t see the `id` of the API key in the app anywhere, so
this isn’t useful information. Much more useful is the `type` and `name`
of the key. So this commit changes the schema to also return these.

This commit does some slightly hacky stuff with conftest because it
breaks a lot of other tests if the sample notification has a real API
key or an API key with a non-unique name.
This commit is contained in:
Chris Hill-Scott
2016-09-23 14:44:15 +01:00
parent e757c6463c
commit 130f42fed2
3 changed files with 38 additions and 2 deletions

View File

@@ -315,6 +315,16 @@ class NotificationWithTemplateSchema(BaseSchema):
)
job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)
personalisation = fields.Dict(required=False)
key_type = field_for(models.Notification, 'key_type', required=True)
key_name = fields.String()
@pre_dump
def add_api_key_name(self, in_data):
if in_data.api_key:
in_data.key_name = in_data.api_key.name
else:
in_data.key_name = None
return in_data
class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema):