Munge stuff into a consistent event data type

We store our audit history in two ways:

  1. A list of versions of a service
  2. A list of events to do with API keys

In the future there could be auditing data which we want to display that
is stored in other formats (for example the event table).

This commit adds some objects which wrap around the different types of
auditing data, and expose a consistent interface to them. This
architecture will let us:
- write clean code in the presentation layer to display these events on
  a page
- add more types of events in the future by subclassing the `Event` data
  type, without having to rewrite anything in the presentation layer
This commit is contained in:
Chris Hill-Scott
2019-10-18 16:09:39 +01:00
parent 055f000020
commit 59b4d60c91
11 changed files with 367 additions and 121 deletions

View File

@@ -1,3 +1,5 @@
from operator import attrgetter
from flask import Markup, abort, current_app
from notifications_utils.field import Field
from notifications_utils.formatters import nl2br
@@ -5,6 +7,7 @@ from notifications_utils.take import Take
from werkzeug.utils import cached_property
from app.models import JSONModel
from app.models.event import APIKeyEvents, ServiceEvents
from app.models.organisation import Organisation
from app.models.user import InvitedUsers, User, Users
from app.notify_client.api_key_api_client import api_key_api_client
@@ -632,6 +635,9 @@ class Service(JSONModel):
if test:
yield BASE + '_incomplete' + tag
@cached_property
@property
def history(self):
return service_api_client.get_service_history(self.id)['data']
return sorted(
ServiceEvents(self.id) + APIKeyEvents(self.id),
key=attrgetter('time'),
)