mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-16567] Migrate "User.SearchNotInTeam" to Sync by default (#11471)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user