@@ -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+ }
0 commit comments