Migrate User.GetAllProfiles to sync by default (#11513)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
b738e02c15
Коммит
9839b46889
@@ -447,11 +447,7 @@ func (a *App) GetUserByAuth(authData *string, authService string) (*model.User,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
|
func (a *App) GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
|
||||||
result := <-a.Srv.Store.User().GetAllProfiles(options)
|
return a.Srv.Store.User().GetAllProfiles(options)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.([]*model.User), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) {
|
func (a *App) GetUsersPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||||
|
|||||||
@@ -392,39 +392,35 @@ func (s SqlUserStore) GetEtagForAllProfiles() store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetAllProfiles(options *model.UserGetOptions) store.StoreChannel {
|
func (us SqlUserStore) GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
|
||||||
isPostgreSQL := us.DriverName() == model.DATABASE_DRIVER_POSTGRES
|
isPostgreSQL := us.DriverName() == model.DATABASE_DRIVER_POSTGRES
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query := us.usersQuery.
|
||||||
query := us.usersQuery.
|
OrderBy("u.Username ASC").
|
||||||
OrderBy("u.Username ASC").
|
Offset(uint64(options.Page * options.PerPage)).Limit(uint64(options.PerPage))
|
||||||
Offset(uint64(options.Page * options.PerPage)).Limit(uint64(options.PerPage))
|
|
||||||
|
|
||||||
query = applyViewRestrictionsFilter(query, options.ViewRestrictions, true)
|
query = applyViewRestrictionsFilter(query, options.ViewRestrictions, true)
|
||||||
|
|
||||||
query = applyRoleFilter(query, options.Role, isPostgreSQL)
|
query = applyRoleFilter(query, options.Role, isPostgreSQL)
|
||||||
|
|
||||||
if options.Inactive {
|
if options.Inactive {
|
||||||
query = query.Where("u.DeleteAt != 0")
|
query = query.Where("u.DeleteAt != 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
queryString, args, err := query.ToSql()
|
queryString, args, err := query.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlUserStore.GetAllProfiles", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlUserStore.GetAllProfiles", "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.GetAllProfiles", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlUserStore.GetAllProfiles", "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 applyRoleFilter(query sq.SelectBuilder, role string, isPostgreSQL bool) sq.SelectBuilder {
|
func applyRoleFilter(query sq.SelectBuilder, role string, isPostgreSQL bool) sq.SelectBuilder {
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ type UserStore interface {
|
|||||||
GetProfilesNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
GetProfilesNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
||||||
GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
||||||
GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
||||||
GetAllProfiles(options *model.UserGetOptions) StoreChannel
|
GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
||||||
GetProfiles(options *model.UserGetOptions) StoreChannel
|
GetProfiles(options *model.UserGetOptions) StoreChannel
|
||||||
GetProfileByIds(userIds []string, options *UserGetByIdsOpts, allowFromCache bool) ([]*model.User, *model.AppError)
|
GetProfileByIds(userIds []string, options *UserGetByIdsOpts, allowFromCache bool) ([]*model.User, *model.AppError)
|
||||||
GetProfileByGroupChannelIdsForUser(userId string, channelIds []string) (map[string][]*model.User, *model.AppError)
|
GetProfileByGroupChannelIdsForUser(userId string, channelIds []string) (map[string][]*model.User, *model.AppError)
|
||||||
|
|||||||
@@ -193,19 +193,28 @@ func (_m *UserStore) GetAllAfter(limit int, afterId string) ([]*model.User, *mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllProfiles provides a mock function with given fields: options
|
// GetAllProfiles provides a mock function with given fields: options
|
||||||
func (_m *UserStore) GetAllProfiles(options *model.UserGetOptions) store.StoreChannel {
|
func (_m *UserStore) GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
|
||||||
ret := _m.Called(options)
|
ret := _m.Called(options)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.User
|
||||||
if rf, ok := ret.Get(0).(func(*model.UserGetOptions) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(*model.UserGetOptions) []*model.User); ok {
|
||||||
r0 = rf(options)
|
r0 = rf(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(*model.UserGetOptions) *model.AppError); ok {
|
||||||
|
r1 = rf(options)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllProfilesInChannel provides a mock function with given fields: channelId, allowFromCache
|
// GetAllProfilesInChannel provides a mock function with given fields: channelId, allowFromCache
|
||||||
|
|||||||
@@ -415,10 +415,9 @@ func testUserStoreGetAllProfiles(t *testing.T, ss store.Store) {
|
|||||||
|
|
||||||
t.Run("get offset 0, limit 100", func(t *testing.T) {
|
t.Run("get offset 0, limit 100", func(t *testing.T) {
|
||||||
options := &model.UserGetOptions{Page: 0, PerPage: 100}
|
options := &model.UserGetOptions{Page: 0, PerPage: 100}
|
||||||
result := <-ss.User().GetAllProfiles(options)
|
actual, err := ss.User().GetAllProfiles(options)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
actual := result.Data.([]*model.User)
|
|
||||||
require.Equal(t, []*model.User{
|
require.Equal(t, []*model.User{
|
||||||
sanitized(u1),
|
sanitized(u1),
|
||||||
sanitized(u2),
|
sanitized(u2),
|
||||||
@@ -431,12 +430,11 @@ func testUserStoreGetAllProfiles(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get offset 0, limit 1", func(t *testing.T) {
|
t.Run("get offset 0, limit 1", func(t *testing.T) {
|
||||||
result := <-ss.User().GetAllProfiles(&model.UserGetOptions{
|
actual, err := ss.User().GetAllProfiles(&model.UserGetOptions{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
PerPage: 1,
|
PerPage: 1,
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
actual := result.Data.([]*model.User)
|
|
||||||
require.Equal(t, []*model.User{
|
require.Equal(t, []*model.User{
|
||||||
sanitized(u1),
|
sanitized(u1),
|
||||||
}, actual)
|
}, actual)
|
||||||
@@ -476,13 +474,12 @@ func testUserStoreGetAllProfiles(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("filter to system_admin role", func(t *testing.T) {
|
t.Run("filter to system_admin role", func(t *testing.T) {
|
||||||
result := <-ss.User().GetAllProfiles(&model.UserGetOptions{
|
actual, err := ss.User().GetAllProfiles(&model.UserGetOptions{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
PerPage: 10,
|
PerPage: 10,
|
||||||
Role: "system_admin",
|
Role: "system_admin",
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
actual := result.Data.([]*model.User)
|
|
||||||
require.Equal(t, []*model.User{
|
require.Equal(t, []*model.User{
|
||||||
sanitized(u5),
|
sanitized(u5),
|
||||||
sanitized(u6),
|
sanitized(u6),
|
||||||
@@ -490,27 +487,25 @@ func testUserStoreGetAllProfiles(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("filter to system_admin role, inactive", func(t *testing.T) {
|
t.Run("filter to system_admin role, inactive", func(t *testing.T) {
|
||||||
result := <-ss.User().GetAllProfiles(&model.UserGetOptions{
|
actual, err := ss.User().GetAllProfiles(&model.UserGetOptions{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
PerPage: 10,
|
PerPage: 10,
|
||||||
Role: "system_admin",
|
Role: "system_admin",
|
||||||
Inactive: true,
|
Inactive: true,
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
actual := result.Data.([]*model.User)
|
|
||||||
require.Equal(t, []*model.User{
|
require.Equal(t, []*model.User{
|
||||||
sanitized(u6),
|
sanitized(u6),
|
||||||
}, actual)
|
}, actual)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("filter to inactive", func(t *testing.T) {
|
t.Run("filter to inactive", func(t *testing.T) {
|
||||||
result := <-ss.User().GetAllProfiles(&model.UserGetOptions{
|
actual, err := ss.User().GetAllProfiles(&model.UserGetOptions{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
PerPage: 10,
|
PerPage: 10,
|
||||||
Inactive: true,
|
Inactive: true,
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
actual := result.Data.([]*model.User)
|
|
||||||
require.Equal(t, []*model.User{
|
require.Equal(t, []*model.User{
|
||||||
sanitized(u6),
|
sanitized(u6),
|
||||||
sanitized(u7),
|
sanitized(u7),
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user