Migrating User Store VerifyEmail, GetByAuth and GetByEmail functions to sync by default (#10941)

Этот коммит содержится в:
Jesús Espino
2019-06-12 19:30:50 +02:00
коммит произвёл GitHub
родитель f49a0881bf
Коммит 76bab4f0c2
16 изменённых файлов: 181 добавлений и 164 удалений

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

@@ -293,7 +293,10 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
} }
ruser.Password = "Pa$$word11" ruser.Password = "Pa$$word11"
store.Must(me.App.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)) _, err := me.App.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
if err != nil {
return nil
}
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
return ruser return ruser
} }

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

@@ -17,7 +17,6 @@ import (
"github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/services/mailservice" "github.com/mattermost/mattermost-server/services/mailservice"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/utils/testutils" "github.com/mattermost/mattermost-server/utils/testutils"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@@ -1391,7 +1390,8 @@ func TestUpdateUserAuth(t *testing.T) {
user := th.CreateUser() user := th.CreateUser()
th.LinkUserToTeam(user, team) th.LinkUserToTeam(user, team)
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id, user.Email)) _, err := th.App.Srv.Store.User().VerifyEmail(user.Id, user.Email)
require.Nil(t, err)
userAuth := &model.UserAuth{} userAuth := &model.UserAuth{}
userAuth.AuthData = user.AuthData userAuth.AuthData = user.AuthData
@@ -1431,7 +1431,8 @@ func TestUpdateUserAuth(t *testing.T) {
// Regular user can not use endpoint // Regular user can not use endpoint
user2 := th.CreateUser() user2 := th.CreateUser()
th.LinkUserToTeam(user2, team) th.LinkUserToTeam(user2, team)
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id, user2.Email)) _, err = th.App.Srv.Store.User().VerifyEmail(user2.Id, user2.Email)
require.Nil(t, err)
th.SystemAdminClient.Login(user2.Email, "passwd1") th.SystemAdminClient.Login(user2.Email, "passwd1")

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

@@ -11,9 +11,9 @@ import (
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
) )
func TestWebSocket(t *testing.T) { func TestWebSocket(t *testing.T) {
@@ -304,12 +304,14 @@ func TestWebSocketStatuses(t *testing.T) {
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
ruser := Client.Must(Client.CreateUser(&user)).(*model.User) ruser := Client.Must(Client.CreateUser(&user)).(*model.User)
th.LinkUserToTeam(ruser, rteam) th.LinkUserToTeam(ruser, rteam)
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)) _, err = th.App.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
require.Nil(t, err)
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
ruser2 := Client.Must(Client.CreateUser(&user2)).(*model.User) ruser2 := Client.Must(Client.CreateUser(&user2)).(*model.User)
th.LinkUserToTeam(ruser2, rteam) th.LinkUserToTeam(ruser2, rteam)
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser2.Id, ruser2.Email)) _, err = th.App.Srv.Store.User().VerifyEmail(ruser2.Id, ruser2.Email)
require.Nil(t, err)
Client.Login(user.Email, user.Password) Client.Login(user.Email, user.Password)

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

@@ -48,7 +48,10 @@ func (a *App) CreateBasicUser(client *model.Client4) *model.AppError {
if resp.Error != nil { if resp.Error != nil {
return resp.Error return resp.Error
} }
store.Must(a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)) _, err := a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
if err != nil {
return err
}
store.Must(a.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}, *a.Config().TeamSettings.MaxUsersPerTeam)) store.Must(a.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}, *a.Config().TeamSettings.MaxUsersPerTeam))
} }
return nil return nil
@@ -83,7 +86,10 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
} }
// We need to cheat to verify the user's email // We need to cheat to verify the user's email
store.Must(cfg.app.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)) _, err := cfg.app.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
if err != nil {
return nil, false
}
return ruser, true return ruser, true
} }

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

