Migrate User Store methods related to enterprise to sync by default (#11332)

This commit is contained in:
Jesús Espino
2019-06-26 10:41:45 +02:00
committed by GitHub
parent 7e918e38bc
commit 6df57d7a83
14 changed files with 316 additions and 340 deletions

View File

@@ -268,13 +268,12 @@ func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int)
})
}
func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
email = strings.ToLower(email)
func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError) {
email = strings.ToLower(email)
updateAt := model.GetMillis()
updateAt := model.GetMillis()
query := `
query := `
UPDATE
Users
SET
@@ -285,26 +284,23 @@ func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *s
AuthService = :AuthService,
AuthData = :AuthData`
if len(email) != 0 {
query += ", Email = :Email"
}
if len(email) != 0 {
query += ", Email = :Email"
}
if resetMfa {
query += ", MfaActive = false, MfaSecret = ''"
}
if resetMfa {
query += ", MfaActive = false, MfaSecret = ''"
}
query += " WHERE Id = :UserId"
query += " WHERE Id = :UserId"
if _, err := us.GetMaster().Exec(query, map[string]interface{}{"LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId, "AuthService": service, "AuthData": authData, "Email": email}); err != nil {
if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique", "AuthData", "users_authdata_key"}) {
result.Err = model.NewAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.email_exists.app_error", map[string]interface{}{"Service": service, "Email": email}, "user_id="+userId+", "+err.Error(), http.StatusBadRequest)
} else {
result.Err = model.NewAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.app_error", nil, "id="+userId+", "+err.Error(), http.StatusInternalServerError)
}
} else {
result.Data = userId
if _, err := us.GetMaster().Exec(query, map[string]interface{}{"LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId, "AuthService": service, "AuthData": authData, "Email": email}); err != nil {
if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique", "AuthData", "users_authdata_key"}) {
return "", model.NewAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.email_exists.app_error", map[string]interface{}{"Service": service, "Email": email}, "user_id="+userId+", "+err.Error(), http.StatusBadRequest)
}
})
return "", model.NewAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.app_error", nil, "id="+userId+", "+err.Error(), http.StatusInternalServerError)
}
return userId, nil
}
func (us SqlUserStore) UpdateMfaSecret(userId, secret string) store.StoreChannel {
@@ -1045,26 +1041,22 @@ func (us SqlUserStore) GetByAuth(authData *string, authService string) (*model.U
return &user, nil
}
func (us SqlUserStore) GetAllUsingAuthService(authService string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
query := us.usersQuery.
Where("u.AuthService = ?", authService).
OrderBy("u.Username ASC")
func (us SqlUserStore) GetAllUsingAuthService(authService string) ([]*model.User, *model.AppError) {
query := us.usersQuery.
Where("u.AuthService = ?", authService).
OrderBy("u.Username ASC")
queryString, args, err := query.ToSql()
if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetAllUsingAuthService", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
queryString, args, err := query.ToSql()
if err != nil {
return nil, model.NewAppError("SqlUserStore.GetAllUsingAuthService", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
var data []*model.User
if _, err := us.GetReplica().Select(&data, queryString, args...); err != nil {
result.Err = model.NewAppError("SqlUserStore.GetAllUsingAuthService", "store.sql_user.get_by_auth.other.app_error", nil, "authService="+authService+", "+err.Error(), http.StatusInternalServerError)
return
}
var users []*model.User
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
return nil, model.NewAppError("SqlUserStore.GetAllUsingAuthService", "store.sql_user.get_by_auth.other.app_error", nil, "authService="+authService+", "+err.Error(), http.StatusInternalServerError)
}
result.Data = data
})
return users, nil
}
func (us SqlUserStore) GetByUsername(username string) store.StoreChannel {
@@ -1144,48 +1136,44 @@ func (us SqlUserStore) PermanentDelete(userId string) *model.AppError {
return nil
}
func (us SqlUserStore) Count(options model.UserCountOptions) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
query := sq.Select("COUNT(DISTINCT u.Id)").From("Users AS u")
func (us SqlUserStore) Count(options model.UserCountOptions) (int64, *model.AppError) {
query := sq.Select("COUNT(DISTINCT u.Id)").From("Users AS u")
if !options.IncludeDeleted {
query = query.Where("u.DeleteAt = 0")
}
if !options.IncludeDeleted {
query = query.Where("u.DeleteAt = 0")
}
if options.IncludeBotAccounts {
if options.ExcludeRegularUsers {
query = query.Join("Bots ON u.Id = Bots.UserId")
}
} else {
query = query.LeftJoin("Bots ON u.Id = Bots.UserId").Where("Bots.UserId IS NULL")
if options.ExcludeRegularUsers {
// Currenty this doesn't make sense because it will always return 0
result.Err = model.NewAppError("SqlUserStore.Count", "store.sql_user.count.app_error", nil, "", http.StatusInternalServerError)
return
}
if options.IncludeBotAccounts {
if options.ExcludeRegularUsers {
query = query.Join("Bots ON u.Id = Bots.UserId")
}
} else {
query = query.LeftJoin("Bots ON u.Id = Bots.UserId").Where("Bots.UserId IS NULL")
if options.ExcludeRegularUsers {
// Currenty this doesn't make sense because it will always return 0
return int64(0), model.NewAppError("SqlUserStore.Count", "store.sql_user.count.app_error", nil, "", http.StatusInternalServerError)
}
}
if options.TeamId != "" {
query = query.LeftJoin("TeamMembers AS tm ON u.Id = tm.UserId").Where("tm.TeamId = ? AND tm.DeleteAt = 0", options.TeamId)
}
query = applyViewRestrictionsFilter(query, options.ViewRestrictions, false)
if options.TeamId != "" {
query = query.LeftJoin("TeamMembers AS tm ON u.Id = tm.UserId").Where("tm.TeamId = ? AND tm.DeleteAt = 0", options.TeamId)
}
query = applyViewRestrictionsFilter(query, options.ViewRestrictions, false)
if us.DriverName() == model.DATABASE_DRIVER_POSTGRES {
query = query.PlaceholderFormat(sq.Dollar)
}
if us.DriverName() == model.DATABASE_DRIVER_POSTGRES {
query = query.PlaceholderFormat(sq.Dollar)
}
queryString, args, err := query.ToSql()
if err != nil {
result.Err = model.NewAppError("SqlUserStore.Get", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
queryString, args, err := query.ToSql()
if err != nil {
return int64(0), model.NewAppError("SqlUserStore.Get", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if count, err := us.GetReplica().SelectInt(queryString, args...); err != nil {
result.Err = model.NewAppError("SqlUserStore.Count", "store.sql_user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
result.Data = count
}
})
count, err := us.GetReplica().SelectInt(queryString, args...)
if err != nil {
return int64(0), model.NewAppError("SqlUserStore.Count", "store.sql_user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
}
func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) store.StoreChannel {
@@ -1570,30 +1558,28 @@ func (us SqlUserStore) InferSystemInstallDate() store.StoreChannel {
})
}
func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var users []*model.User
usersQuery, args, _ := us.usersQuery.
Where(sq.GtOrEq{"u.CreateAt": startTime}).
Where(sq.Lt{"u.CreateAt": endTime}).
OrderBy("u.CreateAt").
Limit(uint64(limit)).
ToSql()
_, err1 := us.GetSearchReplica().Select(&users, usersQuery, args...)
func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError) {
var users []*model.User
usersQuery, args, _ := us.usersQuery.
Where(sq.GtOrEq{"u.CreateAt": startTime}).
Where(sq.Lt{"u.CreateAt": endTime}).
OrderBy("u.CreateAt").
Limit(uint64(limit)).
ToSql()
_, err1 := us.GetSearchReplica().Select(&users, usersQuery, args...)
if err1 != nil {
result.Err = model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_users.app_error", nil, err1.Error(), http.StatusInternalServerError)
return
}
if err1 != nil {
return nil, model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_users.app_error", nil, err1.Error(), http.StatusInternalServerError)
}
userIds := []string{}
for _, user := range users {
userIds = append(userIds, user.Id)
}
userIds := []string{}
for _, user := range users {
userIds = append(userIds, user.Id)
}
var channelMembers []*model.ChannelMember
channelMembersQuery, args, _ := us.getQueryBuilder().
Select(`
var channelMembers []*model.ChannelMember
channelMembersQuery, args, _ := us.getQueryBuilder().
Select(`
cm.ChannelId,
cm.UserId,
cm.Roles,
@@ -1606,66 +1592,63 @@ func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit
cm.SchemeAdmin,
(cm.SchemeGuest IS NOT NULL AND cm.SchemeGuest) as SchemeGuest
`).
From("ChannelMembers cm").
Join("Channels c ON cm.ChannelId = c.Id").
Where(sq.Eq{"c.Type": "O", "cm.UserId": userIds}).
ToSql()
_, err2 := us.GetSearchReplica().Select(&channelMembers, channelMembersQuery, args...)
From("ChannelMembers cm").
Join("Channels c ON cm.ChannelId = c.Id").
Where(sq.Eq{"c.Type": "O", "cm.UserId": userIds}).
ToSql()
_, err2 := us.GetSearchReplica().Select(&channelMembers, channelMembersQuery, args...)
if err2 != nil {
result.Err = model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_channel_members.app_error", nil, err2.Error(), http.StatusInternalServerError)
return
if err2 != nil {
return nil, model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_channel_members.app_error", nil, err2.Error(), http.StatusInternalServerError)
}
var teamMembers []*model.TeamMember
teamMembersQuery, args, _ := us.getQueryBuilder().
Select("TeamId, UserId, Roles, DeleteAt, (SchemeGuest IS NOT NULL AND SchemeGuest) as SchemeGuest, SchemeUser, SchemeAdmin").
From("TeamMembers").
Where(sq.Eq{"UserId": userIds, "DeleteAt": 0}).
ToSql()
_, err3 := us.GetSearchReplica().Select(&teamMembers, teamMembersQuery, args...)
if err3 != nil {
return nil, model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_team_members.app_error", nil, err3.Error(), http.StatusInternalServerError)
}
userMap := map[string]*model.UserForIndexing{}
for _, user := range users {
userMap[user.Id] = &model.UserForIndexing{
Id: user.Id,
Username: user.Username,
Nickname: user.Nickname,
FirstName: user.FirstName,
LastName: user.LastName,
CreateAt: user.CreateAt,
DeleteAt: user.DeleteAt,
TeamsIds: []string{},
ChannelsIds: []string{},
}
}
var teamMembers []*model.TeamMember
teamMembersQuery, args, _ := us.getQueryBuilder().
Select("TeamId, UserId, Roles, DeleteAt, (SchemeGuest IS NOT NULL AND SchemeGuest) as SchemeGuest, SchemeUser, SchemeAdmin").
From("TeamMembers").
Where(sq.Eq{"UserId": userIds, "DeleteAt": 0}).
ToSql()
_, err3 := us.GetSearchReplica().Select(&teamMembers, teamMembersQuery, args...)
if err3 != nil {
result.Err = model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_team_members.app_error", nil, err3.Error(), http.StatusInternalServerError)
return
for _, c := range channelMembers {
if userMap[c.UserId] != nil {
userMap[c.UserId].ChannelsIds = append(userMap[c.UserId].ChannelsIds, c.ChannelId)
}
userMap := map[string]*model.UserForIndexing{}
for _, user := range users {
userMap[user.Id] = &model.UserForIndexing{
Id: user.Id,
Username: user.Username,
Nickname: user.Nickname,
FirstName: user.FirstName,
LastName: user.LastName,
CreateAt: user.CreateAt,
DeleteAt: user.DeleteAt,
TeamsIds: []string{},
ChannelsIds: []string{},
}
}
for _, t := range teamMembers {
if userMap[t.UserId] != nil {
userMap[t.UserId].TeamsIds = append(userMap[t.UserId].TeamsIds, t.TeamId)
}
}
for _, c := range channelMembers {
if userMap[c.UserId] != nil {
userMap[c.UserId].ChannelsIds = append(userMap[c.UserId].ChannelsIds, c.ChannelId)
}
}
for _, t := range teamMembers {
if userMap[t.UserId] != nil {
userMap[t.UserId].TeamsIds = append(userMap[t.UserId].TeamsIds, t.TeamId)
}
}
usersForIndexing := []*model.UserForIndexing{}
for _, user := range userMap {
usersForIndexing = append(usersForIndexing, user)
}
sort.Slice(usersForIndexing, func(i, j int) bool {
return usersForIndexing[i].CreateAt < usersForIndexing[j].CreateAt
})
result.Data = usersForIndexing
usersForIndexing := []*model.UserForIndexing{}
for _, user := range userMap {
usersForIndexing = append(usersForIndexing, user)
}
sort.Slice(usersForIndexing, func(i, j int) bool {
return usersForIndexing[i].CreateAt < usersForIndexing[j].CreateAt
})
return usersForIndexing, nil
}
func (us SqlUserStore) GetTeamGroupUsers(teamID string) store.StoreChannel {

View File

@@ -252,7 +252,7 @@ type UserStore interface {
ResetLastPictureUpdate(userId string) StoreChannel
UpdateUpdateAt(userId string) StoreChannel
UpdatePassword(userId, newPassword string) StoreChannel
UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) StoreChannel
UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError)
UpdateMfaSecret(userId, secret string) StoreChannel
UpdateMfaActive(userId string, active bool) StoreChannel
Get(id string) (*model.User, *model.AppError)
@@ -273,7 +273,7 @@ type UserStore interface {
InvalidatProfileCacheForUser(userId string)
GetByEmail(email string) (*model.User, *model.AppError)
GetByAuth(authData *string, authService string) (*model.User, *model.AppError)
GetAllUsingAuthService(authService string) StoreChannel
GetAllUsingAuthService(authService string) ([]*model.User, *model.AppError)
GetByUsername(username string) StoreChannel
GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) StoreChannel
VerifyEmail(userId, email string) (string, *model.AppError)
@@ -300,8 +300,8 @@ type UserStore interface {
ClearAllCustomRoleAssignments() StoreChannel
InferSystemInstallDate() StoreChannel
GetAllAfter(limit int, afterId string) StoreChannel
GetUsersBatchForIndexing(startTime, endTime int64, limit int) StoreChannel
Count(options model.UserCountOptions) StoreChannel
GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError)
Count(options model.UserCountOptions) (int64, *model.AppError)
GetTeamGroupUsers(teamID string) StoreChannel
GetChannelGroupUsers(channelID string) StoreChannel
}

View File

@@ -83,19 +83,26 @@ func (_m *UserStore) ClearCaches() {
}
// Count provides a mock function with given fields: options
func (_m *UserStore) Count(options model.UserCountOptions) store.StoreChannel {
func (_m *UserStore) Count(options model.UserCountOptions) (int64, *model.AppError) {
ret := _m.Called(options)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(model.UserCountOptions) store.StoreChannel); ok {
var r0 int64
if rf, ok := ret.Get(0).(func(model.UserCountOptions) int64); ok {
r0 = rf(options)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(int64)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(model.UserCountOptions) *model.AppError); ok {
r1 = rf(options)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0
return r0, r1
}
// Get provides a mock function with given fields: id
@@ -188,19 +195,28 @@ func (_m *UserStore) GetAllProfilesInChannel(channelId string, allowFromCache bo
}
// GetAllUsingAuthService provides a mock function with given fields: authService
func (_m *UserStore) GetAllUsingAuthService(authService string) store.StoreChannel {
func (_m *UserStore) GetAllUsingAuthService(authService string) ([]*model.User, *model.AppError) {
ret := _m.Called(authService)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
var r0 []*model.User
if rf, ok := ret.Get(0).(func(string) []*model.User); ok {
r0 = rf(authService)
} 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(string) *model.AppError); ok {
r1 = rf(authService)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetAnyUnreadPostCountForChannel provides a mock function with given fields: userId, channelId
@@ -615,19 +631,28 @@ func (_m *UserStore) GetUnreadCountForChannel(userId string, channelId string) s
}
// GetUsersBatchForIndexing provides a mock function with given fields: startTime, endTime, limit
func (_m *UserStore) GetUsersBatchForIndexing(startTime int64, endTime int64, limit int) store.StoreChannel {
func (_m *UserStore) GetUsersBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError) {
ret := _m.Called(startTime, endTime, limit)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(int64, int64, int) store.StoreChannel); ok {
var r0 []*model.UserForIndexing
if rf, ok := ret.Get(0).(func(int64, int64, int) []*model.UserForIndexing); ok {
r0 = rf(startTime, endTime, limit)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).([]*model.UserForIndexing)
}
}
return r0
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(int64, int64, int) *model.AppError); ok {
r1 = rf(startTime, endTime, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// InferSystemInstallDate provides a mock function with given fields:
@@ -815,19 +840,26 @@ func (_m *UserStore) Update(user *model.User, allowRoleUpdate bool) (*model.User
}
// UpdateAuthData provides a mock function with given fields: userId, service, authData, email, resetMfa
func (_m *UserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) store.StoreChannel {
func (_m *UserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError) {
ret := _m.Called(userId, service, authData, email, resetMfa)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string, string, *string, string, bool) store.StoreChannel); ok {
var r0 string
if rf, ok := ret.Get(0).(func(string, string, *string, string, bool) string); ok {
r0 = rf(userId, service, authData, email, resetMfa)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(string)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string, *string, string, bool) *model.AppError); ok {
r1 = rf(userId, service, authData, email, resetMfa)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0
return r0, r1
}
// UpdateFailedPasswordAttempts provides a mock function with given fields: userId, attempts

View File

@@ -330,21 +330,21 @@ func testGetAllUsingAuthService(t *testing.T, ss store.Store) {
defer func() { require.Nil(t, ss.User().PermanentDelete(u3.Id)) }()
t.Run("get by unknown auth service", func(t *testing.T) {
result := <-ss.User().GetAllUsingAuthService("unknown")
require.Nil(t, result.Err)
assert.Equal(t, []*model.User{}, result.Data.([]*model.User))
users, err := ss.User().GetAllUsingAuthService("unknown")
require.Nil(t, err)
assert.Equal(t, []*model.User{}, users)
})
t.Run("get by auth service", func(t *testing.T) {
result := <-ss.User().GetAllUsingAuthService("service")
require.Nil(t, result.Err)
assert.Equal(t, []*model.User{u1, u2}, result.Data.([]*model.User))
users, err := ss.User().GetAllUsingAuthService("service")
require.Nil(t, err)
assert.Equal(t, []*model.User{u1, u2}, users)
})
t.Run("get by other auth service", func(t *testing.T) {
result := <-ss.User().GetAllUsingAuthService("service2")
require.Nil(t, result.Err)
assert.Equal(t, []*model.User{u3}, result.Data.([]*model.User))
users, err := ss.User().GetAllUsingAuthService("service2")
require.Nil(t, err)
assert.Equal(t, []*model.User{u3}, users)
})
}
@@ -1771,9 +1771,8 @@ func testUserStoreUpdateAuthData(t *testing.T, ss store.Store) {
service := "someservice"
authData := model.NewId()
if err := (<-ss.User().UpdateAuthData(u1.Id, service, &authData, "", true)).Err; err != nil {
t.Fatal(err)
}
_, err := ss.User().UpdateAuthData(u1.Id, service, &authData, "", true)
require.Nil(t, err)
if user, err := ss.User().GetByEmail(u1.Email); err != nil {
t.Fatal(err)
@@ -3131,80 +3130,80 @@ func testCount(t *testing.T, ss store.Store) {
u3.IsBot = true
defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }()
result := <-ss.User().Count(model.UserCountOptions{
count, err := ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: false,
IncludeDeleted: false,
TeamId: "",
})
require.Nil(t, result.Err)
require.Equal(t, int64(1), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(1), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: true,
IncludeDeleted: false,
TeamId: "",
})
require.Nil(t, result.Err)
require.Equal(t, int64(2), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(2), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: false,
IncludeDeleted: true,
TeamId: "",
})
require.Nil(t, result.Err)
require.Equal(t, int64(2), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(2), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: true,
IncludeDeleted: true,
TeamId: "",
})
require.Nil(t, result.Err)
require.Equal(t, int64(3), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(3), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: true,
IncludeDeleted: true,
ExcludeRegularUsers: true,
TeamId: "",
})
require.Nil(t, result.Err)
require.Equal(t, int64(1), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(1), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: true,
IncludeDeleted: true,
TeamId: teamId,
})
require.Nil(t, result.Err)
require.Equal(t, int64(1), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(1), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: true,
IncludeDeleted: true,
TeamId: model.NewId(),
})
require.Nil(t, result.Err)
require.Equal(t, int64(0), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(0), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: true,
IncludeDeleted: true,
TeamId: teamId,
ViewRestrictions: &model.ViewUsersRestrictions{Teams: []string{teamId}},
})
require.Nil(t, result.Err)
require.Equal(t, int64(1), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(1), count)
result = <-ss.User().Count(model.UserCountOptions{
count, err = ss.User().Count(model.UserCountOptions{
IncludeBotAccounts: true,
IncludeDeleted: true,
TeamId: teamId,
ViewRestrictions: &model.ViewUsersRestrictions{Teams: []string{model.NewId()}},
})
require.Nil(t, result.Err)
require.Equal(t, int64(0), result.Data.(int64))
require.Nil(t, err)
require.Equal(t, int64(0), count)
}
func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
@@ -3661,9 +3660,8 @@ func testUserStoreGetUsersBatchForIndexing(t *testing.T, ss store.Store) {
endTime := u3.CreateAt
// First and last user should be outside the range
res1 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
assert.Nil(t, res1.Err)
res1List := res1.Data.([]*model.UserForIndexing)
res1List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
assert.Nil(t, err)
assert.Len(t, res1List, 1)
assert.Equal(t, res1List[0].Username, u2.Username)
@@ -3672,9 +3670,8 @@ func testUserStoreGetUsersBatchForIndexing(t *testing.T, ss store.Store) {
// Update startTime to include first user
startTime = u1.CreateAt
res2 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
assert.Nil(t, res1.Err)
res2List := res2.Data.([]*model.UserForIndexing)
res2List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
assert.Nil(t, err)
assert.Len(t, res2List, 2)
assert.Equal(t, res2List[0].Username, u1.Username)
@@ -3684,9 +3681,8 @@ func testUserStoreGetUsersBatchForIndexing(t *testing.T, ss store.Store) {
// Update endTime to include last user
endTime = model.GetMillis()
res3 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
assert.Nil(t, res3.Err)
res3List := res3.Data.([]*model.UserForIndexing)
res3List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
assert.Nil(t, err)
assert.Len(t, res3List, 3)
assert.Equal(t, res3List[0].Username, u1.Username)
@@ -3696,9 +3692,8 @@ func testUserStoreGetUsersBatchForIndexing(t *testing.T, ss store.Store) {
assert.ElementsMatch(t, res3List[2].ChannelsIds, []string{cPub2.Id})
// Testing the limit
res4 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 2)
assert.Nil(t, res4.Err)
res4List := res4.Data.([]*model.UserForIndexing)
res4List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 2)
assert.Nil(t, err)
assert.Len(t, res4List, 2)
assert.Equal(t, res4List[0].Username, u1.Username)