diff options
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_user_store.go | 30 | ||||
-rw-r--r-- | store/sql_user_store_test.go | 61 | ||||
-rw-r--r-- | store/store.go | 1 |
3 files changed, 92 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 23b0c3696..c00e37ed6 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -1261,6 +1261,36 @@ func (us SqlUserStore) Search(teamId string, term string, options map[string]boo return storeChannel } +func (us SqlUserStore) SearchWithoutTeam(term string, options map[string]bool) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + searchQuery := ` + SELECT + * + FROM + Users + WHERE + (SELECT + COUNT(0) + FROM + TeamMembers + WHERE + TeamMembers.UserId = Users.Id + AND TeamMembers.DeleteAt = 0) = 0 + SEARCH_CLAUSE + INACTIVE_CLAUSE + ORDER BY Username ASC + LIMIT 100` + + storeChannel <- us.performSearch(searchQuery, term, options, map[string]interface{}{}) + close(storeChannel) + + }() + + return storeChannel +} + func (us SqlUserStore) SearchNotInChannel(teamId string, channelId string, term string, options map[string]bool) StoreChannel { storeChannel := make(StoreChannel, 1) diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index 104735455..798988246 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -1505,6 +1505,67 @@ func TestUserStoreSearch(t *testing.T) { } } +func TestUserStoreSearchWithoutTeam(t *testing.T) { + Setup() + + u1 := &model.User{} + u1.Username = "jimbo" + model.NewId() + u1.FirstName = "Tim" + u1.LastName = "Bill" + u1.Nickname = "Rob" + u1.Email = "harold" + model.NewId() + "@simulator.amazonses.com" + Must(store.User().Save(u1)) + + u2 := &model.User{} + u2.Username = "jim-bobby" + model.NewId() + u2.Email = model.NewId() + Must(store.User().Save(u2)) + + u3 := &model.User{} + u3.Username = "jimbo" + model.NewId() + u3.Email = model.NewId() + u3.DeleteAt = 1 + Must(store.User().Save(u3)) + + tid := model.NewId() + Must(store.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u3.Id})) + + searchOptions := map[string]bool{} + searchOptions[USER_SEARCH_OPTION_NAMES_ONLY] = true + + if r1 := <-store.User().SearchWithoutTeam("", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } + + if r1 := <-store.User().SearchWithoutTeam("jim", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + + found1 := false + found2 := false + found3 := false + + for _, profile := range profiles { + if profile.Id == u1.Id { + found1 = true + } else if profile.Id == u2.Id { + found2 = true + } else if profile.Id == u3.Id { + found3 = true + } + } + + if !found1 { + t.Fatal("should have found user1") + } else if !found2 { + t.Fatal("should have found user2") + } else if found3 { + t.Fatal("should not have found user3") + } + } +} + func TestUserStoreAnalyticsGetInactiveUsersCount(t *testing.T) { Setup() diff --git a/store/store.go b/store/store.go index 72572b1e0..323727697 100644 --- a/store/store.go +++ b/store/store.go @@ -201,6 +201,7 @@ type UserStore interface { Search(teamId 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 AnalyticsGetInactiveUsersCount() StoreChannel AnalyticsGetSystemAdminCount() StoreChannel } |