edit create_audit_event method of AuditableMixin
- create dictonary of log data and log it. Only create insance of AuditEvent if AUDIT_LOG_FEATURE_TOGGLE is set to True
This commit is contained in:
parent
2720240903
commit
1ac9243749
@ -17,24 +17,29 @@ class AuditableMixin(object):
|
||||
if changed_state is None:
|
||||
changed_state = resource.history if action == ACTION_UPDATE else None
|
||||
|
||||
audit_event = AuditEvent(
|
||||
user_id=user_id,
|
||||
portfolio_id=resource.portfolio_id,
|
||||
application_id=resource.application_id,
|
||||
resource_type=resource.resource_type,
|
||||
resource_id=resource.id,
|
||||
display_name=resource.displayname,
|
||||
action=action,
|
||||
changed_state=changed_state,
|
||||
event_details=resource.event_details,
|
||||
)
|
||||
log_data = {
|
||||
"user_id": user_id,
|
||||
"portfolio_id": resource.portfolio_id,
|
||||
"application_id": resource.application_id,
|
||||
"resource_type": resource.resource_type,
|
||||
"resource_id": resource.id,
|
||||
"display_name": resource.displayname,
|
||||
"action": action,
|
||||
"changed_state": changed_state,
|
||||
"event_details": resource.event_details,
|
||||
}
|
||||
|
||||
app.logger.info(
|
||||
"Audit Event {}".format(action),
|
||||
extra={"audit_event": audit_event.log, "tags": ["audit_event", action]},
|
||||
extra={
|
||||
"audit_event": {key: str(value) for key, value in log_data.items()},
|
||||
"tags": ["audit_event", action],
|
||||
},
|
||||
)
|
||||
|
||||
if app.config.get("AUDIT_LOG_FEATURE_TOGGLE", False):
|
||||
audit_event = AuditEvent(**log_data)
|
||||
audit_event.save(connection)
|
||||
return audit_event
|
||||
|
||||
@classmethod
|
||||
def __declare_last__(cls):
|
||||
|
Loading…
x
Reference in New Issue
Block a user