diff options
author | Corey Hulen <corey@hulen.com> | 2016-05-04 06:31:42 -0700 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-04 09:31:42 -0400 |
commit | 6611229cd7bd3cdfc0082c0a581145aaac0ab322 (patch) | |
tree | db6670a8c2716179bfe6e07b82588d83d3afb6bd /store | |
parent | 6b06f49e8910ed44f619adad15ab268758312852 (diff) | |
download | chat-6611229cd7bd3cdfc0082c0a581145aaac0ab322.tar.gz chat-6611229cd7bd3cdfc0082c0a581145aaac0ab322.tar.bz2 chat-6611229cd7bd3cdfc0082c0a581145aaac0ab322.zip |
PLT-2707 Adding option to show DM list from all of server (#2871)
* PLT-2707 Adding option to show DM list from all of server
* Fixing loc
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_user_store.go | 70 | ||||
-rw-r--r-- | store/sql_user_store_test.go | 25 | ||||
-rw-r--r-- | store/store.go | 2 |
3 files changed, 95 insertions, 2 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 07e974559..8d4f1a31b 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -454,7 +454,34 @@ func (s SqlUserStore) GetEtagForDirectProfiles(userId string) StoreChannel { Channels.Type = 'D' AND Channels.Id = ChannelMembers.ChannelId AND ChannelMembers.UserId = :UserId)) - `, map[string]interface{}{"UserId": userId}) + OR Id IN (SELECT + Name + FROM + Preferences + WHERE + UserId = :UserId + AND Category = 'direct_channel_show') + `, map[string]interface{}{"UserId": userId}) + if err != nil { + result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis()) + } else { + result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, updateAt) + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + +func (s SqlUserStore) GetEtagForAllProfiles() StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + updateAt, err := s.GetReplica().SelectInt("SELECT UpdateAt FROM Users ORDER BY UpdateAt DESC LIMIT 1") if err != nil { result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis()) } else { @@ -468,6 +495,37 @@ func (s SqlUserStore) GetEtagForDirectProfiles(userId string) StoreChannel { return storeChannel } +func (us SqlUserStore) GetAllProfiles() StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var users []*model.User + + if _, err := us.GetReplica().Select(&users, "SELECT * FROM Users"); err != nil { + result.Err = model.NewLocAppError("SqlUserStore.GetProfiles", "store.sql_user.get_profiles.app_error", nil, err.Error()) + } else { + + userMap := make(map[string]*model.User) + + for _, u := range users { + u.Password = "" + u.AuthData = "" + userMap[u.Id] = u + } + + result.Data = userMap + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlUserStore) GetEtagForProfiles(teamId string) StoreChannel { storeChannel := make(StoreChannel) @@ -548,7 +606,15 @@ func (us SqlUserStore) GetDirectProfiles(userId string) StoreChannel { WHERE Channels.Type = 'D' AND Channels.Id = ChannelMembers.ChannelId - AND ChannelMembers.UserId = :UserId))`, map[string]interface{}{"UserId": userId}); err != nil { + AND ChannelMembers.UserId = :UserId)) + OR Id IN (SELECT + Name + FROM + Preferences + WHERE + UserId = :UserId + AND Category = 'direct_channel_show') + `, map[string]interface{}{"UserId": userId}); err != nil { result.Err = model.NewLocAppError("SqlUserStore.GetDirectProfiles", "store.sql_user.get_profiles.app_error", nil, err.Error()) } else { diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index fbe2285a9..b48da55f5 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -263,6 +263,31 @@ func TestActiveUserCount(t *testing.T) { } } +func TestUserStoreGetAllProfiles(t *testing.T) { + Setup() + + teamId := model.NewId() + + u1 := &model.User{} + u1.Email = model.NewId() + Must(store.User().Save(u1)) + Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id})) + + u2 := &model.User{} + u2.Email = model.NewId() + Must(store.User().Save(u2)) + Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u2.Id})) + + if r1 := <-store.User().GetAllProfiles(); r1.Err != nil { + t.Fatal(r1.Err) + } else { + users := r1.Data.(map[string]*model.User) + if len(users) < 2 { + t.Fatal("invalid returned users") + } + } +} + func TestUserStoreGetProfiles(t *testing.T) { Setup() diff --git a/store/store.go b/store/store.go index 8097fd8e8..7801f78f9 100644 --- a/store/store.go +++ b/store/store.go @@ -131,6 +131,7 @@ type UserStore interface { UpdateMfaActive(userId string, active bool) StoreChannel Get(id string) StoreChannel GetAll() StoreChannel + GetAllProfiles() StoreChannel GetProfiles(teamId string) StoreChannel GetDirectProfiles(userId string) StoreChannel GetProfileByIds(userId []string) StoreChannel @@ -139,6 +140,7 @@ type UserStore interface { GetByUsername(username string) StoreChannel GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail, ldapEnabled bool) StoreChannel VerifyEmail(userId string) StoreChannel + GetEtagForAllProfiles() StoreChannel GetEtagForProfiles(teamId string) StoreChannel GetEtagForDirectProfiles(userId string) StoreChannel UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel |