Migrate User Store methods related to enterprise to sync by default (#11332)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7e918e38bc
Коммит
6df57d7a83
@@ -1111,9 +1111,9 @@ func TestOAuthComplete(t *testing.T) {
|
|||||||
closeBody(r)
|
closeBody(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-th.App.Srv.Store.User().UpdateAuthData(
|
if _, err := th.App.Srv.Store.User().UpdateAuthData(
|
||||||
th.BasicUser.Id, model.SERVICE_GITLAB, &th.BasicUser.Email, th.BasicUser.Email, true); result.Err != nil {
|
th.BasicUser.Id, model.SERVICE_GITLAB, &th.BasicUser.Email, th.BasicUser.Email, true); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect, resp = Client.AuthorizeOAuthApp(authRequest)
|
redirect, resp = Client.AuthorizeOAuthApp(authRequest)
|
||||||
|
|||||||
@@ -1192,7 +1192,7 @@ func TestGetTotalUsersStat(t *testing.T) {
|
|||||||
th := Setup().InitBasic()
|
th := Setup().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
total := <-th.Server.Store.User().Count(model.UserCountOptions{
|
total, _ := th.Server.Store.User().Count(model.UserCountOptions{
|
||||||
IncludeDeleted: false,
|
IncludeDeleted: false,
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
})
|
})
|
||||||
@@ -1200,7 +1200,7 @@ func TestGetTotalUsersStat(t *testing.T) {
|
|||||||
rstats, resp := th.Client.GetTotalUsersStats("")
|
rstats, resp := th.Client.GetTotalUsersStats("")
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
if rstats.TotalUsersCount != total.Data.(int64) {
|
if rstats.TotalUsersCount != total {
|
||||||
t.Fatal("wrong count")
|
t.Fatal("wrong count")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1617,8 +1617,8 @@ func TestUpdateUserActive(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
authData := model.NewId()
|
authData := model.NewId()
|
||||||
result := <-th.App.Srv.Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
_, err := th.App.Srv.Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, resp = th.SystemAdminClient.UpdateUserActive(user.Id, false)
|
_, resp = th.SystemAdminClient.UpdateUserActive(user.Id, false)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -2301,8 +2301,8 @@ func TestResetPassword(t *testing.T) {
|
|||||||
_, resp = th.Client.ResetPassword(recoveryToken.Token, "newpwd")
|
_, resp = th.Client.ResetPassword(recoveryToken.Token, "newpwd")
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
authData := model.NewId()
|
authData := model.NewId()
|
||||||
if result := <-th.App.Srv.Store.User().UpdateAuthData(user.Id, "random", &authData, "", true); result.Err != nil {
|
if _, err := th.App.Srv.Store.User().UpdateAuthData(user.Id, "random", &authData, "", true); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
_, resp = th.Client.SendPasswordResetEmail(user.Email)
|
_, resp = th.Client.SendPasswordResetEmail(user.Email)
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
@@ -2974,8 +2974,8 @@ func TestSwitchAccount(t *testing.T) {
|
|||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
fakeAuthData := model.NewId()
|
fakeAuthData := model.NewId()
|
||||||
if result := <-th.App.Srv.Store.User().UpdateAuthData(th.BasicUser.Id, model.USER_AUTH_SERVICE_GITLAB, &fakeAuthData, th.BasicUser.Email, true); result.Err != nil {
|
if _, err := th.App.Srv.Store.User().UpdateAuthData(th.BasicUser.Id, model.USER_AUTH_SERVICE_GITLAB, &fakeAuthData, th.BasicUser.Email, true); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sr = &model.SwitchRequest{
|
sr = &model.SwitchRequest{
|
||||||
|
|||||||
@@ -19,12 +19,11 @@ const (
|
|||||||
func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError) {
|
func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||||
skipIntensiveQueries := false
|
skipIntensiveQueries := false
|
||||||
var systemUserCount int64
|
var systemUserCount int64
|
||||||
r := <-a.Srv.Store.User().Count(model.UserCountOptions{})
|
systemUserCount, err := a.Srv.Store.User().Count(model.UserCountOptions{})
|
||||||
if r.Err != nil {
|
if err != nil {
|
||||||
return nil, r.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
systemUserCount = r.Data.(int64)
|
|
||||||
if systemUserCount > int64(*a.Config().AnalyticsSettings.MaxUsersForStatistics) {
|
if systemUserCount > int64(*a.Config().AnalyticsSettings.MaxUsersForStatistics) {
|
||||||
mlog.Debug(fmt.Sprintf("More than %v users on the system, intensive queries skipped", *a.Config().AnalyticsSettings.MaxUsersForStatistics))
|
mlog.Debug(fmt.Sprintf("More than %v users on the system, intensive queries skipped", *a.Config().AnalyticsSettings.MaxUsersForStatistics))
|
||||||
skipIntensiveQueries = true
|
skipIntensiveQueries = true
|
||||||
@@ -62,9 +61,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
if teamId == "" {
|
if teamId == "" {
|
||||||
userInactiveChan = a.Srv.Store.User().AnalyticsGetInactiveUsersCount()
|
userInactiveChan = a.Srv.Store.User().AnalyticsGetInactiveUsersCount()
|
||||||
} else {
|
} else {
|
||||||
userChan = a.Srv.Store.User().Count(model.UserCountOptions{
|
userChan := make(chan store.StoreResult, 1)
|
||||||
TeamId: teamId,
|
go func() {
|
||||||
})
|
count, err := a.Srv.Store.User().Count(model.UserCountOptions{TeamId: teamId})
|
||||||
|
userChan <- store.StoreResult{Data: count, Err: err}
|
||||||
|
close(userChan)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
var postChan store.StoreChannel
|
var postChan store.StoreChannel
|
||||||
|
|||||||
@@ -149,17 +149,12 @@ func (a *App) trackActivity() {
|
|||||||
activeUsersMonthlyCount = r.Data.(int64)
|
activeUsersMonthlyCount = r.Data.(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ucr := <-a.Srv.Store.User().Count(model.UserCountOptions{
|
if count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeDeleted: true}); err == nil {
|
||||||
IncludeDeleted: true,
|
userCount = count
|
||||||
}); ucr.Err == nil {
|
|
||||||
userCount = ucr.Data.(int64)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if bc := <-a.Srv.Store.User().Count(model.UserCountOptions{
|
if count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeBotAccounts: true, ExcludeRegularUsers: true}); err == nil {
|
||||||
IncludeBotAccounts: true,
|
botAccountsCount = count
|
||||||
ExcludeRegularUsers: true,
|
|
||||||
}); bc.Err == nil {
|
|
||||||
botAccountsCount = bc.Data.(int64)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if iucr := <-a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); iucr.Err == nil {
|
if iucr := <-a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); iucr.Err == nil {
|
||||||
|
|||||||
@@ -498,8 +498,8 @@ func (a *App) ImportUser(data *UserImportData, dryRun bool) *model.AppError {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if hasUserAuthDataChanged {
|
if hasUserAuthDataChanged {
|
||||||
if res := <-a.Srv.Store.User().UpdateAuthData(user.Id, authService, authData, user.Email, false); res.Err != nil {
|
if _, err = a.Srv.Store.User().UpdateAuthData(user.Id, authService, authData, user.Email, false); err != nil {
|
||||||
return res.Err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -789,76 +789,60 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
// Check how many users are in the database.
|
// Check how many users are in the database.
|
||||||
var userCount int64
|
userCount, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||||
if r := <-th.App.Srv.Store.User().Count(model.UserCountOptions{
|
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
IncludeBotAccounts: false,
|
IncludeBotAccounts: false,
|
||||||
}); r.Err == nil {
|
})
|
||||||
userCount = r.Data.(int64)
|
require.Nil(t, err, "Failed to get user count.")
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get user count.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do an invalid user in dry-run mode.
|
// Do an invalid user in dry-run mode.
|
||||||
data := UserImportData{
|
data := UserImportData{
|
||||||
Username: ptrStr(model.NewId()),
|
Username: ptrStr(model.NewId()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, true); err == nil {
|
if err = th.App.ImportUser(&data, true); err == nil {
|
||||||
t.Fatalf("Should have failed to import invalid user.")
|
t.Fatalf("Should have failed to import invalid user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that no more users are in the DB.
|
// Check that no more users are in the DB.
|
||||||
if r := <-th.App.Srv.Store.User().Count(model.UserCountOptions{
|
userCount2, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
IncludeBotAccounts: false,
|
IncludeBotAccounts: false,
|
||||||
}); r.Err == nil {
|
})
|
||||||
if r.Data.(int64) != userCount {
|
require.Nil(t, err, "Failed to get user count.")
|
||||||
t.Fatalf("Unexpected number of users")
|
assert.Equal(t, userCount, userCount2, "Unexpected number of users")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get user count.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do a valid user in dry-run mode.
|
// Do a valid user in dry-run mode.
|
||||||
data = UserImportData{
|
data = UserImportData{
|
||||||
Username: ptrStr(model.NewId()),
|
Username: ptrStr(model.NewId()),
|
||||||
Email: ptrStr(model.NewId() + "@example.com"),
|
Email: ptrStr(model.NewId() + "@example.com"),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, true); err != nil {
|
if err = th.App.ImportUser(&data, true); err != nil {
|
||||||
t.Fatalf("Should have succeeded to import valid user.")
|
t.Fatalf("Should have succeeded to import valid user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that no more users are in the DB.
|
// Check that no more users are in the DB.
|
||||||
if r := <-th.App.Srv.Store.User().Count(model.UserCountOptions{
|
userCount3, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
IncludeBotAccounts: false,
|
IncludeBotAccounts: false,
|
||||||
}); r.Err == nil {
|
})
|
||||||
if r.Data.(int64) != userCount {
|
require.Nil(t, err, "Failed to get user count.")
|
||||||
t.Fatalf("Unexpected number of users")
|
assert.Equal(t, userCount, userCount3, "Unexpected number of users")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get user count.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do an invalid user in apply mode.
|
// Do an invalid user in apply mode.
|
||||||
data = UserImportData{
|
data = UserImportData{
|
||||||
Username: ptrStr(model.NewId()),
|
Username: ptrStr(model.NewId()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
if err = th.App.ImportUser(&data, false); err == nil {
|
||||||
t.Fatalf("Should have failed to import invalid user.")
|
t.Fatalf("Should have failed to import invalid user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that no more users are in the DB.
|
// Check that no more users are in the DB.
|
||||||
if r := <-th.App.Srv.Store.User().Count(model.UserCountOptions{
|
userCount4, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
IncludeBotAccounts: false,
|
IncludeBotAccounts: false,
|
||||||
}); r.Err == nil {
|
})
|
||||||
if r.Data.(int64) != userCount {
|
require.Nil(t, err, "Failed to get user count.")
|
||||||
t.Fatalf("Unexpected number of users")
|
assert.Equal(t, userCount, userCount4, "Unexpected number of users")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get user count.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do a valid user in apply mode.
|
// Do a valid user in apply mode.
|
||||||
username := model.NewId()
|
username := model.NewId()
|
||||||
@@ -872,24 +856,20 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
LastName: ptrStr(model.NewId()),
|
LastName: ptrStr(model.NewId()),
|
||||||
Position: ptrStr(model.NewId()),
|
Position: ptrStr(model.NewId()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
if err = th.App.ImportUser(&data, false); err != nil {
|
||||||
t.Fatalf("Should have succeeded to import valid user.")
|
t.Fatalf("Should have succeeded to import valid user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that one more user is in the DB.
|
// Check that one more user is in the DB.
|
||||||
if r := <-th.App.Srv.Store.User().Count(model.UserCountOptions{
|
userCount5, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
IncludeBotAccounts: false,
|
IncludeBotAccounts: false,
|
||||||
}); r.Err == nil {
|
})
|
||||||
if r.Data.(int64) != userCount+1 {
|
require.Nil(t, err, "Failed to get user count.")
|
||||||
t.Fatalf("Unexpected number of users")
|
assert.Equal(t, userCount+1, userCount5, "Unexpected number of users")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get user count.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the user and check all the fields are correct.
|
// Get the user and check all the fields are correct.
|
||||||
if user, err := th.App.GetUserByUsername(username); err != nil {
|
if user, err2 := th.App.GetUserByUsername(username); err2 != nil {
|
||||||
t.Fatalf("Failed to get user from database.")
|
t.Fatalf("Failed to get user from database.")
|
||||||
} else {
|
} else {
|
||||||
if user.Email != *data.Email || user.Nickname != *data.Nickname || user.FirstName != *data.FirstName || user.LastName != *data.LastName || user.Position != *data.Position {
|
if user.Email != *data.Email || user.Nickname != *data.Nickname || user.FirstName != *data.FirstName || user.LastName != *data.LastName || user.Position != *data.Position {
|
||||||
@@ -932,24 +912,20 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
data.Position = ptrStr(model.NewId())
|
data.Position = ptrStr(model.NewId())
|
||||||
data.Roles = ptrStr("system_admin system_user")
|
data.Roles = ptrStr("system_admin system_user")
|
||||||
data.Locale = ptrStr("zh_CN")
|
data.Locale = ptrStr("zh_CN")
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
if err = th.App.ImportUser(&data, false); err != nil {
|
||||||
t.Fatalf("Should have succeeded to update valid user %v", err)
|
t.Fatalf("Should have succeeded to update valid user %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check user count the same.
|
// Check user count the same.
|
||||||
if r := <-th.App.Srv.Store.User().Count(model.UserCountOptions{
|
userCount6, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
IncludeBotAccounts: false,
|
IncludeBotAccounts: false,
|
||||||
}); r.Err == nil {
|
})
|
||||||
if r.Data.(int64) != userCount+1 {
|
require.Nil(t, err, "Failed to get user count.")
|
||||||
t.Fatalf("Unexpected number of users")
|
assert.Equal(t, userCount+1, userCount6, "Unexpected number of users")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get user count.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the user and check all the fields are correct.
|
// Get the user and check all the fields are correct.
|
||||||
if user, err := th.App.GetUserByUsername(username); err != nil {
|
if user, err2 := th.App.GetUserByUsername(username); err2 != nil {
|
||||||
t.Fatalf("Failed to get user from database.")
|
t.Fatalf("Failed to get user from database.")
|
||||||
} else {
|
} else {
|
||||||
if user.Email != *data.Email || user.Nickname != *data.Nickname || user.FirstName != *data.FirstName || user.LastName != *data.LastName || user.Position != *data.Position {
|
if user.Email != *data.Email || user.Nickname != *data.Nickname || user.FirstName != *data.FirstName || user.LastName != *data.LastName || user.Position != *data.Position {
|
||||||
@@ -983,22 +959,22 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
|
|
||||||
// Check Password and AuthData together.
|
// Check Password and AuthData together.
|
||||||
data.Password = ptrStr("PasswordTest")
|
data.Password = ptrStr("PasswordTest")
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
if err = th.App.ImportUser(&data, false); err == nil {
|
||||||
t.Fatalf("Should have failed to import invalid user.")
|
t.Fatalf("Should have failed to import invalid user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
data.AuthData = nil
|
data.AuthData = nil
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
if err = th.App.ImportUser(&data, false); err != nil {
|
||||||
t.Fatalf("Should have succeeded to update valid user %v", err)
|
t.Fatalf("Should have succeeded to update valid user %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Password = ptrStr("")
|
data.Password = ptrStr("")
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
if err = th.App.ImportUser(&data, false); err == nil {
|
||||||
t.Fatalf("Should have failed to import invalid user.")
|
t.Fatalf("Should have failed to import invalid user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Password = ptrStr(strings.Repeat("0123456789", 10))
|
data.Password = ptrStr(strings.Repeat("0123456789", 10))
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
if err = th.App.ImportUser(&data, false); err == nil {
|
||||||
t.Fatalf("Should have failed to import invalid user.")
|
t.Fatalf("Should have failed to import invalid user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,11 +53,10 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
|
|||||||
}
|
}
|
||||||
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||||
|
|
||||||
result := <-a.Srv.Store.User().Count(model.UserCountOptions{})
|
uniqueUserCount, err := a.Srv.Store.User().Count(model.UserCountOptions{})
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, result.Err.Error(), http.StatusBadRequest)
|
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
uniqueUserCount := result.Data.(int64)
|
|
||||||
|
|
||||||
if uniqueUserCount > int64(*license.Features.Users) {
|
if uniqueUserCount > int64(*license.Features.Users) {
|
||||||
return nil, model.NewAppError("addLicense", "api.license.add_license.unique_users.app_error", map[string]interface{}{"Users": *license.Features.Users, "Count": uniqueUserCount}, "", http.StatusBadRequest)
|
return nil, model.NewAppError("addLicense", "api.license.add_license.unique_users.app_error", map[string]interface{}{"Users": *license.Features.Users, "Count": uniqueUserCount}, "", http.StatusBadRequest)
|
||||||
@@ -75,7 +74,7 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
|
|||||||
record.Id = license.Id
|
record.Id = license.Id
|
||||||
record.Bytes = string(licenseBytes)
|
record.Bytes = string(licenseBytes)
|
||||||
|
|
||||||
_, err := a.Srv.Store.License().Save(record)
|
_, err = a.Srv.Store.License().Save(record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.RemoveLicense()
|
a.RemoveLicense()
|
||||||
return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||||
|
|||||||
@@ -577,8 +577,8 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.User().UpdateAuthData(user.Id, service, &authData, ssoEmail, true); result.Err != nil {
|
if _, err = a.Srv.Store.User().UpdateAuthData(user.Id, service, &authData, ssoEmail, true); err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Srv.Go(func() {
|
a.Srv.Go(func() {
|
||||||
|
|||||||
@@ -69,10 +69,8 @@ func (s *Server) DoSecurityUpdateCheck() {
|
|||||||
s.Store.System().Update(systemSecurityLastTime)
|
s.Store.System().Update(systemSecurityLastTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ucr := <-s.Store.User().Count(model.UserCountOptions{
|
if count, err := s.Store.User().Count(model.UserCountOptions{IncludeDeleted: true}); err == nil {
|
||||||
IncludeDeleted: true,
|
v.Set(PROP_SECURITY_USER_COUNT, strconv.FormatInt(count, 10))
|
||||||
}); ucr.Err == nil {
|
|
||||||
v.Set(PROP_SECURITY_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ucr, err := s.Store.Status().GetTotalActiveUsersCount(); err == nil {
|
if ucr, err := s.Store.Status().GetTotalActiveUsersCount(); err == nil {
|
||||||
|
|||||||
32
app/user.go
32
app/user.go
@@ -173,14 +173,12 @@ func (a *App) IsUserSignUpAllowed() *model.AppError {
|
|||||||
|
|
||||||
func (a *App) IsFirstUserAccount() bool {
|
func (a *App) IsFirstUserAccount() bool {
|
||||||
if a.SessionCacheLength() == 0 {
|
if a.SessionCacheLength() == 0 {
|
||||||
cr := <-a.Srv.Store.User().Count(model.UserCountOptions{
|
count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeDeleted: true})
|
||||||
IncludeDeleted: true,
|
if err != nil {
|
||||||
})
|
mlog.Error(fmt.Sprint(err))
|
||||||
if cr.Err != nil {
|
|
||||||
mlog.Error(fmt.Sprint(cr.Err))
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if cr.Data.(int64) <= 0 {
|
if count <= 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,13 +244,11 @@ func (a *App) createUserOrGuest(user *model.User, guest bool) (*model.User, *mod
|
|||||||
|
|
||||||
// Below is a special case where the first user in the entire
|
// Below is a special case where the first user in the entire
|
||||||
// system is granted the system_admin role
|
// system is granted the system_admin role
|
||||||
result := <-a.Srv.Store.User().Count(model.UserCountOptions{
|
count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeDeleted: true})
|
||||||
IncludeDeleted: true,
|
if err != nil {
|
||||||
})
|
return nil, err
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
}
|
||||||
if result.Data.(int64) <= 0 {
|
if count <= 0 {
|
||||||
user.Roles = model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID
|
user.Roles = model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1088,8 +1084,8 @@ func (a *App) UpdateUserAuth(userId string, userAuth *model.UserAuth) (*model.Us
|
|||||||
} else {
|
} else {
|
||||||
userAuth.Password = ""
|
userAuth.Password = ""
|
||||||
|
|
||||||
if result := <-a.Srv.Store.User().UpdateAuthData(userId, userAuth.AuthService, userAuth.AuthData, "", false); result.Err != nil {
|
if _, err := a.Srv.Store.User().UpdateAuthData(userId, userAuth.AuthService, userAuth.AuthData, "", false); err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1639,15 +1635,15 @@ func (a *App) GetVerifyEmailToken(token string) (*model.Token, *model.AppError)
|
|||||||
|
|
||||||
// GetTotalUsersStats is used for the DM list total
|
// GetTotalUsersStats is used for the DM list total
|
||||||
func (a *App) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) (*model.UsersStats, *model.AppError) {
|
func (a *App) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) (*model.UsersStats, *model.AppError) {
|
||||||
result := <-a.Srv.Store.User().Count(model.UserCountOptions{
|
count, err := a.Srv.Store.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
ViewRestrictions: viewRestrictions,
|
ViewRestrictions: viewRestrictions,
|
||||||
})
|
})
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
stats := &model.UsersStats{
|
stats := &model.UsersStats{
|
||||||
TotalUsersCount: result.Data.(int64),
|
TotalUsersCount: count,
|
||||||
}
|
}
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,8 +268,7 @@ func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) store.StoreChannel {
|
func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
email = strings.ToLower(email)
|
email = strings.ToLower(email)
|
||||||
|
|
||||||
updateAt := model.GetMillis()
|
updateAt := model.GetMillis()
|
||||||
@@ -297,14 +296,11 @@ func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *s
|
|||||||
|
|
||||||
if _, err := us.GetMaster().Exec(query, map[string]interface{}{"LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId, "AuthService": service, "AuthData": authData, "Email": email}); err != nil {
|
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"}) {
|
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)
|
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)
|
||||||
} else {
|
|
||||||
result.Err = model.NewAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.app_error", nil, "id="+userId+", "+err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
} else {
|
return "", model.NewAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.app_error", nil, "id="+userId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
result.Data = userId
|
|
||||||
}
|
}
|
||||||
})
|
return userId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) UpdateMfaSecret(userId, secret string) store.StoreChannel {
|
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
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetAllUsingAuthService(authService string) store.StoreChannel {
|
func (us SqlUserStore) GetAllUsingAuthService(authService string) ([]*model.User, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
query := us.usersQuery.
|
query := us.usersQuery.
|
||||||
Where("u.AuthService = ?", authService).
|
Where("u.AuthService = ?", authService).
|
||||||
OrderBy("u.Username ASC")
|
OrderBy("u.Username ASC")
|
||||||
|
|
||||||
queryString, args, err := query.ToSql()
|
queryString, args, err := query.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlUserStore.GetAllUsingAuthService", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlUserStore.GetAllUsingAuthService", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var data []*model.User
|
var users []*model.User
|
||||||
if _, err := us.GetReplica().Select(&data, queryString, args...); err != nil {
|
if _, err := us.GetReplica().Select(&users, 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 nil, model.NewAppError("SqlUserStore.GetAllUsingAuthService", "store.sql_user.get_by_auth.other.app_error", nil, "authService="+authService+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = data
|
return users, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetByUsername(username string) store.StoreChannel {
|
func (us SqlUserStore) GetByUsername(username string) store.StoreChannel {
|
||||||
@@ -1144,8 +1136,7 @@ func (us SqlUserStore) PermanentDelete(userId string) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) Count(options model.UserCountOptions) store.StoreChannel {
|
func (us SqlUserStore) Count(options model.UserCountOptions) (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
query := sq.Select("COUNT(DISTINCT u.Id)").From("Users AS u")
|
query := sq.Select("COUNT(DISTINCT u.Id)").From("Users AS u")
|
||||||
|
|
||||||
if !options.IncludeDeleted {
|
if !options.IncludeDeleted {
|
||||||
@@ -1160,8 +1151,7 @@ func (us SqlUserStore) Count(options model.UserCountOptions) store.StoreChannel
|
|||||||
query = query.LeftJoin("Bots ON u.Id = Bots.UserId").Where("Bots.UserId IS NULL")
|
query = query.LeftJoin("Bots ON u.Id = Bots.UserId").Where("Bots.UserId IS NULL")
|
||||||
if options.ExcludeRegularUsers {
|
if options.ExcludeRegularUsers {
|
||||||
// Currenty this doesn't make sense because it will always return 0
|
// 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 int64(0), model.NewAppError("SqlUserStore.Count", "store.sql_user.count.app_error", nil, "", http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1176,16 +1166,14 @@ func (us SqlUserStore) Count(options model.UserCountOptions) store.StoreChannel
|
|||||||
|
|
||||||
queryString, args, err := query.ToSql()
|
queryString, args, err := query.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlUserStore.Get", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return int64(0), model.NewAppError("SqlUserStore.Get", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if count, err := us.GetReplica().SelectInt(queryString, args...); err != nil {
|
count, err := us.GetReplica().SelectInt(queryString, args...)
|
||||||
result.Err = model.NewAppError("SqlUserStore.Count", "store.sql_user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
if err != nil {
|
||||||
} else {
|
return int64(0), model.NewAppError("SqlUserStore.Count", "store.sql_user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
result.Data = count
|
|
||||||
}
|
}
|
||||||
})
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) store.StoreChannel {
|
func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) store.StoreChannel {
|
||||||
@@ -1570,8 +1558,7 @@ func (us SqlUserStore) InferSystemInstallDate() store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit int) store.StoreChannel {
|
func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
var users []*model.User
|
var users []*model.User
|
||||||
usersQuery, args, _ := us.usersQuery.
|
usersQuery, args, _ := us.usersQuery.
|
||||||
Where(sq.GtOrEq{"u.CreateAt": startTime}).
|
Where(sq.GtOrEq{"u.CreateAt": startTime}).
|
||||||
@@ -1582,8 +1569,7 @@ func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit
|
|||||||
_, err1 := us.GetSearchReplica().Select(&users, usersQuery, args...)
|
_, err1 := us.GetSearchReplica().Select(&users, usersQuery, args...)
|
||||||
|
|
||||||
if err1 != nil {
|
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 nil, model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_users.app_error", nil, err1.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
userIds := []string{}
|
userIds := []string{}
|
||||||
@@ -1613,8 +1599,7 @@ func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit
|
|||||||
_, err2 := us.GetSearchReplica().Select(&channelMembers, channelMembersQuery, args...)
|
_, err2 := us.GetSearchReplica().Select(&channelMembers, channelMembersQuery, args...)
|
||||||
|
|
||||||
if err2 != nil {
|
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 nil, model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_channel_members.app_error", nil, err2.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var teamMembers []*model.TeamMember
|
var teamMembers []*model.TeamMember
|
||||||
@@ -1626,8 +1611,7 @@ func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit
|
|||||||
_, err3 := us.GetSearchReplica().Select(&teamMembers, teamMembersQuery, args...)
|
_, err3 := us.GetSearchReplica().Select(&teamMembers, teamMembersQuery, args...)
|
||||||
|
|
||||||
if err3 != nil {
|
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 nil, model.NewAppError("SqlUserStore.GetUsersBatchForIndexing", "store.sql_user.get_users_batch_for_indexing.get_team_members.app_error", nil, err3.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
userMap := map[string]*model.UserForIndexing{}
|
userMap := map[string]*model.UserForIndexing{}
|
||||||
@@ -1664,8 +1648,7 @@ func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit
|
|||||||
return usersForIndexing[i].CreateAt < usersForIndexing[j].CreateAt
|
return usersForIndexing[i].CreateAt < usersForIndexing[j].CreateAt
|
||||||
})
|
})
|
||||||
|
|
||||||
result.Data = usersForIndexing
|
return usersForIndexing, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetTeamGroupUsers(teamID string) store.StoreChannel {
|
func (us SqlUserStore) GetTeamGroupUsers(teamID string) store.StoreChannel {
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ type UserStore interface {
|
|||||||
ResetLastPictureUpdate(userId string) StoreChannel
|
ResetLastPictureUpdate(userId string) StoreChannel
|
||||||
UpdateUpdateAt(userId string) StoreChannel
|
UpdateUpdateAt(userId string) StoreChannel
|
||||||
UpdatePassword(userId, newPassword 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
|
UpdateMfaSecret(userId, secret string) StoreChannel
|
||||||
UpdateMfaActive(userId string, active bool) StoreChannel
|
UpdateMfaActive(userId string, active bool) StoreChannel
|
||||||
Get(id string) (*model.User, *model.AppError)
|
Get(id string) (*model.User, *model.AppError)
|
||||||
@@ -273,7 +273,7 @@ type UserStore interface {
|
|||||||
InvalidatProfileCacheForUser(userId string)
|
InvalidatProfileCacheForUser(userId string)
|
||||||
GetByEmail(email string) (*model.User, *model.AppError)
|
GetByEmail(email string) (*model.User, *model.AppError)
|
||||||
GetByAuth(authData *string, authService 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
|
GetByUsername(username string) StoreChannel
|
||||||
GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) StoreChannel
|
GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) StoreChannel
|
||||||
VerifyEmail(userId, email string) (string, *model.AppError)
|
VerifyEmail(userId, email string) (string, *model.AppError)
|
||||||
@@ -300,8 +300,8 @@ type UserStore interface {
|
|||||||
ClearAllCustomRoleAssignments() StoreChannel
|
ClearAllCustomRoleAssignments() StoreChannel
|
||||||
InferSystemInstallDate() StoreChannel
|
InferSystemInstallDate() StoreChannel
|
||||||
GetAllAfter(limit int, afterId string) StoreChannel
|
GetAllAfter(limit int, afterId string) StoreChannel
|
||||||
GetUsersBatchForIndexing(startTime, endTime int64, limit int) StoreChannel
|
GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError)
|
||||||
Count(options model.UserCountOptions) StoreChannel
|
Count(options model.UserCountOptions) (int64, *model.AppError)
|
||||||
GetTeamGroupUsers(teamID string) StoreChannel
|
GetTeamGroupUsers(teamID string) StoreChannel
|
||||||
GetChannelGroupUsers(channelID string) StoreChannel
|
GetChannelGroupUsers(channelID string) StoreChannel
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,19 +83,26 @@ func (_m *UserStore) ClearCaches() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count provides a mock function with given fields: options
|
// 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)
|
ret := _m.Called(options)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(model.UserCountOptions) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(model.UserCountOptions) int64); ok {
|
||||||
r0 = rf(options)
|
r0 = rf(options)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(int64)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
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
|
// 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
|
// 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)
|
ret := _m.Called(authService)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.User
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) []*model.User); ok {
|
||||||
r0 = rf(authService)
|
r0 = rf(authService)
|
||||||
} 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) *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
|
// 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
|
// 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)
|
ret := _m.Called(startTime, endTime, limit)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.UserForIndexing
|
||||||
if rf, ok := ret.Get(0).(func(int64, int64, int) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(int64, int64, int) []*model.UserForIndexing); ok {
|
||||||
r0 = rf(startTime, endTime, limit)
|
r0 = rf(startTime, endTime, limit)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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:
|
// 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
|
// 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)
|
ret := _m.Called(userId, service, authData, email, resetMfa)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 string
|
||||||
if rf, ok := ret.Get(0).(func(string, string, *string, string, bool) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string, *string, string, bool) string); ok {
|
||||||
r0 = rf(userId, service, authData, email, resetMfa)
|
r0 = rf(userId, service, authData, email, resetMfa)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(string)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
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
|
// UpdateFailedPasswordAttempts provides a mock function with given fields: userId, attempts
|
||||||
|
|||||||
@@ -330,21 +330,21 @@ func testGetAllUsingAuthService(t *testing.T, ss store.Store) {
|
|||||||
defer func() { require.Nil(t, ss.User().PermanentDelete(u3.Id)) }()
|
defer func() { require.Nil(t, ss.User().PermanentDelete(u3.Id)) }()
|
||||||
|
|
||||||
t.Run("get by unknown auth service", func(t *testing.T) {
|
t.Run("get by unknown auth service", func(t *testing.T) {
|
||||||
result := <-ss.User().GetAllUsingAuthService("unknown")
|
users, err := ss.User().GetAllUsingAuthService("unknown")
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, []*model.User{}, result.Data.([]*model.User))
|
assert.Equal(t, []*model.User{}, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get by auth service", func(t *testing.T) {
|
t.Run("get by auth service", func(t *testing.T) {
|
||||||
result := <-ss.User().GetAllUsingAuthService("service")
|
users, err := ss.User().GetAllUsingAuthService("service")
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, []*model.User{u1, u2}, result.Data.([]*model.User))
|
assert.Equal(t, []*model.User{u1, u2}, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get by other auth service", func(t *testing.T) {
|
t.Run("get by other auth service", func(t *testing.T) {
|
||||||
result := <-ss.User().GetAllUsingAuthService("service2")
|
users, err := ss.User().GetAllUsingAuthService("service2")
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, []*model.User{u3}, result.Data.([]*model.User))
|
assert.Equal(t, []*model.User{u3}, users)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1771,9 +1771,8 @@ func testUserStoreUpdateAuthData(t *testing.T, ss store.Store) {
|
|||||||
service := "someservice"
|
service := "someservice"
|
||||||
authData := model.NewId()
|
authData := model.NewId()
|
||||||
|
|
||||||
if err := (<-ss.User().UpdateAuthData(u1.Id, service, &authData, "", true)).Err; err != nil {
|
_, err := ss.User().UpdateAuthData(u1.Id, service, &authData, "", true)
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
if user, err := ss.User().GetByEmail(u1.Email); err != nil {
|
if user, err := ss.User().GetByEmail(u1.Email); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -3131,80 +3130,80 @@ func testCount(t *testing.T, ss store.Store) {
|
|||||||
u3.IsBot = true
|
u3.IsBot = true
|
||||||
defer func() { require.Nil(t, ss.Bot().PermanentDelete(u3.Id)) }()
|
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,
|
IncludeBotAccounts: false,
|
||||||
IncludeDeleted: false,
|
IncludeDeleted: false,
|
||||||
TeamId: "",
|
TeamId: "",
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(1), result.Data.(int64))
|
require.Equal(t, int64(1), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
IncludeDeleted: false,
|
IncludeDeleted: false,
|
||||||
TeamId: "",
|
TeamId: "",
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(2), result.Data.(int64))
|
require.Equal(t, int64(2), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: false,
|
IncludeBotAccounts: false,
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
TeamId: "",
|
TeamId: "",
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(2), result.Data.(int64))
|
require.Equal(t, int64(2), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
TeamId: "",
|
TeamId: "",
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(3), result.Data.(int64))
|
require.Equal(t, int64(3), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
ExcludeRegularUsers: true,
|
ExcludeRegularUsers: true,
|
||||||
TeamId: "",
|
TeamId: "",
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(1), result.Data.(int64))
|
require.Equal(t, int64(1), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
TeamId: teamId,
|
TeamId: teamId,
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(1), result.Data.(int64))
|
require.Equal(t, int64(1), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
TeamId: model.NewId(),
|
TeamId: model.NewId(),
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(0), result.Data.(int64))
|
require.Equal(t, int64(0), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
TeamId: teamId,
|
TeamId: teamId,
|
||||||
ViewRestrictions: &model.ViewUsersRestrictions{Teams: []string{teamId}},
|
ViewRestrictions: &model.ViewUsersRestrictions{Teams: []string{teamId}},
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(1), result.Data.(int64))
|
require.Equal(t, int64(1), count)
|
||||||
|
|
||||||
result = <-ss.User().Count(model.UserCountOptions{
|
count, err = ss.User().Count(model.UserCountOptions{
|
||||||
IncludeBotAccounts: true,
|
IncludeBotAccounts: true,
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
TeamId: teamId,
|
TeamId: teamId,
|
||||||
ViewRestrictions: &model.ViewUsersRestrictions{Teams: []string{model.NewId()}},
|
ViewRestrictions: &model.ViewUsersRestrictions{Teams: []string{model.NewId()}},
|
||||||
})
|
})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(0), result.Data.(int64))
|
require.Equal(t, int64(0), count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
|
func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
|
||||||
@@ -3661,9 +3660,8 @@ func testUserStoreGetUsersBatchForIndexing(t *testing.T, ss store.Store) {
|
|||||||
endTime := u3.CreateAt
|
endTime := u3.CreateAt
|
||||||
|
|
||||||
// First and last user should be outside the range
|
// First and last user should be outside the range
|
||||||
res1 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
|
res1List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
|
||||||
assert.Nil(t, res1.Err)
|
assert.Nil(t, err)
|
||||||
res1List := res1.Data.([]*model.UserForIndexing)
|
|
||||||
|
|
||||||
assert.Len(t, res1List, 1)
|
assert.Len(t, res1List, 1)
|
||||||
assert.Equal(t, res1List[0].Username, u2.Username)
|
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
|
// Update startTime to include first user
|
||||||
startTime = u1.CreateAt
|
startTime = u1.CreateAt
|
||||||
res2 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
|
res2List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
|
||||||
assert.Nil(t, res1.Err)
|
assert.Nil(t, err)
|
||||||
res2List := res2.Data.([]*model.UserForIndexing)
|
|
||||||
|
|
||||||
assert.Len(t, res2List, 2)
|
assert.Len(t, res2List, 2)
|
||||||
assert.Equal(t, res2List[0].Username, u1.Username)
|
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
|
// Update endTime to include last user
|
||||||
endTime = model.GetMillis()
|
endTime = model.GetMillis()
|
||||||
res3 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
|
res3List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 100)
|
||||||
assert.Nil(t, res3.Err)
|
assert.Nil(t, err)
|
||||||
res3List := res3.Data.([]*model.UserForIndexing)
|
|
||||||
|
|
||||||
assert.Len(t, res3List, 3)
|
assert.Len(t, res3List, 3)
|
||||||
assert.Equal(t, res3List[0].Username, u1.Username)
|
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})
|
assert.ElementsMatch(t, res3List[2].ChannelsIds, []string{cPub2.Id})
|
||||||
|
|
||||||
// Testing the limit
|
// Testing the limit
|
||||||
res4 := <-ss.User().GetUsersBatchForIndexing(startTime, endTime, 2)
|
res4List, err := ss.User().GetUsersBatchForIndexing(startTime, endTime, 2)
|
||||||
assert.Nil(t, res4.Err)
|
assert.Nil(t, err)
|
||||||
res4List := res4.Data.([]*model.UserForIndexing)
|
|
||||||
|
|
||||||
assert.Len(t, res4List, 2)
|
assert.Len(t, res4List, 2)
|
||||||
assert.Equal(t, res4List[0].Username, u1.Username)
|
assert.Equal(t, res4List[0].Username, u1.Username)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user