Create search filters by interface (#39843)
* Extract search users to a new service * Fix wire provider * Fix common_test and remove RouteRegister * Remove old endpoints * Fix test * Create search filters using interfaces * Move Enterprise filter, rename filter for filters and allow use filters with params * Each filter has unique key * Back activeLast30Days filter to OSS * Fix tests * Delete unusued param * Move filters to searchusers service and small refactor * Fix tests
This commit is contained in:
@@ -614,16 +614,22 @@ func SearchUsers(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
whereParams = append(whereParams, query.AuthModule)
|
||||
}
|
||||
|
||||
if query.Filter == models.ActiveLast30Days {
|
||||
activeUserDeadlineDate := time.Now().Add(-activeUserTimeLimit)
|
||||
whereConditions = append(whereConditions, `last_seen_at > ?`)
|
||||
whereParams = append(whereParams, activeUserDeadlineDate)
|
||||
}
|
||||
|
||||
if len(whereConditions) > 0 {
|
||||
sess.Where(strings.Join(whereConditions, " AND "), whereParams...)
|
||||
}
|
||||
|
||||
for _, filter := range query.Filters {
|
||||
if jc := filter.JoinCondition(); jc != nil {
|
||||
sess.Join(jc.Operator, jc.Table, jc.Params)
|
||||
}
|
||||
if ic := filter.InCondition(); ic != nil {
|
||||
sess.In(ic.Condition, ic.Params)
|
||||
}
|
||||
if wc := filter.WhereCondition(); wc != nil {
|
||||
sess.Where(wc.Condition, wc.Params)
|
||||
}
|
||||
}
|
||||
|
||||
if query.Limit > 0 {
|
||||
offset := query.Limit * (query.Page - 1)
|
||||
sess.Limit(query.Limit, offset)
|
||||
|
||||
Reference in New Issue
Block a user