PLT-6162: Search for users not in a given team. (#5943)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
da5265681d
Коммит
232a99f0c7
@@ -1339,6 +1339,32 @@ func (us SqlUserStore) SearchWithoutTeam(term string, options map[string]bool) S
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options map[string]bool) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
searchQuery := `
|
||||
SELECT
|
||||
Users.*
|
||||
FROM Users
|
||||
LEFT JOIN TeamMembers tm
|
||||
ON tm.UserId = Users.Id
|
||||
AND tm.TeamId = :NotInTeamId
|
||||
WHERE
|
||||
tm.UserId IS NULL
|
||||
SEARCH_CLAUSE
|
||||
INACTIVE_CLAUSE
|
||||
ORDER BY Users.Username ASC
|
||||
LIMIT 100`
|
||||
|
||||
storeChannel <- us.performSearch(searchQuery, term, options, map[string]interface{}{"NotInTeamId": notInTeamId})
|
||||
close(storeChannel)
|
||||
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (us SqlUserStore) SearchNotInChannel(teamId string, channelId string, term string, options map[string]bool) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
|
||||
@@ -1546,6 +1546,47 @@ func TestUserStoreSearch(t *testing.T) {
|
||||
t.Fatal("should have found user")
|
||||
}
|
||||
}
|
||||
|
||||
// Search Users not in Team.
|
||||
u4 := &model.User{}
|
||||
u4.Username = "simon" + model.NewId()
|
||||
u4.Email = model.NewId()
|
||||
u4.DeleteAt = 0
|
||||
Must(store.User().Save(u4))
|
||||
|
||||
if r1 := <-store.User().SearchNotInTeam(tid, "simo", searchOptions); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
profiles := r1.Data.([]*model.User)
|
||||
found := false
|
||||
for _, profile := range profiles {
|
||||
if profile.Id == u4.Id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatal("should have found user")
|
||||
}
|
||||
}
|
||||
|
||||
if r1 := <-store.User().SearchNotInTeam(tid, "jimb", searchOptions); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
profiles := r1.Data.([]*model.User)
|
||||
found := false
|
||||
for _, profile := range profiles {
|
||||
if profile.Id == u1.Id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
t.Fatal("should not have found user")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserStoreSearchWithoutTeam(t *testing.T) {
|
||||
|
||||
@@ -202,6 +202,7 @@ type UserStore interface {
|
||||
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
|
||||
GetRecentlyActiveUsersForTeam(teamId string) StoreChannel
|
||||
Search(teamId string, term string, options map[string]bool) StoreChannel
|
||||
SearchNotInTeam(notInTeamId string, term string, options map[string]bool) StoreChannel
|
||||
SearchInChannel(channelId string, term string, options map[string]bool) StoreChannel
|
||||
SearchNotInChannel(teamId string, channelId string, term string, options map[string]bool) StoreChannel
|
||||
SearchWithoutTeam(term string, options map[string]bool) StoreChannel
|
||||
|
||||
Ссылка в новой задаче
Block a user