add general search filter

This commit is contained in:
pascal
2026-02-11 16:38:31 +01:00
parent d069145bd1
commit 1ffe8deb10
3 changed files with 18 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ type AccessLogFilter struct {
PageSize int
// Filtering parameters
Search *string // General search across host, path, source IP, and user fields
SourceIP *string // Filter by source IP address
Host *string // Filter by host header
Path *string // Filter by request path (supports LIKE pattern)
@@ -54,6 +55,10 @@ func (f *AccessLogFilter) ParseFromRequest(r *http.Request) {
}
}
if search := queryParams.Get("search"); search != "" {
f.Search = &search
}
if sourceIP := queryParams.Get("source_ip"); sourceIP != "" {
f.SourceIP = &sourceIP
}

View File

@@ -5102,6 +5102,14 @@ func (s *SqlStore) GetAccountAccessLogs(ctx context.Context, lockStrength Lockin
// applyAccessLogFilters applies filter conditions to the query
func (s *SqlStore) applyAccessLogFilters(query *gorm.DB, filter accesslogs.AccessLogFilter) *gorm.DB {
if filter.Search != nil {
searchPattern := "%" + *filter.Search + "%"
query = query.Where(
"source_ip LIKE ? OR host LIKE ? OR path LIKE ? OR user_id IN (SELECT id FROM users WHERE email LIKE ? OR name LIKE ?)",
searchPattern, searchPattern, searchPattern, searchPattern, searchPattern,
)
}
if filter.SourceIP != nil {
query = query.Where("source_ip = ?", *filter.SourceIP)
}

View File

@@ -6389,6 +6389,11 @@ paths:
minimum: 1
maximum: 100
description: Number of items per page (max 100)
- in: query
name: search
schema:
type: string
description: General search across host, path, source IP, user email, and user name
- in: query
name: source_ip
schema: