summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-03-29 21:11:40 -0400
committerJoram Wilander <jwawilander@gmail.com>2017-03-29 21:11:40 -0400
commit6ac87d82e38c83e3b9b3bd12c3122e047f0110b1 (patch)
treeaa3f0f8f41df7c987f8bb62756ca3d8259ecbaa1 /store
parenta4764a5c10ec59820eec7338d97be48d41c1a4d6 (diff)
downloadchat-6ac87d82e38c83e3b9b3bd12c3122e047f0110b1.tar.gz
chat-6ac87d82e38c83e3b9b3bd12c3122e047f0110b1.tar.bz2
chat-6ac87d82e38c83e3b9b3bd12c3122e047f0110b1.zip
PLT-2713 Added ability for admins to list users not in any team (#5844)
* PLT-2713 Added ability for admins to list users not in any team * Updated style of unit test
Diffstat (limited to 'store')
-rw-r--r--store/sql_user_store.go48
-rw-r--r--store/sql_user_store_test.go43
-rw-r--r--store/store.go1
3 files changed, 92 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 092f4abc7..2fb7158ac 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -726,6 +726,54 @@ func (us SqlUserStore) GetProfilesNotInChannel(teamId string, channelId string,
return storeChannel
}
+func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var users []*model.User
+
+ query := `
+ SELECT
+ *
+ FROM
+ Users
+ WHERE
+ (SELECT
+ COUNT(0)
+ FROM
+ TeamMembers
+ WHERE
+ TeamMembers.UserId = Users.Id
+ AND TeamMembers.DeleteAt = 0) = 0
+ ORDER BY
+ Username ASC
+ LIMIT
+ :Limit
+ OFFSET
+ :Offset`
+
+ if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
+ result.Err = model.NewLocAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.get_profiles.app_error", nil, err.Error())
+ } else {
+
+ for _, u := range users {
+ u.Password = ""
+ u.AuthData = new(string)
+ *u.AuthData = ""
+ }
+
+ result.Data = users
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (us SqlUserStore) GetProfilesByUsernames(usernames []string, teamId string) StoreChannel {
storeChannel := make(StoreChannel)
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go
index 73d42dbcd..6e9642b60 100644
--- a/store/sql_user_store_test.go
+++ b/store/sql_user_store_test.go
@@ -373,6 +373,49 @@ func TestUserStoreGetProfilesInChannel(t *testing.T) {
}
}
+func TestUserStoreGetProfilesWithoutTeam(t *testing.T) {
+ Setup()
+
+ teamId := model.NewId()
+
+ // These usernames need to appear in the first 100 users for this to work
+
+ u1 := &model.User{}
+ u1.Username = "a000000000" + model.NewId()
+ u1.Email = model.NewId()
+ Must(store.User().Save(u1))
+ Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id}))
+ defer store.User().PermanentDelete(u1.Id)
+
+ u2 := &model.User{}
+ u2.Username = "a000000001" + model.NewId()
+ u2.Email = model.NewId()
+ Must(store.User().Save(u2))
+ defer store.User().PermanentDelete(u2.Id)
+
+ if r1 := <-store.User().GetProfilesWithoutTeam(0, 100); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ users := r1.Data.([]*model.User)
+
+ found1 := false
+ found2 := false
+ for _, u := range users {
+ if u.Id == u1.Id {
+ found1 = true
+ } else if u.Id == u2.Id {
+ found2 = true
+ }
+ }
+
+ if found1 {
+ t.Fatal("shouldn't have returned user on team")
+ } else if !found2 {
+ t.Fatal("should've returned user without any teams")
+ }
+ }
+}
+
func TestUserStoreGetAllProfilesInChannel(t *testing.T) {
Setup()
diff --git a/store/store.go b/store/store.go
index 409280918..6523df0c8 100644
--- a/store/store.go
+++ b/store/store.go
@@ -177,6 +177,7 @@ type UserStore interface {
GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel
GetAllProfilesInChannel(channelId string, allowFromCache bool) StoreChannel
GetProfilesNotInChannel(teamId string, channelId string, offset int, limit int) StoreChannel
+ GetProfilesWithoutTeam(offset int, limit int) StoreChannel
GetProfilesByUsernames(usernames []string, teamId string) StoreChannel
GetAllProfiles(offset int, limit int) StoreChannel
GetProfiles(teamId string, offset int, limit int) StoreChannel