"""Record event log message.""" from auditlogger.event import Event class RecordEvent(Event): """Represent a record event.""" RECORD_EVENTS = ["create", "update", "delete"] ES_INDEX = "record-event" OS_INDEX = "record_event" def __init__(self, target_type, target_id, event_name, changeset, user_type, user_id): """Return the event. Args: target_type (str): The name of the model. target_id (str): The ID for the model. event_name (str): One of the known record events. changeset (dict): A dict containing dicts under the keys "original" and "updated". user_type (str): The type of user. user_id (str): The unique ID of the user of this type. """ if event_name not in self.RECORD_EVENTS: raise Exception("unexpected record event: {}".format(event_name)) super().__init__() self.data["target_type"] = target_type self.data["target_id"] = target_id self.data["event_name"] = event_name self.data["changeset"] = changeset self.data["user_type"] = user_type self.data["user_id"] = user_id