Migrate "User.GetProfilesWithoutTeam" to Sync by default (#11612)

* 👤 Migrates GetProfilesWithoutTeam to Sync

* 🔬 Fix tests

* 🗣 Address CR feedback

* 🏃‍♂️ Run `make store-mocks`
Этот коммит содержится в:
Dave Lunny
2019-07-12 23:11:59 -07:00
коммит произвёл Jesús Espino
родитель 48e06e9bc4
Коммит 53f1cf1cb2
5 изменённых файлов: 51 добавлений и 50 удалений

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

@@ -583,11 +583,7 @@ func (a *App) GetUsersWithoutTeamPage(page int, perPage int, asAdmin bool, viewR
} }
func (a *App) GetUsersWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { func (a *App) GetUsersWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
result := <-a.Srv.Store.User().GetProfilesWithoutTeam(offset, limit, viewRestrictions) return a.Srv.Store.User().GetProfilesWithoutTeam(offset, limit, viewRestrictions)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
} }
// GetTeamGroupUsers returns the users who are associated to the team via GroupTeams and GroupMembers. // GetTeamGroupUsers returns the users who are associated to the team via GroupTeams and GroupMembers.

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

@@ -673,8 +673,7 @@ func (us SqlUserStore) GetProfilesNotInChannel(teamId string, channelId string,
return users, nil return users, nil
} }
func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel { func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
query := us.usersQuery. query := us.usersQuery.
Where(`( Where(`(
SELECT SELECT
@@ -692,22 +691,19 @@ func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestric
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return
} }
var users []*model.User var users []*model.User
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil { if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
result.Err = model.NewAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
return
} }
for _, u := range users { for _, u := range users {
u.Sanitize(map[string]bool{}) u.Sanitize(map[string]bool{})
} }
result.Data = users return users, nil
})
} }
func (us SqlUserStore) GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { func (us SqlUserStore) GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {

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

@@ -267,7 +267,7 @@ type UserStore interface {
GetProfilesInChannelByStatus(channelId string, offset int, limit int) StoreChannel GetProfilesInChannelByStatus(channelId string, offset int, limit int) StoreChannel
GetAllProfilesInChannel(channelId string, allowFromCache bool) (map[string]*model.User, *model.AppError) GetAllProfilesInChannel(channelId string, allowFromCache bool) (map[string]*model.User, *model.AppError)
GetProfilesNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetProfilesNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError)
GetProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) GetProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError)

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

@@ -674,19 +674,28 @@ func (_m *UserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool,
} }
// GetProfilesWithoutTeam provides a mock function with given fields: offset, limit, viewRestrictions // GetProfilesWithoutTeam provides a mock function with given fields: offset, limit, viewRestrictions
func (_m *UserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel { func (_m *UserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
ret := _m.Called(offset, limit, viewRestrictions) ret := _m.Called(offset, limit, viewRestrictions)
var r0 store.StoreChannel var r0 []*model.User
if rf, ok := ret.Get(0).(func(int, int, *model.ViewUsersRestrictions) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(int, int, *model.ViewUsersRestrictions) []*model.User); ok {
r0 = rf(offset, limit, viewRestrictions) r0 = rf(offset, limit, viewRestrictions)
} 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(int, int, *model.ViewUsersRestrictions) *model.AppError); ok {
r1 = rf(offset, limit, viewRestrictions)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetRecentlyActiveUsersForTeam provides a mock function with given fields: teamId, offset, limit, viewRestrictions // GetRecentlyActiveUsersForTeam provides a mock function with given fields: teamId, offset, limit, viewRestrictions

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

@@ -886,21 +886,21 @@ func testUserStoreGetProfilesWithoutTeam(t *testing.T, ss store.Store) {
defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }() defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }()
t.Run("get, offset 0, limit 100", func(t *testing.T) { t.Run("get, offset 0, limit 100", func(t *testing.T) {
result := <-ss.User().GetProfilesWithoutTeam(0, 100, nil) users, err := ss.User().GetProfilesWithoutTeam(0, 100, nil)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u2), sanitized(u3)}, result.Data.([]*model.User)) assert.Equal(t, []*model.User{sanitized(u2), sanitized(u3)}, users)
}) })
t.Run("get, offset 1, limit 1", func(t *testing.T) { t.Run("get, offset 1, limit 1", func(t *testing.T) {
result := <-ss.User().GetProfilesWithoutTeam(1, 1, nil) users, err := ss.User().GetProfilesWithoutTeam(1, 1, nil)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u3)}, result.Data.([]*model.User)) assert.Equal(t, []*model.User{sanitized(u3)}, users)
}) })
t.Run("get, offset 2, limit 1", func(t *testing.T) { t.Run("get, offset 2, limit 1", func(t *testing.T) {
result := <-ss.User().GetProfilesWithoutTeam(2, 1, nil) users, err := ss.User().GetProfilesWithoutTeam(2, 1, nil)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{}, result.Data.([]*model.User)) assert.Equal(t, []*model.User{}, users)
}) })
} }