Add display_name property to AuditEvent
This commit is contained in:
parent
870929afd6
commit
85d866956b
@ -24,6 +24,7 @@ def upgrade():
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('resource_type', sa.String(), nullable=False),
|
||||
sa.Column('display_name', sa.String(), nullable=True),
|
||||
sa.Column('resource_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('action', sa.String(), nullable=False),
|
||||
sa.Column('workspace_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
|
@ -19,21 +19,19 @@ class AuditEvent(Base, TimestampsMixin):
|
||||
|
||||
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)
|
||||
|
||||
def __str__(self):
|
||||
full_action = "{} on {} {}".format(
|
||||
|
||||
user_str = "{} performed".format(self.user.full_name) if self.user else "ATAT System"
|
||||
action_str = "{} on {} {}".format(
|
||||
self.action, self.resource_type, self.resource_id
|
||||
)
|
||||
display_name_str = "({})".format(self.display_name) if self.display_name else ""
|
||||
workspace_str = "in workspace {}".format(self.workspace_id) if self.workspace_id else ""
|
||||
|
||||
if self.user and self.workspace:
|
||||
return "{} performed {} in workspace {}".format(
|
||||
self.user.full_name, full_action, self.workspace_id
|
||||
)
|
||||
if self.user:
|
||||
return "{} performed {}".format(self.user.full_name, full_action)
|
||||
else:
|
||||
return "ATAT System performed {}".format(full_action)
|
||||
return " ".join([user_str, action_str, display_name_str, workspace_str])
|
||||
|
||||
def save(self, connection):
|
||||
attrs = inspect(self).dict
|
||||
|
@ -27,12 +27,14 @@ class AuditableMixin(object):
|
||||
user_id = getattr_path(g, "current_user.id")
|
||||
workspace_id = resource.auditable_workspace_id()
|
||||
resource_type = resource.auditable_resource_type()
|
||||
display_name = resource.auditable_displayname()
|
||||
|
||||
audit_event = AuditEvent(
|
||||
user_id=user_id,
|
||||
workspace_id=workspace_id,
|
||||
resource_type=resource_type,
|
||||
resource_id=resource.id,
|
||||
display_name=display_name,
|
||||
action=action,
|
||||
)
|
||||
|
||||
@ -63,3 +65,6 @@ class AuditableMixin(object):
|
||||
|
||||
def auditable_workspace_id(self):
|
||||
return getattr_path(self, "workspace.id")
|
||||
|
||||
def auditable_displayname(self):
|
||||
return getattr_path(self, "displayname")
|
||||
|
Loading…
x
Reference in New Issue
Block a user