mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
implemented migration to sync (#11413)
This commit is contained in:
15
app/user.go
15
app/user.go
@@ -1752,13 +1752,11 @@ func (a *App) SearchUsersInTeam(teamId, term string, options *model.UserSearchOp
|
||||
}
|
||||
|
||||
if !a.IsESAutocompletionEnabled() || err != nil {
|
||||
result := <-a.Srv.Store.User().Search(teamId, term, options)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
users, err = a.Srv.Store.User().Search(teamId, term, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
users = result.Data.([]*model.User)
|
||||
|
||||
for _, user := range users {
|
||||
a.SanitizeProfile(user, options.IsAdmin)
|
||||
}
|
||||
@@ -1936,12 +1934,11 @@ func (a *App) AutocompleteUsersInTeam(teamId string, term string, options *model
|
||||
|
||||
if !a.IsESAutocompletionEnabled() || err != nil {
|
||||
autocomplete = &model.UserAutocompleteInTeam{}
|
||||
result := <-a.Srv.Store.User().Search(teamId, term, options)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
users, err := a.Srv.Store.User().Search(teamId, term, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
users := result.Data.([]*model.User)
|
||||
for _, user := range users {
|
||||
a.SanitizeProfile(user, options.IsAdmin)
|
||||
}
|
||||
|
||||
@@ -1224,18 +1224,19 @@ func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlUserStore) Search(teamId string, term string, options *model.UserSearchOptions) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := us.usersQuery.
|
||||
OrderBy("Username ASC").
|
||||
Limit(uint64(options.Limit))
|
||||
func (us SqlUserStore) Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
||||
query := us.usersQuery.
|
||||
OrderBy("Username ASC").
|
||||
Limit(uint64(options.Limit))
|
||||
|
||||
if teamId != "" {
|
||||
query = query.Join("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", teamId)
|
||||
}
|
||||
|
||||
*result = us.performSearch(query, term, options)
|
||||
})
|
||||
if teamId != "" {
|
||||
query = query.Join("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", teamId)
|
||||
}
|
||||
result := us.performSearch(query, term, options)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.([]*model.User), nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) SearchWithoutTeam(term string, options *model.UserSearchOptions) store.StoreChannel {
|
||||
|
||||
@@ -288,7 +288,7 @@ type UserStore interface {
|
||||
GetAnyUnreadPostCountForChannel(userId string, channelId string) StoreChannel
|
||||
GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
||||
GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
Search(teamId string, term string, options *model.UserSearchOptions) StoreChannel
|
||||
Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) StoreChannel
|
||||
SearchInChannel(channelId string, term string, options *model.UserSearchOptions) StoreChannel
|
||||
SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) StoreChannel
|
||||
|
||||
@@ -749,19 +749,28 @@ func (_m *UserStore) Save(user *model.User) store.StoreChannel {
|
||||
}
|
||||
|
||||
// Search provides a mock function with given fields: teamId, term, options
|
||||
func (_m *UserStore) Search(teamId string, term string, options *model.UserSearchOptions) store.StoreChannel {
|
||||
func (_m *UserStore) Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
||||
ret := _m.Called(teamId, term, options)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string, *model.UserSearchOptions) store.StoreChannel); ok {
|
||||
var r0 []*model.User
|
||||
if rf, ok := ret.Get(0).(func(string, string, *model.UserSearchOptions) []*model.User); ok {
|
||||
r0 = rf(teamId, term, options)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.User)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string, *model.UserSearchOptions) *model.AppError); ok {
|
||||
r1 = rf(teamId, term, options)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchInChannel provides a mock function with given fields: channelId, term, options
|
||||
|
||||
@@ -2412,9 +2412,9 @@ func testUserStoreSearch(t *testing.T, ss store.Store) {
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.Description, func(t *testing.T) {
|
||||
result := <-ss.User().Search(testCase.TeamId, testCase.Term, testCase.Options)
|
||||
require.Nil(t, result.Err)
|
||||
assertUsersMatchInAnyOrder(t, testCase.Expected, result.Data.([]*model.User))
|
||||
users, err := ss.User().Search(testCase.TeamId, testCase.Term, testCase.Options)
|
||||
require.Nil(t, err)
|
||||
assertUsersMatchInAnyOrder(t, testCase.Expected, users)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2424,9 +2424,9 @@ func testUserStoreSearch(t *testing.T, ss store.Store) {
|
||||
Limit: model.USER_SEARCH_DEFAULT_LIMIT,
|
||||
}
|
||||
|
||||
r1 := <-ss.User().Search(tid, "", searchOptions)
|
||||
require.Nil(t, r1.Err)
|
||||
assert.Len(t, r1.Data.([]*model.User), 4)
|
||||
users, err := ss.User().Search(tid, "", searchOptions)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, users, 4)
|
||||
// Don't assert contents, since Postgres' default collation order is left up to
|
||||
// the operating system, and jimbo1 might sort before or after jim-bo.
|
||||
// assertUsers(t, []*model.User{u2, u1, u6, u5}, r1.Data.([]*model.User))
|
||||
@@ -2438,9 +2438,9 @@ func testUserStoreSearch(t *testing.T, ss store.Store) {
|
||||
Limit: 2,
|
||||
}
|
||||
|
||||
r1 := <-ss.User().Search(tid, "", searchOptions)
|
||||
require.Nil(t, r1.Err)
|
||||
assert.Len(t, r1.Data.([]*model.User), 2)
|
||||
users, err := ss.User().Search(tid, "", searchOptions)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, users, 2)
|
||||
// Don't assert contents, since Postgres' default collation order is left up to
|
||||
// the operating system, and jimbo1 might sort before or after jim-bo.
|
||||
// assertUsers(t, []*model.User{u2, u1, u6, u5}, r1.Data.([]*model.User))
|
||||
|
||||
Reference in New Issue
Block a user