diff --git a/api4/user.go b/api4/user.go index 927971c4f2..bfdd7baad8 100644 --- a/api4/user.go +++ b/api4/user.go @@ -557,7 +557,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) { return } - profiles, err = c.App.GetUsersWithoutTeamPage(c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions) + profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin()) } else if len(notInChannelId) > 0 { if !c.App.SessionHasPermissionToChannel(c.App.Session, notInChannelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) diff --git a/app/user.go b/app/user.go index bc5da8a814..da2e016c21 100644 --- a/app/user.go +++ b/app/user.go @@ -589,8 +589,8 @@ func (a *App) GetUsersNotInChannelPage(teamId string, channelId string, groupCon return a.sanitizeProfiles(users, asAdmin), nil } -func (a *App) GetUsersWithoutTeamPage(page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { - users, err := a.GetUsersWithoutTeam(page*perPage, perPage, viewRestrictions) +func (a *App) GetUsersWithoutTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) { + users, err := a.GetUsersWithoutTeam(options) if err != nil { return nil, err } @@ -598,8 +598,8 @@ func (a *App) GetUsersWithoutTeamPage(page int, perPage int, asAdmin bool, viewR return a.sanitizeProfiles(users, asAdmin), nil } -func (a *App) GetUsersWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { - return a.Srv.Store.User().GetProfilesWithoutTeam(offset, limit, viewRestrictions) +func (a *App) GetUsersWithoutTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) { + return a.Srv.Store.User().GetProfilesWithoutTeam(options) } // GetTeamGroupUsers returns the users who are associated to the team via GroupTeams and GroupMembers. diff --git a/app/user_viewmembers_test.go b/app/user_viewmembers_test.go index 7a87b28177..2668bc14ac 100644 --- a/app/user_viewmembers_test.go +++ b/app/user_viewmembers_test.go @@ -618,7 +618,7 @@ func TestResctrictedViewMembers(t *testing.T) { for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { - results, err := th.App.GetUsersWithoutTeam(0, 100, tc.Restrictions) + results, err := th.App.GetUsersWithoutTeam(&model.UserGetOptions{Page: 0, PerPage: 100, ViewRestrictions: tc.Restrictions}) require.Nil(t, err) ids := []string{} for _, result := range results { diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 5a8fc3fe75..5febcc88e0 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -667,7 +667,8 @@ func (us SqlUserStore) GetProfilesNotInChannel(teamId string, channelId string, return users, nil } -func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { +func (us SqlUserStore) GetProfilesWithoutTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) { + isPostgreSQL := us.DriverName() == model.DATABASE_DRIVER_POSTGRES query := us.usersQuery. Where(`( SELECT @@ -679,9 +680,15 @@ func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestric AND TeamMembers.DeleteAt = 0 ) = 0`). OrderBy("u.Username ASC"). - Offset(uint64(offset)).Limit(uint64(limit)) + Offset(uint64(options.Page * options.PerPage)).Limit(uint64(options.PerPage)) - query = applyViewRestrictionsFilter(query, viewRestrictions, true) + query = applyViewRestrictionsFilter(query, options.ViewRestrictions, true) + + query = applyRoleFilter(query, options.Role, isPostgreSQL) + + if options.Inactive { + query = query.Where("u.DeleteAt != 0") + } queryString, args, err := query.ToSql() if err != nil { diff --git a/store/store.go b/store/store.go index cc96278eee..9ad3324a02 100644 --- a/store/store.go +++ b/store/store.go @@ -253,7 +253,7 @@ type UserStore interface { GetProfilesInChannelByStatus(channelId string, offset int, limit int) ([]*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) - GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) + GetProfilesWithoutTeam(options *model.UserGetOptions) ([]*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) diff --git a/store/storetest/mocks/LayeredStoreDatabaseLayer.go b/store/storetest/mocks/LayeredStoreDatabaseLayer.go index cb0ab438f5..6414b80649 100644 --- a/store/storetest/mocks/LayeredStoreDatabaseLayer.go +++ b/store/storetest/mocks/LayeredStoreDatabaseLayer.go @@ -5,12 +5,8 @@ package mocks import ( - context "context" - - model "github.com/mattermost/mattermost-server/model" - mock "github.com/stretchr/testify/mock" - store "github.com/mattermost/mattermost-server/store" + mock "github.com/stretchr/testify/mock" ) // LayeredStoreDatabaseLayer is an autogenerated mock type for the LayeredStoreDatabaseLayer type @@ -404,221 +400,6 @@ func (_m *LayeredStoreDatabaseLayer) Role() store.RoleStore { return r0 } -// RoleDelete provides a mock function with given fields: ctx, roldId, hints -func (_m *LayeredStoreDatabaseLayer) RoleDelete(ctx context.Context, roldId string, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, roldId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, roldId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, roldId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGet provides a mock function with given fields: ctx, roleId, hints -func (_m *LayeredStoreDatabaseLayer) RoleGet(ctx context.Context, roleId string, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, roleId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, roleId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, roleId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGetAll provides a mock function with given fields: ctx, hints -func (_m *LayeredStoreDatabaseLayer) RoleGetAll(ctx context.Context, hints ...store.LayeredStoreHint) ([]*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 []*model.Role - if rf, ok := ret.Get(0).(func(context.Context, ...store.LayeredStoreHint) []*model.Role); ok { - r0 = rf(ctx, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGetByName provides a mock function with given fields: ctx, name, hints -func (_m *LayeredStoreDatabaseLayer) RoleGetByName(ctx context.Context, name string, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, name) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, name, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, name, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGetByNames provides a mock function with given fields: ctx, names, hints -func (_m *LayeredStoreDatabaseLayer) RoleGetByNames(ctx context.Context, names []string, hints ...store.LayeredStoreHint) ([]*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, names) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 []*model.Role - if rf, ok := ret.Get(0).(func(context.Context, []string, ...store.LayeredStoreHint) []*model.Role); ok { - r0 = rf(ctx, names, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, []string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, names, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RolePermanentDeleteAll provides a mock function with given fields: ctx, hints -func (_m *LayeredStoreDatabaseLayer) RolePermanentDeleteAll(ctx context.Context, hints ...store.LayeredStoreHint) *model.AppError { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(context.Context, ...store.LayeredStoreHint) *model.AppError); ok { - r0 = rf(ctx, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } - } - - return r0 -} - -// RoleSave provides a mock function with given fields: ctx, role, hints -func (_m *LayeredStoreDatabaseLayer) RoleSave(ctx context.Context, role *model.Role, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, role) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, *model.Role, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, role, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, *model.Role, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, role, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - // Scheme provides a mock function with given fields: func (_m *LayeredStoreDatabaseLayer) Scheme() store.SchemeStore { ret := _m.Called() @@ -635,189 +416,6 @@ func (_m *LayeredStoreDatabaseLayer) Scheme() store.SchemeStore { return r0 } -// SchemeDelete provides a mock function with given fields: ctx, schemeId, hints -func (_m *LayeredStoreDatabaseLayer) SchemeDelete(ctx context.Context, schemeId string, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, schemeId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemeGet provides a mock function with given fields: ctx, schemeId, hints -func (_m *LayeredStoreDatabaseLayer) SchemeGet(ctx context.Context, schemeId string, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, schemeId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemeGetAllPage provides a mock function with given fields: ctx, scope, offset, limit, hints -func (_m *LayeredStoreDatabaseLayer) SchemeGetAllPage(ctx context.Context, scope string, offset int, limit int, hints ...store.LayeredStoreHint) ([]*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, scope, offset, limit) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 []*model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, int, int, ...store.LayeredStoreHint) []*model.Scheme); ok { - r0 = rf(ctx, scope, offset, limit, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, int, int, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, scope, offset, limit, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemeGetByName provides a mock function with given fields: ctx, schemeName, hints -func (_m *LayeredStoreDatabaseLayer) SchemeGetByName(ctx context.Context, schemeName string, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, schemeName) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, schemeName, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, schemeName, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemePermanentDeleteAll provides a mock function with given fields: ctx, hints -func (_m *LayeredStoreDatabaseLayer) SchemePermanentDeleteAll(ctx context.Context, hints ...store.LayeredStoreHint) *model.AppError { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(context.Context, ...store.LayeredStoreHint) *model.AppError); ok { - r0 = rf(ctx, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } - } - - return r0 -} - -// SchemeSave provides a mock function with given fields: ctx, scheme, hints -func (_m *LayeredStoreDatabaseLayer) SchemeSave(ctx context.Context, scheme *model.Scheme, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, scheme) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, *model.Scheme, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, scheme, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, *model.Scheme, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, scheme, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - // Session provides a mock function with given fields: func (_m *LayeredStoreDatabaseLayer) Session() store.SessionStore { ret := _m.Called() diff --git a/store/storetest/mocks/LayeredStoreSupplier.go b/store/storetest/mocks/LayeredStoreSupplier.go index 6d4e655e22..18f9642bf8 100644 --- a/store/storetest/mocks/LayeredStoreSupplier.go +++ b/store/storetest/mocks/LayeredStoreSupplier.go @@ -5,12 +5,8 @@ package mocks import ( - context "context" - - model "github.com/mattermost/mattermost-server/model" - mock "github.com/stretchr/testify/mock" - store "github.com/mattermost/mattermost-server/store" + mock "github.com/stretchr/testify/mock" ) // LayeredStoreSupplier is an autogenerated mock type for the LayeredStoreSupplier type @@ -34,404 +30,6 @@ func (_m *LayeredStoreSupplier) Next() store.LayeredStoreSupplier { return r0 } -// RoleDelete provides a mock function with given fields: ctx, roldId, hints -func (_m *LayeredStoreSupplier) RoleDelete(ctx context.Context, roldId string, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, roldId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, roldId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, roldId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGet provides a mock function with given fields: ctx, roleId, hints -func (_m *LayeredStoreSupplier) RoleGet(ctx context.Context, roleId string, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, roleId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, roleId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, roleId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGetAll provides a mock function with given fields: ctx, hints -func (_m *LayeredStoreSupplier) RoleGetAll(ctx context.Context, hints ...store.LayeredStoreHint) ([]*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 []*model.Role - if rf, ok := ret.Get(0).(func(context.Context, ...store.LayeredStoreHint) []*model.Role); ok { - r0 = rf(ctx, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGetByName provides a mock function with given fields: ctx, name, hints -func (_m *LayeredStoreSupplier) RoleGetByName(ctx context.Context, name string, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, name) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, name, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, name, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RoleGetByNames provides a mock function with given fields: ctx, names, hints -func (_m *LayeredStoreSupplier) RoleGetByNames(ctx context.Context, names []string, hints ...store.LayeredStoreHint) ([]*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, names) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 []*model.Role - if rf, ok := ret.Get(0).(func(context.Context, []string, ...store.LayeredStoreHint) []*model.Role); ok { - r0 = rf(ctx, names, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, []string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, names, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// RolePermanentDeleteAll provides a mock function with given fields: ctx, hints -func (_m *LayeredStoreSupplier) RolePermanentDeleteAll(ctx context.Context, hints ...store.LayeredStoreHint) *model.AppError { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(context.Context, ...store.LayeredStoreHint) *model.AppError); ok { - r0 = rf(ctx, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } - } - - return r0 -} - -// RoleSave provides a mock function with given fields: ctx, role, hints -func (_m *LayeredStoreSupplier) RoleSave(ctx context.Context, role *model.Role, hints ...store.LayeredStoreHint) (*model.Role, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, role) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Role - if rf, ok := ret.Get(0).(func(context.Context, *model.Role, ...store.LayeredStoreHint) *model.Role); ok { - r0 = rf(ctx, role, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Role) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, *model.Role, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, role, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemeDelete provides a mock function with given fields: ctx, schemeId, hints -func (_m *LayeredStoreSupplier) SchemeDelete(ctx context.Context, schemeId string, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, schemeId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemeGet provides a mock function with given fields: ctx, schemeId, hints -func (_m *LayeredStoreSupplier) SchemeGet(ctx context.Context, schemeId string, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, schemeId) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, schemeId, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemeGetAllPage provides a mock function with given fields: ctx, scope, offset, limit, hints -func (_m *LayeredStoreSupplier) SchemeGetAllPage(ctx context.Context, scope string, offset int, limit int, hints ...store.LayeredStoreHint) ([]*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, scope, offset, limit) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 []*model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, int, int, ...store.LayeredStoreHint) []*model.Scheme); ok { - r0 = rf(ctx, scope, offset, limit, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, int, int, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, scope, offset, limit, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemeGetByName provides a mock function with given fields: ctx, schemeName, hints -func (_m *LayeredStoreSupplier) SchemeGetByName(ctx context.Context, schemeName string, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, schemeName) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, string, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, schemeName, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, string, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, schemeName, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - -// SchemePermanentDeleteAll provides a mock function with given fields: ctx, hints -func (_m *LayeredStoreSupplier) SchemePermanentDeleteAll(ctx context.Context, hints ...store.LayeredStoreHint) *model.AppError { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(context.Context, ...store.LayeredStoreHint) *model.AppError); ok { - r0 = rf(ctx, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } - } - - return r0 -} - -// SchemeSave provides a mock function with given fields: ctx, scheme, hints -func (_m *LayeredStoreSupplier) SchemeSave(ctx context.Context, scheme *model.Scheme, hints ...store.LayeredStoreHint) (*model.Scheme, *model.AppError) { - _va := make([]interface{}, len(hints)) - for _i := range hints { - _va[_i] = hints[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, scheme) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *model.Scheme - if rf, ok := ret.Get(0).(func(context.Context, *model.Scheme, ...store.LayeredStoreHint) *model.Scheme); ok { - r0 = rf(ctx, scheme, hints...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Scheme) - } - } - - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(context.Context, *model.Scheme, ...store.LayeredStoreHint) *model.AppError); ok { - r1 = rf(ctx, scheme, hints...) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } - } - - return r0, r1 -} - // SetChainNext provides a mock function with given fields: _a0 func (_m *LayeredStoreSupplier) SetChainNext(_a0 store.LayeredStoreSupplier) { _m.Called(_a0) diff --git a/store/storetest/mocks/SqlSupplier.go b/store/storetest/mocks/SqlSupplier.go index 4a844524d3..2b4f7c746f 100644 --- a/store/storetest/mocks/SqlSupplier.go +++ b/store/storetest/mocks/SqlSupplier.go @@ -4,8 +4,10 @@ package mocks -import gorp "github.com/mattermost/gorp" -import mock "github.com/stretchr/testify/mock" +import ( + gorp "github.com/mattermost/gorp" + mock "github.com/stretchr/testify/mock" +) // SqlSupplier is an autogenerated mock type for the SqlSupplier type type SqlSupplier struct { diff --git a/store/storetest/mocks/UserStore.go b/store/storetest/mocks/UserStore.go index e901c81d70..43931cd758 100644 --- a/store/storetest/mocks/UserStore.go +++ b/store/storetest/mocks/UserStore.go @@ -709,13 +709,13 @@ func (_m *UserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool, return r0, r1 } -// GetProfilesWithoutTeam provides a mock function with given fields: offset, limit, viewRestrictions -func (_m *UserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { - ret := _m.Called(offset, limit, viewRestrictions) +// GetProfilesWithoutTeam provides a mock function with given fields: options +func (_m *UserStore) GetProfilesWithoutTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) { + ret := _m.Called(options) var r0 []*model.User - if rf, ok := ret.Get(0).(func(int, int, *model.ViewUsersRestrictions) []*model.User); ok { - r0 = rf(offset, limit, viewRestrictions) + 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) @@ -723,8 +723,8 @@ func (_m *UserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestricti } var r1 *model.AppError - if rf, ok := ret.Get(1).(func(int, int, *model.ViewUsersRestrictions) *model.AppError); ok { - r1 = rf(offset, limit, viewRestrictions) + 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) diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index 58eed620ff..b538248e67 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -919,6 +919,8 @@ func testUserStoreGetProfilesWithoutTeam(t *testing.T, ss store.Store) { u3, err := ss.User().Save(&model.User{ Email: MakeEmail(), Username: "u3" + model.NewId(), + DeleteAt: 1, + Roles: "system_admin", }) require.Nil(t, err) defer func() { require.Nil(t, ss.User().PermanentDelete(u3.Id)) }() @@ -931,23 +933,35 @@ func testUserStoreGetProfilesWithoutTeam(t *testing.T, ss store.Store) { u3.IsBot = true defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }() - t.Run("get, offset 0, limit 100", func(t *testing.T) { - users, err := ss.User().GetProfilesWithoutTeam(0, 100, nil) + t.Run("get, page 0, per_page 100", func(t *testing.T) { + users, err := ss.User().GetProfilesWithoutTeam(&model.UserGetOptions{Page: 0, PerPage: 100}) 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) { - users, err := ss.User().GetProfilesWithoutTeam(1, 1, nil) + t.Run("get, page 1, per_page 1", func(t *testing.T) { + users, err := ss.User().GetProfilesWithoutTeam(&model.UserGetOptions{Page: 1, PerPage: 1}) require.Nil(t, err) assert.Equal(t, []*model.User{sanitized(u3)}, users) }) - t.Run("get, offset 2, limit 1", func(t *testing.T) { - users, err := ss.User().GetProfilesWithoutTeam(2, 1, nil) + t.Run("get, page 2, per_page 1", func(t *testing.T) { + users, err := ss.User().GetProfilesWithoutTeam(&model.UserGetOptions{Page: 2, PerPage: 1}) require.Nil(t, err) assert.Equal(t, []*model.User{}, users) }) + + t.Run("get, page 0, per_page 100, inactive", func(t *testing.T) { + users, err := ss.User().GetProfilesWithoutTeam(&model.UserGetOptions{Page: 0, PerPage: 100, Inactive: true}) + require.Nil(t, err) + assert.Equal(t, []*model.User{sanitized(u3)}, users) + }) + + t.Run("get, page 0, per_page 100, role", func(t *testing.T) { + users, err := ss.User().GetProfilesWithoutTeam(&model.UserGetOptions{Page: 0, PerPage: 100, Role: "system_admin"}) + require.Nil(t, err) + assert.Equal(t, []*model.User{sanitized(u3)}, users) + }) } func testUserStoreGetAllProfilesInChannel(t *testing.T, ss store.Store) { diff --git a/store/timer_layer.go b/store/timer_layer.go index 577852408e..5bdbc5c00b 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -1195,6 +1195,40 @@ func (s *TimerLayerChannelStore) GetMoreChannels(teamId string, userId string, o return resultVar0, resultVar1 } +func (s *TimerLayerChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache) + + t := timemodule.Now() + elapsed := t.Sub(start) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetPinnedPostCount", success, float64(elapsed)) + } + return resultVar0, resultVar1 +} + +func (s *TimerLayerChannelStore) GetPinnedPostCountFromCache(channelId string) int64 { + start := timemodule.Now() + + resultVar0 := s.ChannelStore.GetPinnedPostCountFromCache(channelId) + + t := timemodule.Now() + elapsed := t.Sub(start) + if s.Root.Metrics != nil { + success := "false" + if true { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetPinnedPostCountFromCache", success, float64(elapsed)) + } + return resultVar0 +} + func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) { start := timemodule.Now() @@ -5360,6 +5394,40 @@ func (s *TimerLayerTeamStore) AnalyticsGetTeamCountForScheme(schemeId string) (i return resultVar0, resultVar1 } +func (s *TimerLayerTeamStore) AnalyticsPrivateTeamCount() (int64, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.TeamStore.AnalyticsPrivateTeamCount() + + t := timemodule.Now() + elapsed := t.Sub(start) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.AnalyticsPrivateTeamCount", success, float64(elapsed)) + } + return resultVar0, resultVar1 +} + +func (s *TimerLayerTeamStore) AnalyticsPublicTeamCount() (int64, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.TeamStore.AnalyticsPublicTeamCount() + + t := timemodule.Now() + elapsed := t.Sub(start) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.AnalyticsPublicTeamCount", success, float64(elapsed)) + } + return resultVar0, resultVar1 +} + func (s *TimerLayerTeamStore) AnalyticsTeamCount() (int64, *model.AppError) { start := timemodule.Now() @@ -5530,6 +5598,23 @@ func (s *TimerLayerTeamStore) GetAllPrivateTeamPageListing(offset int, limit int return resultVar0, resultVar1 } +func (s *TimerLayerTeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.TeamStore.GetAllPublicTeamPageListing(offset, limit) + + t := timemodule.Now() + elapsed := t.Sub(start) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.GetAllPublicTeamPageListing", success, float64(elapsed)) + } + return resultVar0, resultVar1 +} + func (s *TimerLayerTeamStore) GetAllTeamListing() ([]*model.Team, *model.AppError) { start := timemodule.Now() @@ -6737,10 +6822,10 @@ func (s *TimerLayerUserStore) GetProfilesNotInTeam(teamId string, groupConstrain return resultVar0, resultVar1 } -func (s *TimerLayerUserStore) GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { +func (s *TimerLayerUserStore) GetProfilesWithoutTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) { start := timemodule.Now() - resultVar0, resultVar1 := s.UserStore.GetProfilesWithoutTeam(offset, limit, viewRestrictions) + resultVar0, resultVar1 := s.UserStore.GetProfilesWithoutTeam(options) t := timemodule.Now() elapsed := t.Sub(start)