diff options
author | George Goldberg <george@gberg.me> | 2017-03-30 02:10:51 +0100 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-03-29 21:10:51 -0400 |
commit | a4764a5c10ec59820eec7338d97be48d41c1a4d6 (patch) | |
tree | 665d61a0b0738b328b9d7514b8732a59787c20ce /store/sql_user_store.go | |
parent | 6d6b8134462d9e718f21e76f9c47f73604574c9b (diff) | |
download | chat-a4764a5c10ec59820eec7338d97be48d41c1a4d6.tar.gz chat-a4764a5c10ec59820eec7338d97be48d41c1a4d6.tar.bz2 chat-a4764a5c10ec59820eec7338d97be48d41c1a4d6.zip |
PLT-6083: API to get users not in a specific team. (#5888)
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r-- | store/sql_user_store.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index c00e37ed6..092f4abc7 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -1514,3 +1514,76 @@ func (us SqlUserStore) AnalyticsGetSystemAdminCount() StoreChannel { return storeChannel } + +func (us SqlUserStore) GetProfilesNotInTeam(teamId string, offset int, limit int) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var users []*model.User + + if _, err := us.GetReplica().Select(&users, ` + SELECT + u.* + FROM Users u + LEFT JOIN TeamMembers tm + ON tm.UserId = u.Id + AND tm.TeamId = :TeamId + AND tm.DeleteAt = 0 + WHERE tm.UserId IS NULL + ORDER BY u.Username ASC + LIMIT :Limit OFFSET :Offset + `, map[string]interface{}{"TeamId": teamId, "Offset": offset, "Limit": limit}); err != nil { + result.Err = model.NewLocAppError("SqlUserStore.GetProfilesNotInTeam", "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) GetEtagForProfilesNotInTeam(teamId string) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + updateAt, err := us.GetReplica().SelectInt(` + SELECT + u.UpdateAt + FROM Users u + LEFT JOIN TeamMembers tm + ON tm.UserId = u.Id + AND tm.TeamId = :TeamId + AND tm.DeleteAt = 0 + WHERE tm.UserId IS NULL + ORDER BY u.UpdateAt DESC + LIMIT 1 + `, map[string]interface{}{"TeamId": teamId}) + + if err != nil { + result.Data = fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.GetMillis(), utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress) + } else { + result.Data = fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, updateAt, utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress) + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} |