mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-22 18:26:41 +00:00
add general search filter
This commit is contained in:
@@ -21,6 +21,7 @@ type AccessLogFilter struct {
|
|||||||
PageSize int
|
PageSize int
|
||||||
|
|
||||||
// Filtering parameters
|
// Filtering parameters
|
||||||
|
Search *string // General search across host, path, source IP, and user fields
|
||||||
SourceIP *string // Filter by source IP address
|
SourceIP *string // Filter by source IP address
|
||||||
Host *string // Filter by host header
|
Host *string // Filter by host header
|
||||||
Path *string // Filter by request path (supports LIKE pattern)
|
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 != "" {
|
if sourceIP := queryParams.Get("source_ip"); sourceIP != "" {
|
||||||
f.SourceIP = &sourceIP
|
f.SourceIP = &sourceIP
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5102,6 +5102,14 @@ func (s *SqlStore) GetAccountAccessLogs(ctx context.Context, lockStrength Lockin
|
|||||||
|
|
||||||
// applyAccessLogFilters applies filter conditions to the query
|
// applyAccessLogFilters applies filter conditions to the query
|
||||||
func (s *SqlStore) applyAccessLogFilters(query *gorm.DB, filter accesslogs.AccessLogFilter) *gorm.DB {
|
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 {
|
if filter.SourceIP != nil {
|
||||||
query = query.Where("source_ip = ?", *filter.SourceIP)
|
query = query.Where("source_ip = ?", *filter.SourceIP)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6389,6 +6389,11 @@ paths:
|
|||||||
minimum: 1
|
minimum: 1
|
||||||
maximum: 100
|
maximum: 100
|
||||||
description: Number of items per page (max 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
|
- in: query
|
||||||
name: source_ip
|
name: source_ip
|
||||||
schema:
|
schema:
|
||||||
|
|||||||
Reference in New Issue
Block a user