[MM-28210] sqlstore/user_store: filter deleted users for GetProfilesInChannel (#15390)

* sqlstore/user_store: filter deleted users for GetProfilesInChannel

* allow GetProfilesInChannel use userGetOptions

* sqlstore/user_store: add more test cases

* store/user_store: refine filter
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2020-09-16 11:04:17 +03:00
коммит произвёл GitHub
родитель 9c272f0b20
Коммит e69a2a41ca
14 изменённых файлов: 229 добавлений и 77 удалений

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

@@ -732,13 +732,13 @@ func (_m *UserStore) GetProfilesByUsernames(usernames []string, viewRestrictions
return r0, r1
}
// GetProfilesInChannel provides a mock function with given fields: channelId, offset, limit
func (_m *UserStore) GetProfilesInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
ret := _m.Called(channelId, offset, limit)
// GetProfilesInChannel provides a mock function with given fields: options
func (_m *UserStore) GetProfilesInChannel(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
ret := _m.Called(options)
var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
r0 = rf(channelId, offset, limit)
if rf, ok := ret.Get(0).(func(*model.UserGetOptions) []*model.User); ok {
r0 = rf(options)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.User)
@@ -746,8 +746,8 @@ func (_m *UserStore) GetProfilesInChannel(channelId string, offset int, limit in
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
r1 = rf(channelId, offset, limit)
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)
@@ -757,13 +757,13 @@ func (_m *UserStore) GetProfilesInChannel(channelId string, offset int, limit in
return r0, r1
}
// GetProfilesInChannelByStatus provides a mock function with given fields: channelId, offset, limit
func (_m *UserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
ret := _m.Called(channelId, offset, limit)
// GetProfilesInChannelByStatus provides a mock function with given fields: options
func (_m *UserStore) GetProfilesInChannelByStatus(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
ret := _m.Called(options)
var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
r0 = rf(channelId, offset, limit)
if rf, ok := ret.Get(0).(func(*model.UserGetOptions) []*model.User); ok {
r0 = rf(options)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.User)
@@ -771,8 +771,8 @@ func (_m *UserStore) GetProfilesInChannelByStatus(channelId string, offset int,
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
r1 = rf(channelId, offset, limit)
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)

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

@@ -756,6 +756,15 @@ func testUserStoreGetProfilesInChannel(t *testing.T, ss store.Store) {
u3.IsBot = true
defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }()
u4, err := ss.User().Save(&model.User{
Email: MakeEmail(),
Username: "u4" + model.NewId(),
})
require.Nil(t, err)
defer func() { require.Nil(t, ss.User().PermanentDelete(u4.Id)) }()
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u4.Id}, -1)
require.Nil(t, nErr)
ch1 := &model.Channel{
TeamId: teamId,
DisplayName: "Profiles in channel",
@@ -795,26 +804,79 @@ func testUserStoreGetProfilesInChannel(t *testing.T, ss store.Store) {
})
require.Nil(t, nErr)
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id,
UserId: u4.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(),
})
require.Nil(t, nErr)
u4.DeleteAt = 1
_, err = ss.User().Update(u4, true)
require.Nil(t, err)
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id,
UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(),
})
require.Nil(t, nErr)
t.Run("get in channel 1, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(c1.Id, 0, 100)
t.Run("get all users in channel 1, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 0,
PerPage: 100,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u1), sanitized(u2), sanitized(u3), sanitized(u4)}, users)
})
t.Run("get only active users in channel 1, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 0,
PerPage: 100,
Active: true,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u1), sanitized(u2), sanitized(u3)}, users)
})
t.Run("get in channel 1, offset 1, limit 2", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(c1.Id, 1, 2)
t.Run("get inactive users in channel 1, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 0,
PerPage: 100,
Inactive: true,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u4)}, users)
})
t.Run("get in channel 1, offset 1, limit 2", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 1,
PerPage: 1,
})
require.Nil(t, err)
users_p2, err2 := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 2,
PerPage: 1,
})
require.Nil(t, err2)
users = append(users, users_p2...)
assert.Equal(t, []*model.User{sanitized(u2), sanitized(u3)}, users)
})
t.Run("get in channel 2, offset 0, limit 1", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(c2.Id, 0, 1)
users, err := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c2.Id,
Page: 0,
PerPage: 1,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u1)}, users)
})
@@ -861,6 +923,15 @@ func testUserStoreGetProfilesInChannelByStatus(t *testing.T, ss store.Store, s S
u3.IsBot = true
defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }()
u4, err := ss.User().Save(&model.User{
Email: MakeEmail(),
Username: "u4" + model.NewId(),
})
require.Nil(t, err)
defer func() { require.Nil(t, ss.User().PermanentDelete(u4.Id)) }()
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u4.Id}, -1)
require.Nil(t, nErr)
ch1 := &model.Channel{
TeamId: teamId,
DisplayName: "Profiles in channel",
@@ -900,6 +971,17 @@ func testUserStoreGetProfilesInChannelByStatus(t *testing.T, ss store.Store, s S
})
require.Nil(t, nErr)
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id,
UserId: u4.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(),
})
require.Nil(t, nErr)
u4.DeleteAt = 1
_, err = ss.User().Update(u4, true)
require.Nil(t, err)
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id,
UserId: u1.Id,
@@ -919,14 +1001,44 @@ func testUserStoreGetProfilesInChannelByStatus(t *testing.T, ss store.Store, s S
Status: model.STATUS_ONLINE,
}))
t.Run("get in channel 1 by status, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannelByStatus(c1.Id, 0, 100)
t.Run("get all users in channel 1, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 0,
PerPage: 100,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u1), sanitized(u2), sanitized(u3), sanitized(u4)}, users)
})
t.Run("get active in channel 1 by status, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannelByStatus(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 0,
PerPage: 100,
Active: true,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u3), sanitized(u2), sanitized(u1)}, users)
})
t.Run("get inactive users in channel 1, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(&model.UserGetOptions{
InChannelId: c1.Id,
Page: 0,
PerPage: 100,
Inactive: true,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u4)}, users)
})
t.Run("get in channel 2 by status, offset 0, limit 1", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannelByStatus(c2.Id, 0, 1)
users, err := ss.User().GetProfilesInChannelByStatus(&model.UserGetOptions{
InChannelId: c2.Id,
Page: 0,
PerPage: 1,
})
require.Nil(t, err)
assert.Equal(t, []*model.User{sanitized(u1)}, users)
})