Add application_id column to AuditEvent

Use application_id and portfolio_id if the resource is a portfolio in AuditableMixin
Clean up some residual references to workspace
This commit is contained in:
leigh-mil
2019-05-15 18:14:26 -04:00
parent 42900a20a6
commit b3ecd1658c
5 changed files with 83 additions and 11 deletions

View File

@@ -17,11 +17,17 @@ class AuditEvent(Base, TimestampsMixin):
portfolio_id = Column(UUID(as_uuid=True), ForeignKey("portfolios.id"), index=True)
portfolio = relationship("Portfolio", backref="audit_events")
application_id = Column(
UUID(as_uuid=True), ForeignKey("applications.id"), index=True
)
application = relationship("Application", backref="audit_events")
changed_state = Column(JSONB())
event_details = Column(JSONB())
resource_type = Column(String(), nullable=False)
resource_id = Column(UUID(as_uuid=True), index=True, nullable=False)
display_name = Column(String())
action = Column(String(), nullable=False)
@@ -29,6 +35,7 @@ class AuditEvent(Base, TimestampsMixin):
def log(self):
return {
"portfolio_id": str(self.portfolio_id),
"application_id": str(self.application_id),
"changed_state": self.changed_state,
"event_details": self.event_details,
"resource_type": self.resource_type,

View File

@@ -13,17 +13,27 @@ class AuditableMixin(object):
@staticmethod
def create_audit_event(connection, resource, action, changed_state=None):
user_id = getattr_path(g, "current_user.id")
portfolio_id = resource.portfolio_id
resource_type = resource.resource_type
display_name = resource.displayname
event_details = resource.event_details
if resource_type == "portfolio":
portfolio_id = resource.id
else:
portfolio_id = resource.portfolio_id
if resource_type == "application":
application_id = resource.id
else:
application_id = resource.application_id
if changed_state is None:
changed_state = resource.history if action == ACTION_UPDATE else None
audit_event = AuditEvent(
user_id=user_id,
portfolio_id=portfolio_id,
application_id=application_id,
resource_type=resource_type,
resource_id=resource.id,
display_name=display_name,
@@ -95,6 +105,10 @@ class AuditableMixin(object):
def portfolio_id(self):
return None
@property
def application_id(self):
return None
@property
def displayname(self):
return None