Skip to content

Commit 5e061aa

Browse files
knuttiesayushjain17
authored andcommitted
feat: add audit log UI with filters
1 parent 083e1df commit 5e061aa

6 files changed

Lines changed: 772 additions & 6 deletions

File tree

crates/frontend/src/api.rs

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ use superposition_types::{
2323
workspace::{CreateWorkspaceRequest, UpdateWorkspaceRequest, WorkspaceResponse},
2424
},
2525
custom_query::{DimensionQuery, PaginationParams, QueryMap, QueryParam},
26-
database::models::{
27-
cac::{Context, DefaultConfig, Function, TypeTemplate},
28-
experimentation::ExperimentGroup,
29-
others::{CustomHeaders, HttpMethod, PayloadVersion, Webhook, WebhookEvent},
30-
ChangeReason, Description, Metrics, NonEmptyString, WorkspaceStatus,
26+
database::{
27+
models::{
28+
cac::{ConfigVersion, Context, DefaultConfig, EventLog, Function, TypeTemplate},
29+
experimentation::ExperimentGroup,
30+
others::{CustomHeaders, HttpMethod, PayloadVersion, Webhook, WebhookEvent},
31+
ChangeReason, Description, Metrics, NonEmptyString, WorkspaceStatus
32+
},
33+
types::DimensionWithMandatory,
3134
},
3235
Config, PaginatedResponse,
3336
};
@@ -1116,3 +1119,64 @@ pub mod experiment_groups {
11161119
parse_json_response(response).await
11171120
}
11181121
}
1122+
1123+
pub async fn fetch_audit_logs(
1124+
filters: &crate::pages::audit_log::filter::AuditLogFilters,
1125+
pagination: &PaginationParams,
1126+
tenant: String,
1127+
org_id: String,
1128+
) -> Result<PaginatedResponse<EventLog>, ServerFnError> {
1129+
let client = reqwest::Client::new();
1130+
let host = use_host_server();
1131+
1132+
let mut query_params = vec![];
1133+
1134+
// Add pagination params
1135+
if let Some(page) = pagination.page {
1136+
query_params.push(format!("page={}", page));
1137+
}
1138+
if let Some(count) = pagination.count {
1139+
query_params.push(format!("count={}", count));
1140+
}
1141+
1142+
// Add filter params
1143+
if let Some(from_date) = filters.from_date {
1144+
query_params.push(format!("from_date={}", from_date.to_rfc3339()));
1145+
}
1146+
if let Some(to_date) = filters.to_date {
1147+
query_params.push(format!("to_date={}", to_date.to_rfc3339()));
1148+
}
1149+
if let Some(username) = &filters.username {
1150+
query_params.push(format!("username={}", username));
1151+
}
1152+
if let Some(tables) = &filters.table {
1153+
for table in &tables.0 {
1154+
query_params.push(format!("table={}", table));
1155+
}
1156+
}
1157+
if let Some(actions) = &filters.action {
1158+
for action in &actions.0 {
1159+
query_params.push(format!("action={}", action));
1160+
}
1161+
}
1162+
1163+
let query_string = query_params.join("&");
1164+
let url = if query_string.is_empty() {
1165+
format!("{}/audit", host)
1166+
} else {
1167+
format!("{}/audit?{}", host, query_string)
1168+
};
1169+
1170+
let response: PaginatedResponse<EventLog> = client
1171+
.get(url)
1172+
.header("x-tenant", &tenant)
1173+
.header("x-org-id", org_id)
1174+
.send()
1175+
.await
1176+
.map_err(|e| ServerFnError::new(e.to_string()))?
1177+
.json()
1178+
.await
1179+
.map_err(|e| ServerFnError::new(e.to_string()))?;
1180+
1181+
Ok(response)
1182+
}

crates/frontend/src/app.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::pages::function::{
1616
function_create::CreateFunctionView, function_list::FunctionList, FunctionPage,
1717
};
1818
use crate::pages::{
19-
context_override::ContextOverride, default_config::DefaultConfig,
19+
audit_log::AuditLog, context_override::ContextOverride, default_config::DefaultConfig,
2020
default_config_list::DefaultConfigList, experiment::ExperimentPage, home::Home,
2121
organisations::Organisations, type_template::TypePage, type_templates::TypesPage,
2222
webhook::Webhook, webhooks::Webhooks, workspace::Workspace,
@@ -178,6 +178,17 @@ pub fn app(app_envs: Envs) -> impl IntoView {
178178

179179
<Route ssr=SsrMode::Async path="webhooks" view=Webhooks />
180180
<Route ssr=SsrMode::Async path="webhooks/:webhook_name" view=Webhook />
181+
182+
<Route ssr=SsrMode::Async path="/admin/:org_id/:tenant/audit-log"
183+
view=move || {
184+
view! {
185+
<Layout>
186+
<AuditLog />
187+
</Layout>
188+
}
189+
}
190+
/>
191+
181192
</Route>
182193
// <Route
183194
// path="/*any"

crates/frontend/src/components/side_nav.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ fn create_routes(org: &str, tenant: &str) -> Vec<AppRoute> {
7070
icon: "ri-webhook-line".to_string(),
7171
label: "Webhooks".to_string(),
7272
},
73+
AppRoute {
74+
key: format!("{base}/admin/{org}/{tenant}/audit-log"),
75+
path: format!("{base}/admin/{org}/{tenant}/audit-log"),
76+
icon: "ri-file-list-3-line".to_string(),
77+
label: "Audit Log".to_string(),
78+
},
7379
]
7480
}
7581

crates/frontend/src/pages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod audit_log;
12
pub mod compare_overrides;
23
pub mod config_version;
34
pub mod config_version_list;

0 commit comments

Comments
 (0)