@@ -594,22 +594,21 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.blank_email.app_error", nil, "", http.StatusBadRequest) return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.blank_email.app_error", nil, "", http.StatusBadRequest)
} }
result := <-a.Srv.Store.User().GetByEmail(email) user, err := a.Srv.Store.User().GetByEmail(email)
if result.Err != nil { if err != nil {
return nil, result.Err
}
user := result.Data.(*model.User)
if err := a.RevokeAllSessions(user.Id); err != nil {
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.RevokeAllSessions(user.Id); err != nil {
return nil, err
}
if result := <-a.Srv.Store.User().UpdateAuthData(user.Id, service, &authData, ssoEmail, true); result.Err != nil {
return nil, result.Err return nil, result.Err
} }
a.Srv.Go(func() { a.Srv.Go(func() {
if err := a.SendSignInChangeEmail(user.Email, strings.Title(service)+" SSO", user.Locale, a.GetSiteURL()); err != nil { if err = a.SendSignInChangeEmail(user.Email, strings.Title(service)+" SSO", user.Locale, a.GetSiteURL()); err != nil {
mlog.Error(err.Error()) mlog.Error(err.Error())
} }
}) })

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

@@ -168,8 +168,7 @@ func (a *App) SlackAddUsers(teamId string, slackusers []SlackUser, importerLog *
password := model.NewId() password := model.NewId()
// Check for email conflict and use existing user if found // Check for email conflict and use existing user if found
if result := <-a.Srv.Store.User().GetByEmail(email); result.Err == nil { if existingUser, err := a.Srv.Store.User().GetByEmail(email); err == nil {
existingUser := result.Data.(*model.User)
addedUsers[sUser.Id] = existingUser addedUsers[sUser.Id] = existingUser
if err := a.JoinUserToTeam(team, addedUsers[sUser.Id], ""); err != nil { if err := a.JoinUserToTeam(team, addedUsers[sUser.Id], ""); err != nil {
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.merge_existing_failed", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username})) importerLog.WriteString(utils.T("api.slackimport.slack_add_users.merge_existing_failed", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username}))
@@ -795,8 +794,8 @@ func (a *App) OldImportUser(team *model.Team, user *model.User) *model.User {
} }
ruser := result.Data.(*model.User) ruser := result.Data.(*model.User)
if cresult := <-a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email); cresult.Err != nil { if _, err := a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email); err != nil {
mlog.Error(fmt.Sprintf("Failed to set email verified err=%v", cresult.Err)) mlog.Error(fmt.Sprintf("Failed to set email verified err=%v", err))
} }
if err := a.JoinUserToTeam(team, user, ""); err != nil { if err := a.JoinUserToTeam(team, user, ""); err != nil {

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

@@ -337,8 +337,18 @@ func (a *App) CreateOAuthUser(service string, userData io.Reader, teamId string)
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]interface{}{"Service": service}, "", http.StatusInternalServerError) return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]interface{}{"Service": service}, "", http.StatusInternalServerError)
} }
suchan := a.Srv.Store.User().GetByAuth(user.AuthData, service) suchan := make(chan store.StoreResult, 1)
euchan := a.Srv.Store.User().GetByEmail(user.Email) euchan := make(chan store.StoreResult, 1)
go func() {
userByAuth, err := a.Srv.Store.User().GetByAuth(user.AuthData, service)
suchan <- store.StoreResult{Data: userByAuth, Err: err}
close(suchan)
}()
go func() {
userByEmail, err := a.Srv.Store.User().GetByEmail(user.Email)
euchan <- store.StoreResult{Data: userByEmail, Err: err}
close(euchan)
}()
found := true found := true
count := 0 count := 0
@@ -427,24 +437,20 @@ func (a *App) GetUserByUsername(username string) (*model.User, *model.AppError)
} }
func (a *App) GetUserByEmail(email string) (*model.User, *model.AppError) { func (a *App) GetUserByEmail(email string) (*model.User, *model.AppError) {
result := <-a.Srv.Store.User().GetByEmail(email) user, err := a.Srv.Store.User().GetByEmail(email)
if result.Err != nil { if err != nil {
if result.Err.Id == "store.sql_user.missing_account.const" { if err.Id == "store.sql_user.missing_account.const" {
result.Err.StatusCode = http.StatusNotFound err.StatusCode = http.StatusNotFound
return nil, result.Err return nil, err
} }
result.Err.StatusCode = http.StatusBadRequest err.StatusCode = http.StatusBadRequest
return nil, result.Err return nil, err
} }
return result.Data.(*model.User), nil return user, nil
} }
func (a *App) GetUserByAuth(authData *string, authService string) (*model.User, *model.AppError) { func (a *App) GetUserByAuth(authData *string, authService string) (*model.User, *model.AppError) {
result := <-a.Srv.Store.User().GetByAuth(authData, authService) return a.Srv.Store.User().GetByAuth(authData, authService)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.User), nil
} }
func (a *App) GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError) { func (a *App) GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
@@ -1636,8 +1642,7 @@ func (a *App) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions)
} }
func (a *App) VerifyUserEmail(userId, email string) *model.AppError { func (a *App) VerifyUserEmail(userId, email string) *model.AppError {
err := (<-a.Srv.Store.User().VerifyEmail(userId, email)).Err _, err := a.Srv.Store.User().VerifyEmail(userId, email)
if err != nil { if err != nil {
return err return err
} }

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

@@ -5,8 +5,6 @@ package commands
import ( import (
"testing" "testing"
"github.com/mattermost/mattermost-server/model"
) )
func TestAssignRole(t *testing.T) { func TestAssignRole(t *testing.T) {
@@ -15,10 +13,9 @@ func TestAssignRole(t *testing.T) {
th.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email) th.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil {
t.Fatal(result.Err) t.Fatal(err)
} else { } else {
user := result.Data.(*model.User)
if user.Roles != "system_user system_admin" { if user.Roles != "system_user system_admin" {
t.Fatal("Got wrong roles:", user.Roles) t.Fatal("Got wrong roles:", user.Roles)
} }
@@ -26,10 +23,9 @@ func TestAssignRole(t *testing.T) {
th.CheckCommand(t, "roles", "member", th.BasicUser.Email) th.CheckCommand(t, "roles", "member", th.BasicUser.Email)
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil {
t.Fatal(result.Err) t.Fatal(err)
} else { } else {
user := result.Data.(*model.User)
if user.Roles != "system_user" { if user.Roles != "system_user" {
t.Fatal("Got wrong roles:", user.Roles, user.Id) t.Fatal("Got wrong roles:", user.Roles, user.Id)
} }

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

@@ -886,8 +886,8 @@ func verifyUserCmdF(command *cobra.Command, args []string) error {
CommandPrintErrorln("Unable to find user '" + args[i] + "'") CommandPrintErrorln("Unable to find user '" + args[i] + "'")
continue continue
} }
if cresult := <-a.Srv.Store.User().VerifyEmail(user.Id, user.Email); cresult.Err != nil { if _, err := a.Srv.Store.User().VerifyEmail(user.Id, user.Email); err != nil {
CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error()) CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + err.Error())
} }
} }

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

@@ -48,10 +48,9 @@ func TestCreateUserWithoutTeam(t *testing.T) {
th.CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) th.CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil { if user, err := th.App.Srv.Store.User().GetByEmail(email); err != nil {
t.Fatal(result.Err) t.Fatal(err)
} else { } else {
user := result.Data.(*model.User)
require.Equal(t, email, user.Email) require.Equal(t, email, user.Email)
} }
} }
@@ -85,13 +84,12 @@ func TestChangeUserEmail(t *testing.T) {
newEmail := model.NewId() + "@mattermost-test.com" newEmail := model.NewId() + "@mattermost-test.com"
th.CheckCommand(t, "user", "email", th.BasicUser.Username, newEmail) th.CheckCommand(t, "user", "email", th.BasicUser.Username, newEmail)
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err == nil { if _, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err == nil {
t.Fatal("should've updated to the new email") t.Fatal("should've updated to the new email")
} }
if result := <-th.App.Srv.Store.User().GetByEmail(newEmail); result.Err != nil { if user, err := th.App.Srv.Store.User().GetByEmail(newEmail); err != nil {
t.Fatal(result.Err) t.Fatal(err)
} else { } else {
user := result.Data.(*model.User)
if user.Email != newEmail { if user.Email != newEmail {
t.Fatal("should've updated to the new email") t.Fatal("should've updated to the new email")
} }

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

@@ -18,10 +18,7 @@ func getUsersFromUserArgs(a *app.App, userArgs []string) []*model.User {
} }
func getUserFromUserArg(a *app.App, userArg string) *model.User { func getUserFromUserArg(a *app.App, userArg string) *model.User {
var user *model.User user, _ := a.Srv.Store.User().GetByEmail(userArg)
if result := <-a.Srv.Store.User().GetByEmail(userArg); result.Err == nil {
user = result.Data.(*model.User)
}
if user == nil { if user == nil {
if result := <-a.Srv.Store.User().GetByUsername(userArg); result.Err == nil { if result := <-a.Srv.Store.User().GetByUsername(userArg); result.Err == nil {

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

@@ -99,7 +99,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
return return
} }
<-c.App.Srv.Store.User().VerifyEmail(user.Id, user.Email) c.App.Srv.Store.User().VerifyEmail(user.Id, user.Email)
<-c.App.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: teamID, UserId: user.Id}, *c.App.Config().TeamSettings.MaxUsersPerTeam) <-c.App.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: teamID, UserId: user.Id}, *c.App.Config().TeamSettings.MaxUsersPerTeam)
userID = user.Id userID = user.Id

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

@@ -949,55 +949,45 @@ func (us SqlUserStore) GetSystemAdminProfiles() store.StoreChannel {
}) })
} }
func (us SqlUserStore) GetByEmail(email string) store.StoreChannel { func (us SqlUserStore) GetByEmail(email string) (*model.User, *model.AppError) {
return store.Do(func(result *store.StoreResult) { email = strings.ToLower(email)
email = strings.ToLower(email)
query := us.usersQuery.Where("Email = ?", email) query := us.usersQuery.Where("Email = ?", email)
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetByEmail", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetByEmail", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return }
}
user := model.User{} user := model.User{}
if err := us.GetReplica().SelectOne(&user, queryString, args...); err != nil { if err := us.GetReplica().SelectOne(&user, queryString, args...); err != nil {
result.Err = model.NewAppError("SqlUserStore.GetByEmail", store.MISSING_ACCOUNT_ERROR, nil, "email="+email+", "+err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetByEmail", store.MISSING_ACCOUNT_ERROR, nil, "email="+email+", "+err.Error(), http.StatusInternalServerError)
} }
result.Data = &user return &user, nil
})
} }
func (us SqlUserStore) GetByAuth(authData *string, authService string) store.StoreChannel { func (us SqlUserStore) GetByAuth(authData *string, authService string) (*model.User, *model.AppError) {
return store.Do(func(result *store.StoreResult) { if authData == nil || *authData == "" {
if authData == nil || *authData == "" { return nil, model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData='', authService="+authService, http.StatusBadRequest)
result.Err = model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData='', authService="+authService, http.StatusBadRequest) }
return
}
query := us.usersQuery. query := us.usersQuery.
Where("u.AuthData = ?", authData). Where("u.AuthData = ?", authData).
Where("u.AuthService = ?", authService) Where("u.AuthService = ?", authService)
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return }
}
user := model.User{} user := model.User{}
if err := us.GetReplica().SelectOne(&user, queryString, args...); err == sql.ErrNoRows { if err := us.GetReplica().SelectOne(&user, queryString, args...); err == sql.ErrNoRows {
result.Err = model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError)
return } else if err != nil {
} else if err != nil { return nil, model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.get_by_auth.other.app_error", nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError)
result.Err = model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.get_by_auth.other.app_error", nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError) }
return return &user, nil
}
result.Data = &user
})
} }
func (us SqlUserStore) GetAllUsingAuthService(authService string) store.StoreChannel { func (us SqlUserStore) GetAllUsingAuthService(authService string) store.StoreChannel {
@@ -1083,15 +1073,13 @@ func (us SqlUserStore) GetForLogin(loginId string, allowSignInWithUsername, allo
}) })
} }
func (us SqlUserStore) VerifyEmail(userId, email string) store.StoreChannel { func (us SqlUserStore) VerifyEmail(userId, email string) (string, *model.AppError) {
return store.Do(func(result *store.StoreResult) { curTime := model.GetMillis()
curTime := model.GetMillis() if _, err := us.GetMaster().Exec("UPDATE Users SET Email = :email, EmailVerified = true, UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"email": email, "Time": curTime, "UserId": userId}); err != nil {
if _, err := us.GetMaster().Exec("UPDATE Users SET Email = :email, EmailVerified = true, UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"email": email, "Time": curTime, "UserId": userId}); err != nil { return "", model.NewAppError("SqlUserStore.VerifyEmail", "store.sql_user.verify_email.app_error", nil, "userId="+userId+", "+err.Error(), http.StatusInternalServerError)
result.Err = model.NewAppError("SqlUserStore.VerifyEmail", "store.sql_user.verify_email.app_error", nil, "userId="+userId+", "+err.Error(), http.StatusInternalServerError) }
}
result.Data = userId return userId, nil
})
} }
func (us SqlUserStore) PermanentDelete(userId string) *model.AppError { func (us SqlUserStore) PermanentDelete(userId string) *model.AppError {

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

@@ -268,12 +268,12 @@ type UserStore interface {
GetProfiles(options *model.UserGetOptions) StoreChannel GetProfiles(options *model.UserGetOptions) StoreChannel
GetProfileByIds(userId []string, allowFromCache bool, viewRestrictions *model.ViewUsersRestrictions) StoreChannel GetProfileByIds(userId []string, allowFromCache bool, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
InvalidatProfileCacheForUser(userId string) InvalidatProfileCacheForUser(userId string)
GetByEmail(email string) StoreChannel GetByEmail(email string) (*model.User, *model.AppError)
GetByAuth(authData *string, authService string) StoreChannel GetByAuth(authData *string, authService string) (*model.User, *model.AppError)
GetAllUsingAuthService(authService string) StoreChannel GetAllUsingAuthService(authService string) StoreChannel
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) StoreChannel VerifyEmail(userId, email string) (string, *model.AppError)
GetEtagForAllProfiles() StoreChannel GetEtagForAllProfiles() StoreChannel
GetEtagForProfiles(teamId string) StoreChannel GetEtagForProfiles(teamId string) StoreChannel
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel

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

@@ -220,35 +220,53 @@ func (_m *UserStore) GetAnyUnreadPostCountForChannel(userId string, channelId st
} }
// GetByAuth provides a mock function with given fields: authData, authService // GetByAuth provides a mock function with given fields: authData, authService
func (_m *UserStore) GetByAuth(authData *string, authService string) store.StoreChannel { func (_m *UserStore) GetByAuth(authData *string, authService string) (*model.User, *model.AppError) {
ret := _m.Called(authData, authService) ret := _m.Called(authData, authService)
var r0 store.StoreChannel var r0 *model.User
if rf, ok := ret.Get(0).(func(*string, string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(*string, string) *model.User); ok {
r0 = rf(authData, authService) r0 = rf(authData, 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, string) *model.AppError); ok {
r1 = rf(authData, authService)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetByEmail provides a mock function with given fields: email // GetByEmail provides a mock function with given fields: email
func (_m *UserStore) GetByEmail(email string) store.StoreChannel { func (_m *UserStore) GetByEmail(email string) (*model.User, *model.AppError) {
ret := _m.Called(email) ret := _m.Called(email)
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(email) r0 = rf(email)
} 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(email)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetByUsername provides a mock function with given fields: username // GetByUsername provides a mock function with given fields: username
@@ -884,17 +902,24 @@ func (_m *UserStore) UpdateUpdateAt(userId string) store.StoreChannel {
} }
// VerifyEmail provides a mock function with given fields: userId, email // VerifyEmail provides a mock function with given fields: userId, email
func (_m *UserStore) VerifyEmail(userId string, email string) store.StoreChannel { func (_m *UserStore) VerifyEmail(userId string, email string) (string, *model.AppError) {
ret := _m.Called(userId, email) ret := _m.Called(userId, email)
var r0 store.StoreChannel var r0 string
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, string) string); ok {
r0 = rf(userId, email) r0 = rf(userId, email)
} 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) *model.AppError); ok {
r1 = rf(userId, email)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
} }
} }
return r0 return r0, r1
} }

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

