Fix active LDAP sync (#25321)

* LDAP: sync only users with 'ldap' module as a most recent auth module

* LDAP: tests for searching ldap users
This commit is contained in:
Alexander Zobnin
2020-06-03 16:28:13 +03:00
committed by GitHub
parent 63463e0e46
commit c4eca530ce
2 changed files with 52 additions and 12 deletions

View File

@ -468,13 +468,7 @@ func SearchUsers(query *models.SearchUsersQuery) error {
}
if query.AuthModule != "" {
whereConditions = append(
whereConditions,
`u.id IN (SELECT user_id
FROM user_auth
WHERE auth_module=?)`,
)
whereConditions = append(whereConditions, `auth_module=?`)
whereParams = append(whereParams, query.AuthModule)
}
@ -494,6 +488,11 @@ func SearchUsers(query *models.SearchUsersQuery) error {
user := models.User{}
countSess := x.Table("user").Alias("u")
// Join with user_auth table if users filtered by auth_module
if query.AuthModule != "" {
countSess.Join("LEFT", "user_auth", joinCondition)
}
if len(whereConditions) > 0 {
countSess.Where(strings.Join(whereConditions, " AND "), whereParams...)
}