From 3731dd876e253362cb0d979fba771536ca62e88f Mon Sep 17 00:00:00 2001 From: Montana Date: Mon, 7 Jan 2019 14:46:41 -0500 Subject: [PATCH] Display audit logs for current workspace --- atst/domain/audit_log.py | 9 +++++++++ atst/routes/workspaces/index.py | 10 ++++++++-- templates/workspaces/activity.html | 1 - templates/workspaces/activity/index.html | 23 +++++++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) delete mode 100644 templates/workspaces/activity.html create mode 100644 templates/workspaces/activity/index.html diff --git a/atst/domain/audit_log.py b/atst/domain/audit_log.py index 6dc42a50..0292920a 100644 --- a/atst/domain/audit_log.py +++ b/atst/domain/audit_log.py @@ -25,6 +25,15 @@ class AuditLog(object): ) return AuditEventQuery.get_all(pagination_opts) + @classmethod + def get_workspace_events(cls, workspace_id): + return ( + db.session.query(AuditEvent) + .filter(AuditEvent.workspace_id == workspace_id) + .order_by(AuditEvent.time_created.desc()) + .all() + ) + @classmethod def get_by_resource(cls, resource_id): return ( diff --git a/atst/routes/workspaces/index.py b/atst/routes/workspaces/index.py index 30e11ab1..cad5e5b2 100644 --- a/atst/routes/workspaces/index.py +++ b/atst/routes/workspaces/index.py @@ -5,8 +5,9 @@ from flask import render_template, request as http_request, g, redirect, url_for from . import workspaces_bp from atst.domain.reports import Reports from atst.domain.workspaces import Workspaces -from atst.forms.workspace import WorkspaceForm +from atst.domain.audit_log import AuditLog from atst.domain.authz import Authorization +from atst.forms.workspace import WorkspaceForm from atst.models.permissions import Permissions @@ -92,5 +93,10 @@ def workspace_activity(workspace_id): Permissions.VIEW_USAGE_DOLLARS, "view workspace reports", ) + audit_events = AuditLog.get_workspace_events(workspace_id) - return render_template("workspaces/activity.html", workspace_name=workspace.name) + return render_template( + "workspaces/activity/index.html", + workspace_name=workspace.name, + audit_events=audit_events, + ) diff --git a/templates/workspaces/activity.html b/templates/workspaces/activity.html deleted file mode 100644 index acd43b4e..00000000 --- a/templates/workspaces/activity.html +++ /dev/null @@ -1 +0,0 @@ -

Activity Log for Workspace {{workspace_name}}

diff --git a/templates/workspaces/activity/index.html b/templates/workspaces/activity/index.html new file mode 100644 index 00000000..08f2a583 --- /dev/null +++ b/templates/workspaces/activity/index.html @@ -0,0 +1,23 @@ +{% extends "workspaces/base.html" %} + +{% block workspace_content %} + +
+
+
+

{{ "audit_log.header_title" | translate }}

+
+ +
    + {% for event in audit_events %} +
  • + {% autoescape false %} + {{ event | renderAuditEvent }} + {% endautoescape %} +
  • + {% endfor %} +
+
+ +
+{% endblock %}