mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrate "User.GetProfilesWithoutTeam" to Sync by default (#11612)
* 👤 Migrates GetProfilesWithoutTeam to Sync * 🔬 Fix tests * 🗣 Address CR feedback * 🏃♂️ Run `make store-mocks`
This commit is contained in:
@@ -673,41 +673,37 @@ func (us SqlUserStore) GetProfilesNotInChannel(teamId string, channelId string,
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := us.usersQuery.
|
||||
Where(`(
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
TeamMembers
|
||||
WHERE
|
||||
TeamMembers.UserId = u.Id
|
||||
AND TeamMembers.DeleteAt = 0
|
||||
) = 0`).
|
||||
OrderBy("u.Username ASC").
|
||||
Offset(uint64(offset)).Limit(uint64(limit))
|
||||
func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||
query := us.usersQuery.
|
||||
Where(`(
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
TeamMembers
|
||||
WHERE
|
||||
TeamMembers.UserId = u.Id
|
||||
AND TeamMembers.DeleteAt = 0
|
||||
) = 0`).
|
||||
OrderBy("u.Username ASC").
|
||||
Offset(uint64(offset)).Limit(uint64(limit))
|
||||
|
||||
query = applyViewRestrictionsFilter(query, viewRestrictions, true)
|
||||
query = applyViewRestrictionsFilter(query, viewRestrictions, true)
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var users []*model.User
|
||||
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
|
||||
}
|
||||
var users []*model.User
|
||||
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, u := range users {
|
||||
u.Sanitize(map[string]bool{})
|
||||
}
|
||||
for _, u := range users {
|
||||
u.Sanitize(map[string]bool{})
|
||||
}
|
||||
|
||||
result.Data = users
|
||||
})
|
||||
return users, nil
|
||||
}
|
||||
|
||||
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
|
||||
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)
|
||||
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)
|
||||
GetAllProfiles(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
|
||||
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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(int, int, *model.ViewUsersRestrictions) store.StoreChannel); ok {
|
||||
var r0 []*model.User
|
||||
if rf, ok := ret.Get(0).(func(int, int, *model.ViewUsersRestrictions) []*model.User); ok {
|
||||
r0 = rf(offset, limit, viewRestrictions)
|
||||
} 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(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
|
||||
|
||||
@@ -886,21 +886,21 @@ func testUserStoreGetProfilesWithoutTeam(t *testing.T, ss store.Store) {
|
||||
defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }()
|
||||
|
||||
t.Run("get, offset 0, limit 100", func(t *testing.T) {
|
||||
result := <-ss.User().GetProfilesWithoutTeam(0, 100, nil)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, []*model.User{sanitized(u2), sanitized(u3)}, result.Data.([]*model.User))
|
||||
users, err := ss.User().GetProfilesWithoutTeam(0, 100, nil)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, []*model.User{sanitized(u2), sanitized(u3)}, users)
|
||||
})
|
||||
|
||||
t.Run("get, offset 1, limit 1", func(t *testing.T) {
|
||||
result := <-ss.User().GetProfilesWithoutTeam(1, 1, nil)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, []*model.User{sanitized(u3)}, result.Data.([]*model.User))
|
||||
users, err := ss.User().GetProfilesWithoutTeam(1, 1, nil)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, []*model.User{sanitized(u3)}, users)
|
||||
})
|
||||
|
||||
t.Run("get, offset 2, limit 1", func(t *testing.T) {
|
||||
result := <-ss.User().GetProfilesWithoutTeam(2, 1, nil)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, []*model.User{}, result.Data.([]*model.User))
|
||||
users, err := ss.User().GetProfilesWithoutTeam(2, 1, nil)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, []*model.User{}, users)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user