@@ -1345,33 +1345,33 @@ func testUserStoreGetByEmail(t *testing.T, ss store.Store) {
defer func() { store.Must(ss.Bot().PermanentDelete(u3.Id)) }() defer func() { store.Must(ss.Bot().PermanentDelete(u3.Id)) }()
t.Run("get u1 by email", func(t *testing.T) { t.Run("get u1 by email", func(t *testing.T) {
result := <-ss.User().GetByEmail(u1.Email) u, err := ss.User().GetByEmail(u1.Email)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, u1, result.Data.(*model.User)) assert.Equal(t, u1, u)
}) })
t.Run("get u2 by email", func(t *testing.T) { t.Run("get u2 by email", func(t *testing.T) {
result := <-ss.User().GetByEmail(u2.Email) u, err := ss.User().GetByEmail(u2.Email)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, u2, result.Data.(*model.User)) assert.Equal(t, u2, u)
}) })
t.Run("get u3 by email", func(t *testing.T) { t.Run("get u3 by email", func(t *testing.T) {
result := <-ss.User().GetByEmail(u3.Email) u, err := ss.User().GetByEmail(u3.Email)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, u3, result.Data.(*model.User)) assert.Equal(t, u3, u)
}) })
t.Run("get by empty email", func(t *testing.T) { t.Run("get by empty email", func(t *testing.T) {
result := <-ss.User().GetByEmail("") _, err := ss.User().GetByEmail("")
require.NotNil(t, result.Err) require.NotNil(t, err)
require.Equal(t, result.Err.Id, store.MISSING_ACCOUNT_ERROR) require.Equal(t, err.Id, store.MISSING_ACCOUNT_ERROR)
}) })
t.Run("get by unknown", func(t *testing.T) { t.Run("get by unknown", func(t *testing.T) {
result := <-ss.User().GetByEmail("unknown") _, err := ss.User().GetByEmail("unknown")
require.NotNil(t, result.Err) require.NotNil(t, err)
require.Equal(t, result.Err.Id, store.MISSING_ACCOUNT_ERROR) require.Equal(t, err.Id, store.MISSING_ACCOUNT_ERROR)
}) })
} }
@@ -1413,35 +1413,35 @@ func testUserStoreGetByAuthData(t *testing.T, ss store.Store) {
defer func() { store.Must(ss.Bot().PermanentDelete(u3.Id)) }() defer func() { store.Must(ss.Bot().PermanentDelete(u3.Id)) }()
t.Run("get by u1 auth", func(t *testing.T) { t.Run("get by u1 auth", func(t *testing.T) {
result := <-ss.User().GetByAuth(u1.AuthData, u1.AuthService) u, err := ss.User().GetByAuth(u1.AuthData, u1.AuthService)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, u1, result.Data.(*model.User)) assert.Equal(t, u1, u)
}) })
t.Run("get by u3 auth", func(t *testing.T) { t.Run("get by u3 auth", func(t *testing.T) {
result := <-ss.User().GetByAuth(u3.AuthData, u3.AuthService) u, err := ss.User().GetByAuth(u3.AuthData, u3.AuthService)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, u3, result.Data.(*model.User)) assert.Equal(t, u3, u)
}) })
t.Run("get by u1 auth, unknown service", func(t *testing.T) { t.Run("get by u1 auth, unknown service", func(t *testing.T) {
result := <-ss.User().GetByAuth(u1.AuthData, "unknown") _, err := ss.User().GetByAuth(u1.AuthData, "unknown")
require.NotNil(t, result.Err) require.NotNil(t, err)
require.Equal(t, result.Err.Id, store.MISSING_AUTH_ACCOUNT_ERROR) require.Equal(t, err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
}) })
t.Run("get by unknown auth, u1 service", func(t *testing.T) { t.Run("get by unknown auth, u1 service", func(t *testing.T) {
unknownAuth := "" unknownAuth := ""
result := <-ss.User().GetByAuth(&unknownAuth, u1.AuthService) _, err := ss.User().GetByAuth(&unknownAuth, u1.AuthService)
require.NotNil(t, result.Err) require.NotNil(t, err)
require.Equal(t, result.Err.Id, store.MISSING_AUTH_ACCOUNT_ERROR) require.Equal(t, err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
}) })
t.Run("get by unknown auth, unknown service", func(t *testing.T) { t.Run("get by unknown auth, unknown service", func(t *testing.T) {
unknownAuth := "" unknownAuth := ""
result := <-ss.User().GetByAuth(&unknownAuth, "unknown") _, err := ss.User().GetByAuth(&unknownAuth, "unknown")
require.NotNil(t, result.Err) require.NotNil(t, err)
require.Equal(t, result.Err.Id, store.MISSING_AUTH_ACCOUNT_ERROR) require.Equal(t, err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
}) })
} }
@@ -1605,10 +1605,9 @@ func testUserStoreUpdatePassword(t *testing.T, ss store.Store) {
t.Fatal(err) t.Fatal(err)
} }
if r1 := <-ss.User().GetByEmail(u1.Email); r1.Err != nil { if user, err := ss.User().GetByEmail(u1.Email); err != nil {
t.Fatal(r1.Err) t.Fatal(err)
} else { } else {
user := r1.Data.(*model.User)
if user.Password != hashedPassword { if user.Password != hashedPassword {
t.Fatal("Password was not updated correctly") t.Fatal("Password was not updated correctly")
} }
@@ -1643,10 +1642,9 @@ func testUserStoreUpdateAuthData(t *testing.T, ss store.Store) {
t.Fatal(err) t.Fatal(err)
} }
if r1 := <-ss.User().GetByEmail(u1.Email); r1.Err != nil { if user, err := ss.User().GetByEmail(u1.Email); err != nil {
t.Fatal(r1.Err) t.Fatal(err)
} else { } else {
user := r1.Data.(*model.User)
if user.AuthService != service { if user.AuthService != service {
t.Fatal("AuthService was not updated correctly") t.Fatal("AuthService was not updated correctly")
} }