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

This commit is contained in:
Deepak Sah
2019-06-29 03:54:46 +05:30
committed by Hanzei
parent ede426a806
commit f8ba59ca9e
5 changed files with 35 additions and 25 deletions

View File

@@ -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) {
term = strings.TrimSpace(term)
result := <-a.Srv.Store.User().SearchNotInTeam(notInTeamId, term, options)
if result.Err != nil {
return nil, result.Err
users, err := a.Srv.Store.User().SearchNotInTeam(notInTeamId, term, options)
if err != nil {
return nil, err
}
users := result.Data.([]*model.User)
for _, user := range users {
a.SanitizeProfile(user, options.IsAdmin)

View File

@@ -1265,20 +1265,22 @@ func (us SqlUserStore) SearchWithoutTeam(term string, options *model.UserSearchO
return result.Data.([]*model.User), nil
}
func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
query := us.usersQuery.
LeftJoin("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", notInTeamId).
Where("tm.UserId IS NULL").
OrderBy("u.Username ASC").
Limit(uint64(options.Limit))
func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
query := us.usersQuery.
LeftJoin("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", notInTeamId).
Where("tm.UserId IS NULL").
OrderBy("u.Username ASC").
Limit(uint64(options.Limit))
if options.GroupConstrained {
query = applyTeamGroupConstrainedFilter(query, notInTeamId)
}
if options.GroupConstrained {
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 {

View File

@@ -289,7 +289,7 @@ type UserStore interface {
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)
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
SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) StoreChannel
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)

View File

@@ -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
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)
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(notInTeamId, 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(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

View File

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