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:
|
if changed_state is None:
|
||||||
changed_state = resource.history if action == ACTION_UPDATE else None
|
changed_state = resource.history if action == ACTION_UPDATE else None
|
||||||
|
|
||||||
audit_event = AuditEvent(
|
log_data = {
|
||||||
user_id=user_id,
|
"user_id": user_id,
|
||||||
portfolio_id=resource.portfolio_id,
|
"portfolio_id": resource.portfolio_id,
|
||||||
application_id=resource.application_id,
|
"application_id": resource.application_id,
|
||||||
resource_type=resource.resource_type,
|
"resource_type": resource.resource_type,
|
||||||
resource_id=resource.id,
|
"resource_id": resource.id,
|
||||||
display_name=resource.displayname,
|
"display_name": resource.displayname,
|
||||||
action=action,
|
"action": action,
|
||||||
changed_state=changed_state,
|
"changed_state": changed_state,
|
||||||
event_details=resource.event_details,
|
"event_details": resource.event_details,
|
||||||
)
|
}
|
||||||
|
|
||||||
app.logger.info(
|
app.logger.info(
|
||||||
"Audit Event {}".format(action),
|
"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)
|
audit_event.save(connection)
|
||||||
return audit_event
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __declare_last__(cls):
|
def __declare_last__(cls):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user