mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
Add filter to search users by active (#38637)
* Add filter to search users by active * Fix query
This commit is contained in:
parent
f1529b83a2
commit
e47a60f511
@ -290,8 +290,9 @@ func searchUser(c *models.ReqContext) (*models.SearchUsersQuery, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
searchQuery := c.Query("query")
|
searchQuery := c.Query("query")
|
||||||
|
filter := c.Query("filter")
|
||||||
|
|
||||||
query := &models.SearchUsersQuery{Query: searchQuery, Page: page, Limit: perPage}
|
query := &models.SearchUsersQuery{Query: searchQuery, Filter: models.SearchUsersFilter(filter), Page: page, Limit: perPage}
|
||||||
if err := bus.Dispatch(query); err != nil {
|
if err := bus.Dispatch(query); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -138,12 +138,17 @@ type GetUserProfileQuery struct {
|
|||||||
Result UserProfileDTO
|
Result UserProfileDTO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SearchUsersFilter string
|
||||||
|
|
||||||
|
const ActiveLast30Days SearchUsersFilter = "activeLast30Days"
|
||||||
|
|
||||||
type SearchUsersQuery struct {
|
type SearchUsersQuery struct {
|
||||||
OrgId int64
|
OrgId int64
|
||||||
Query string
|
Query string
|
||||||
Page int
|
Page int
|
||||||
Limit int
|
Limit int
|
||||||
AuthModule string
|
AuthModule string
|
||||||
|
Filter SearchUsersFilter
|
||||||
|
|
||||||
IsDisabled *bool
|
IsDisabled *bool
|
||||||
|
|
||||||
|
@ -588,7 +588,6 @@ func SearchUsers(query *models.SearchUsersQuery) error {
|
|||||||
ORDER BY user_auth.created DESC `
|
ORDER BY user_auth.created DESC `
|
||||||
joinCondition = "user_auth.id=" + joinCondition + dialect.Limit(1) + ")"
|
joinCondition = "user_auth.id=" + joinCondition + dialect.Limit(1) + ")"
|
||||||
sess.Join("LEFT", "user_auth", joinCondition)
|
sess.Join("LEFT", "user_auth", joinCondition)
|
||||||
|
|
||||||
if query.OrgId > 0 {
|
if query.OrgId > 0 {
|
||||||
whereConditions = append(whereConditions, "org_id = ?")
|
whereConditions = append(whereConditions, "org_id = ?")
|
||||||
whereParams = append(whereParams, query.OrgId)
|
whereParams = append(whereParams, query.OrgId)
|
||||||
@ -609,6 +608,12 @@ func SearchUsers(query *models.SearchUsersQuery) error {
|
|||||||
whereParams = append(whereParams, query.AuthModule)
|
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 {
|
if len(whereConditions) > 0 {
|
||||||
sess.Where(strings.Join(whereConditions, " AND "), whereParams...)
|
sess.Where(strings.Join(whereConditions, " AND "), whereParams...)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user