Migrate 'User.GetProfilesNotInTeam' to Sync by default (#11420)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
bcaab359a4
Коммит
0b6e4e2f16
@@ -476,11 +476,7 @@ func (a *App) GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
func (a *App) GetUsersNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||||
result := <-a.Srv.Store.User().GetProfilesNotInTeam(teamId, groupConstrained, offset, limit, viewRestrictions)
|
return a.Srv.Store.User().GetProfilesNotInTeam(teamId, groupConstrained, offset, limit, viewRestrictions)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.([]*model.User), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersInTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) {
|
func (a *App) GetUsersInTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||||
|
|||||||
@@ -1435,38 +1435,33 @@ func (us SqlUserStore) AnalyticsGetSystemAdminCount() (int64, *model.AppError) {
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel {
|
func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var users []*model.User
|
||||||
query := us.usersQuery.
|
query := us.usersQuery.
|
||||||
LeftJoin("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", teamId).
|
LeftJoin("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", teamId).
|
||||||
Where("tm.UserId IS NULL").
|
Where("tm.UserId IS NULL").
|
||||||
OrderBy("u.Username ASC").
|
OrderBy("u.Username ASC").
|
||||||
Offset(uint64(offset)).Limit(uint64(limit))
|
Offset(uint64(offset)).Limit(uint64(limit))
|
||||||
|
|
||||||
query = applyViewRestrictionsFilter(query, viewRestrictions, true)
|
query = applyViewRestrictionsFilter(query, viewRestrictions, true)
|
||||||
|
|
||||||
if groupConstrained {
|
if groupConstrained {
|
||||||
query = applyTeamGroupConstrainedFilter(query, teamId)
|
query = applyTeamGroupConstrainedFilter(query, teamId)
|
||||||
}
|
}
|
||||||
|
|
||||||
queryString, args, err := query.ToSql()
|
queryString, args, err := query.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlUserStore.GetProfilesNotInTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlUserStore.GetProfilesNotInTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var users []*model.User
|
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||||
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
return nil, model.NewAppError("SqlUserStore.GetProfilesNotInTeam", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
result.Err = model.NewAppError("SqlUserStore.GetProfilesNotInTeam", "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{})
|
||||||
}
|
}
|
||||||
|
return users, nil
|
||||||
result.Data = users
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) store.StoreChannel {
|
func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) store.StoreChannel {
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ type UserStore interface {
|
|||||||
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
|
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
|
||||||
AnalyticsGetSystemAdminCount() (int64, *model.AppError)
|
AnalyticsGetSystemAdminCount() (int64, *model.AppError)
|
||||||
GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetEtagForProfilesNotInTeam(teamId string) StoreChannel
|
GetEtagForProfilesNotInTeam(teamId string) StoreChannel
|
||||||
ClearAllCustomRoleAssignments() StoreChannel
|
ClearAllCustomRoleAssignments() StoreChannel
|
||||||
InferSystemInstallDate() StoreChannel
|
InferSystemInstallDate() StoreChannel
|
||||||
|
|||||||
@@ -567,19 +567,28 @@ func (_m *UserStore) GetProfilesNotInChannel(teamId string, channelId string, gr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetProfilesNotInTeam provides a mock function with given fields: teamId, groupConstrained, offset, limit, viewRestrictions
|
// GetProfilesNotInTeam provides a mock function with given fields: teamId, groupConstrained, offset, limit, viewRestrictions
|
||||||
func (_m *UserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel {
|
func (_m *UserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||||
ret := _m.Called(teamId, groupConstrained, offset, limit, viewRestrictions)
|
ret := _m.Called(teamId, groupConstrained, offset, limit, viewRestrictions)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.User
|
||||||
if rf, ok := ret.Get(0).(func(string, bool, int, int, *model.ViewUsersRestrictions) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, bool, int, int, *model.ViewUsersRestrictions) []*model.User); ok {
|
||||||
r0 = rf(teamId, groupConstrained, offset, limit, viewRestrictions)
|
r0 = rf(teamId, groupConstrained, 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(string, bool, int, int, *model.ViewUsersRestrictions) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId, groupConstrained, offset, limit, viewRestrictions)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProfilesWithoutTeam provides a mock function with given fields: offset, limit, viewRestrictions
|
// GetProfilesWithoutTeam provides a mock function with given fields: offset, limit, viewRestrictions
|
||||||
|
|||||||
@@ -3342,29 +3342,29 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get not in team 1, offset 0, limit 100000", func(t *testing.T) {
|
t.Run("get not in team 1, offset 0, limit 100000", func(t *testing.T) {
|
||||||
result := <-ss.User().GetProfilesNotInTeam(teamId, false, 0, 100000, nil)
|
users, userErr := ss.User().GetProfilesNotInTeam(teamId, false, 0, 100000, nil)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, userErr)
|
||||||
assert.Equal(t, []*model.User{
|
assert.Equal(t, []*model.User{
|
||||||
sanitized(u2),
|
sanitized(u2),
|
||||||
sanitized(u3),
|
sanitized(u3),
|
||||||
}, result.Data.([]*model.User))
|
}, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get not in team 1, offset 1, limit 1", func(t *testing.T) {
|
t.Run("get not in team 1, offset 1, limit 1", func(t *testing.T) {
|
||||||
result := <-ss.User().GetProfilesNotInTeam(teamId, false, 1, 1, nil)
|
users, userErr := ss.User().GetProfilesNotInTeam(teamId, false, 1, 1, nil)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, userErr)
|
||||||
assert.Equal(t, []*model.User{
|
assert.Equal(t, []*model.User{
|
||||||
sanitized(u3),
|
sanitized(u3),
|
||||||
}, result.Data.([]*model.User))
|
}, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get not in team 2, offset 0, limit 100", func(t *testing.T) {
|
t.Run("get not in team 2, offset 0, limit 100", func(t *testing.T) {
|
||||||
result := <-ss.User().GetProfilesNotInTeam(teamId2, false, 0, 100, nil)
|
users, userErr := ss.User().GetProfilesNotInTeam(teamId2, false, 0, 100, nil)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, userErr)
|
||||||
assert.Equal(t, []*model.User{
|
assert.Equal(t, []*model.User{
|
||||||
sanitized(u1),
|
sanitized(u1),
|
||||||
sanitized(u3),
|
sanitized(u3),
|
||||||
}, result.Data.([]*model.User))
|
}, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Ensure update at timestamp changes
|
// Ensure update at timestamp changes
|
||||||
@@ -3382,11 +3382,11 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get not in team 1, offset 0, limit 100000 after update", func(t *testing.T) {
|
t.Run("get not in team 1, offset 0, limit 100000 after update", func(t *testing.T) {
|
||||||
result := <-ss.User().GetProfilesNotInTeam(teamId, false, 0, 100000, nil)
|
users, userErr := ss.User().GetProfilesNotInTeam(teamId, false, 0, 100000, nil)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, userErr)
|
||||||
assert.Equal(t, []*model.User{
|
assert.Equal(t, []*model.User{
|
||||||
sanitized(u3),
|
sanitized(u3),
|
||||||
}, result.Data.([]*model.User))
|
}, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Ensure update at timestamp changes
|
// Ensure update at timestamp changes
|
||||||
@@ -3406,13 +3406,13 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get not in team 1, offset 0, limit 100000 after second update", func(t *testing.T) {
|
t.Run("get not in team 1, offset 0, limit 100000 after second update", func(t *testing.T) {
|
||||||
result := <-ss.User().GetProfilesNotInTeam(teamId, false, 0, 100000, nil)
|
users, userErr := ss.User().GetProfilesNotInTeam(teamId, false, 0, 100000, nil)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, userErr)
|
||||||
assert.Equal(t, []*model.User{
|
assert.Equal(t, []*model.User{
|
||||||
sanitized(u1),
|
sanitized(u1),
|
||||||
sanitized(u2),
|
sanitized(u2),
|
||||||
sanitized(u3),
|
sanitized(u3),
|
||||||
}, result.Data.([]*model.User))
|
}, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Ensure update at timestamp changes
|
// Ensure update at timestamp changes
|
||||||
@@ -3450,9 +3450,9 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get not in team 1, offset 0, limit 100000 after second update, setting group constrained when it's not", func(t *testing.T) {
|
t.Run("get not in team 1, offset 0, limit 100000 after second update, setting group constrained when it's not", func(t *testing.T) {
|
||||||
result := <-ss.User().GetProfilesNotInTeam(teamId, true, 0, 100000, nil)
|
users, userErr := ss.User().GetProfilesNotInTeam(teamId, true, 0, 100000, nil)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, userErr)
|
||||||
assert.Empty(t, result.Data.([]*model.User))
|
assert.Empty(t, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
// create a group
|
// create a group
|
||||||
@@ -3479,12 +3479,12 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
t.Run("get not in team 1, offset 0, limit 100000 after second update, setting group constrained", func(t *testing.T) {
|
t.Run("get not in team 1, offset 0, limit 100000 after second update, setting group constrained", func(t *testing.T) {
|
||||||
result := <-ss.User().GetProfilesNotInTeam(teamId, true, 0, 100000, nil)
|
users, userErr := ss.User().GetProfilesNotInTeam(teamId, true, 0, 100000, nil)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, userErr)
|
||||||
assert.Equal(t, []*model.User{
|
assert.Equal(t, []*model.User{
|
||||||
sanitized(u1),
|
sanitized(u1),
|
||||||
sanitized(u2),
|
sanitized(u2),
|
||||||
}, result.Data.([]*model.User))
|
}, users)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user