[MM-16567] Migrate "User.SearchNotInTeam" to Sync by default (#11471)

Этот коммит содержится в:
Deepak Sah
2019-06-29 03:54:46 +05:30
коммит произвёл Hanzei
родитель ede426a806
Коммит f8ba59ca9e
5 изменённых файлов: 35 добавлений и 25 удалений

Просмотреть файл

@@ -1758,11 +1758,10 @@ func (a *App) SearchUsersInTeam(teamId, term string, options *model.UserSearchOp
func (a *App) SearchUsersNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) { func (a *App) SearchUsersNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
term = strings.TrimSpace(term) term = strings.TrimSpace(term)
result := <-a.Srv.Store.User().SearchNotInTeam(notInTeamId, term, options) users, err := a.Srv.Store.User().SearchNotInTeam(notInTeamId, term, options)
if result.Err != nil { if err != nil {
return nil, result.Err return nil, err
} }
users := result.Data.([]*model.User)
for _, user := range users { for _, user := range users {
a.SanitizeProfile(user, options.IsAdmin) a.SanitizeProfile(user, options.IsAdmin)

Просмотреть файл

@@ -1265,8 +1265,7 @@ func (us SqlUserStore) SearchWithoutTeam(term string, options *model.UserSearchO
return result.Data.([]*model.User), nil return result.Data.([]*model.User), nil
} }
func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) store.StoreChannel { func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
query := us.usersQuery. query := us.usersQuery.
LeftJoin("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", notInTeamId). LeftJoin("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", notInTeamId).
Where("tm.UserId IS NULL"). Where("tm.UserId IS NULL").
@@ -1277,8 +1276,11 @@ func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options
query = applyTeamGroupConstrainedFilter(query, notInTeamId) query = applyTeamGroupConstrainedFilter(query, notInTeamId)
} }
*result = us.performSearch(query, term, options) result := us.performSearch(query, term, options)
}) if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
} }
func (us SqlUserStore) SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) store.StoreChannel { func (us SqlUserStore) SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) store.StoreChannel {

Просмотреть файл

@@ -289,7 +289,7 @@ type UserStore interface {
GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) StoreChannel SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchInChannel(channelId 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 SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) StoreChannel
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)

Просмотреть файл

@@ -856,19 +856,28 @@ func (_m *UserStore) SearchNotInChannel(teamId string, channelId string, term st
} }
// SearchNotInTeam provides a mock function with given fields: notInTeamId, term, options // SearchNotInTeam provides a mock function with given fields: notInTeamId, term, options
func (_m *UserStore) SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) store.StoreChannel { func (_m *UserStore) SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
ret := _m.Called(notInTeamId, term, options) ret := _m.Called(notInTeamId, term, options)
var r0 store.StoreChannel var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, string, *model.UserSearchOptions) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, string, *model.UserSearchOptions) []*model.User); ok {
r0 = rf(notInTeamId, term, options) r0 = rf(notInTeamId, term, options)
} else { } else {
if ret.Get(0) != nil { 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(notInTeamId, term, options)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// SearchWithoutTeam provides a mock function with given fields: term, options // SearchWithoutTeam provides a mock function with given fields: term, options

Просмотреть файл

@@ -3005,13 +3005,13 @@ func testUserStoreSearchNotInTeam(t *testing.T, ss store.Store) {
for _, testCase := range testCases { for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) { t.Run(testCase.Description, func(t *testing.T) {
result := <-ss.User().SearchNotInTeam( users, err := ss.User().SearchNotInTeam(
testCase.TeamId, testCase.TeamId,
testCase.Term, testCase.Term,
testCase.Options, testCase.Options,
) )
require.Nil(t, result.Err) require.Nil(t, err)
assertUsers(t, testCase.Expected, result.Data.([]*model.User)) assertUsers(t, testCase.Expected, users)
}) })
} }
} }