diff --git a/backend/internal/controller/audit_log_controller.go b/backend/internal/controller/audit_log_controller.go index fd41bd7b..1a4ecd9b 100644 --- a/backend/internal/controller/audit_log_controller.go +++ b/backend/internal/controller/audit_log_controller.go @@ -89,6 +89,7 @@ func (alc *AuditLogController) listAuditLogsForUserHandler(c *gin.Context) { // @Param filters[userId] query string false "Filter by user ID" // @Param filters[event] query string false "Filter by event type" // @Param filters[clientName] query string false "Filter by client name" +// @Param filters[location] query string false "Filter by location type (external or internal)" // @Success 200 {object} dto.Paginated[dto.AuditLogDto] // @Router /api/audit-logs/all [get] func (alc *AuditLogController) listAllAuditLogsHandler(c *gin.Context) { diff --git a/backend/internal/dto/audit_log_dto.go b/backend/internal/dto/audit_log_dto.go index ed3f2072..7e25df48 100644 --- a/backend/internal/dto/audit_log_dto.go +++ b/backend/internal/dto/audit_log_dto.go @@ -23,4 +23,5 @@ type AuditLogFilterDto struct { UserID string `form:"filters[userId]"` Event string `form:"filters[event]"` ClientName string `form:"filters[clientName]"` + Location string `form:"filters[location]"` } diff --git a/backend/internal/service/audit_log_service.go b/backend/internal/service/audit_log_service.go index 6b59fc26..a6508677 100644 --- a/backend/internal/service/audit_log_service.go +++ b/backend/internal/service/audit_log_service.go @@ -150,6 +150,14 @@ func (s *AuditLogService) ListAllAuditLogs(ctx context.Context, sortedPagination return nil, utils.PaginationResponse{}, fmt.Errorf("unsupported database dialect: %s", dialect) } } + if filters.Location != "" { + switch filters.Location { + case "external": + query = query.Where("country != 'Internal Network'") + case "internal": + query = query.Where("country = 'Internal Network'") + } + } pagination, err := utils.PaginateAndSort(sortedPaginationRequest, query, &logs) if err != nil { diff --git a/backend/resources/migrations/postgres/20250619115053_add_country_index.down.sql b/backend/resources/migrations/postgres/20250619115053_add_country_index.down.sql new file mode 100644 index 00000000..70d390bb --- /dev/null +++ b/backend/resources/migrations/postgres/20250619115053_add_country_index.down.sql @@ -0,0 +1 @@ +DROP INDEX idx_audit_logs_country; \ No newline at end of file diff --git a/backend/resources/migrations/postgres/20250619115053_add_country_index.up.sql b/backend/resources/migrations/postgres/20250619115053_add_country_index.up.sql new file mode 100644 index 00000000..fa92172c --- /dev/null +++ b/backend/resources/migrations/postgres/20250619115053_add_country_index.up.sql @@ -0,0 +1 @@ +CREATE INDEX idx_audit_logs_country ON audit_logs(country); \ No newline at end of file diff --git a/backend/resources/migrations/sqlite/20250619115053_add_country_index.down.sql b/backend/resources/migrations/sqlite/20250619115053_add_country_index.down.sql new file mode 100644 index 00000000..70d390bb --- /dev/null +++ b/backend/resources/migrations/sqlite/20250619115053_add_country_index.down.sql @@ -0,0 +1 @@ +DROP INDEX idx_audit_logs_country; \ No newline at end of file diff --git a/backend/resources/migrations/sqlite/20250619115053_add_country_index.up.sql b/backend/resources/migrations/sqlite/20250619115053_add_country_index.up.sql new file mode 100644 index 00000000..fa92172c --- /dev/null +++ b/backend/resources/migrations/sqlite/20250619115053_add_country_index.up.sql @@ -0,0 +1 @@ +CREATE INDEX idx_audit_logs_country ON audit_logs(country); \ No newline at end of file diff --git a/frontend/messages/en.json b/frontend/messages/en.json index 132e7c0b..946b7255 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -320,6 +320,7 @@ "all_users": "All Users", "all_events": "All Events", "all_clients": "All Clients", + "all_locations": "All Locations", "global_audit_log": "Global Audit Log", "see_all_account_activities_from_the_last_3_months": "See all user activity for the last 3 months.", "token_sign_in": "Token Sign In", diff --git a/frontend/src/lib/components/form/searchable-select.svelte b/frontend/src/lib/components/form/searchable-select.svelte index f6b95c01..2f25f951 100644 --- a/frontend/src/lib/components/form/searchable-select.svelte +++ b/frontend/src/lib/components/form/searchable-select.svelte @@ -14,6 +14,7 @@ onSelect, oninput, isLoading, + disableSearch = false, selectText = m.select_an_option(), ...restProps }: HTMLAttributes & { @@ -25,6 +26,7 @@ oninput?: FormEventHandler; onSelect?: (value: string) => void; isLoading?: boolean; + disableSearch?: boolean; selectText?: string; } = $props(); @@ -76,13 +78,15 @@ - { - filterItems(e.currentTarget.value); - oninput?.(e); - }} - /> + {#if !disableSearch} + { + filterItems(e.currentTarget.value); + oninput?.(e); + }} + /> + {/if} {#if isLoading}
diff --git a/frontend/src/lib/types/audit-log.type.ts b/frontend/src/lib/types/audit-log.type.ts index 2358686e..9f290ba5 100644 --- a/frontend/src/lib/types/audit-log.type.ts +++ b/frontend/src/lib/types/audit-log.type.ts @@ -14,5 +14,6 @@ export type AuditLog = { export type AuditLogFilter = { userId: string; event: string; + location: string; clientName: string; }; diff --git a/frontend/src/routes/settings/audit-log/global/+page.svelte b/frontend/src/routes/settings/audit-log/global/+page.svelte index f4163407..56266459 100644 --- a/frontend/src/routes/settings/audit-log/global/+page.svelte +++ b/frontend/src/routes/settings/audit-log/global/+page.svelte @@ -18,9 +18,15 @@ let filters: AuditLogFilter = $state({ userId: '', event: '', + location: '', clientName: '' }); + const locationTypes = $state({ + external: 'External Networks', + internal: 'Internal Networks' + }); + const eventTypes = $state({ SIGN_IN: m.sign_in(), TOKEN_SIGN_IN: m.token_sign_in(), @@ -47,7 +53,7 @@ > -
+
{#await auditLogService.listUsers()} @@ -82,6 +88,20 @@ bind:value={filters.event} />
+
+ ({ + value, + label + })) + ]} + bind:value={filters.location} + /> +
{#await auditLogService.listClientNames()}