mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrating User Store VerifyEmail, GetByAuth and GetByEmail functions to sync by default (#10941)
This commit is contained in:
@@ -293,7 +293,10 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
||||
}
|
||||
|
||||
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()
|
||||
return ruser
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/services/mailservice"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -1391,7 +1390,8 @@ func TestUpdateUserAuth(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
|
||||
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.AuthData = user.AuthData
|
||||
@@ -1431,7 +1431,8 @@ func TestUpdateUserAuth(t *testing.T) {
|
||||
// Regular user can not use endpoint
|
||||
user2 := th.CreateUser()
|
||||
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")
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
)
|
||||
|
||||
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"}
|
||||
ruser := Client.Must(Client.CreateUser(&user)).(*model.User)
|
||||
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"}
|
||||
ruser2 := Client.Must(Client.CreateUser(&user2)).(*model.User)
|
||||
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)
|
||||
|
||||
|
||||
@@ -48,7 +48,10 @@ func (a *App) CreateBasicUser(client *model.Client4) *model.AppError {
|
||||
if resp.Error != nil {
|
||||
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))
|
||||
}
|
||||
return nil
|
||||
@@ -83,7 +86,10 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
17
app/oauth.go
17
app/oauth.go
@@ -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)
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.User().GetByEmail(email)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
if err := a.RevokeAllSessions(user.Id); err != nil {
|
||||
user, err := a.Srv.Store.User().GetByEmail(email)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -168,8 +168,7 @@ func (a *App) SlackAddUsers(teamId string, slackusers []SlackUser, importerLog *
|
||||
password := model.NewId()
|
||||
|
||||
// Check for email conflict and use existing user if found
|
||||
if result := <-a.Srv.Store.User().GetByEmail(email); result.Err == nil {
|
||||
existingUser := result.Data.(*model.User)
|
||||
if existingUser, err := a.Srv.Store.User().GetByEmail(email); err == nil {
|
||||
addedUsers[sUser.Id] = existingUser
|
||||
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}))
|
||||
@@ -795,8 +794,8 @@ func (a *App) OldImportUser(team *model.Team, user *model.User) *model.User {
|
||||
}
|
||||
ruser := result.Data.(*model.User)
|
||||
|
||||
if cresult := <-a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email); cresult.Err != nil {
|
||||
mlog.Error(fmt.Sprintf("Failed to set email verified err=%v", cresult.Err))
|
||||
if _, err := a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email); err != nil {
|
||||
mlog.Error(fmt.Sprintf("Failed to set email verified err=%v", err))
|
||||
}
|
||||
|
||||
if err := a.JoinUserToTeam(team, user, ""); err != nil {
|
||||
|
||||
39
app/user.go
39
app/user.go
@@ -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)
|
||||
}
|
||||
|
||||
suchan := a.Srv.Store.User().GetByAuth(user.AuthData, service)
|
||||
euchan := a.Srv.Store.User().GetByEmail(user.Email)
|
||||
suchan := make(chan store.StoreResult, 1)
|
||||
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
|
||||
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) {
|
||||
result := <-a.Srv.Store.User().GetByEmail(email)
|
||||
if result.Err != nil {
|
||||
if result.Err.Id == "store.sql_user.missing_account.const" {
|
||||
result.Err.StatusCode = http.StatusNotFound
|
||||
return nil, result.Err
|
||||
user, err := a.Srv.Store.User().GetByEmail(email)
|
||||
if err != nil {
|
||||
if err.Id == "store.sql_user.missing_account.const" {
|
||||
err.StatusCode = http.StatusNotFound
|
||||
return nil, err
|
||||
}
|
||||
result.Err.StatusCode = http.StatusBadRequest
|
||||
return nil, result.Err
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
}
|
||||
return result.Data.(*model.User), nil
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (a *App) GetUserByAuth(authData *string, authService string) (*model.User, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().GetByAuth(authData, authService)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.User), nil
|
||||
return a.Srv.Store.User().GetByAuth(authData, authService)
|
||||
}
|
||||
|
||||
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 {
|
||||
err := (<-a.Srv.Store.User().VerifyEmail(userId, email)).Err
|
||||
|
||||
_, err := a.Srv.Store.User().VerifyEmail(userId, email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ package commands
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func TestAssignRole(t *testing.T) {
|
||||
@@ -15,10 +13,9 @@ func TestAssignRole(t *testing.T) {
|
||||
|
||||
th.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
|
||||
|
||||
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
user := result.Data.(*model.User)
|
||||
if user.Roles != "system_user system_admin" {
|
||||
t.Fatal("Got wrong roles:", user.Roles)
|
||||
}
|
||||
@@ -26,10 +23,9 @@ func TestAssignRole(t *testing.T) {
|
||||
|
||||
th.CheckCommand(t, "roles", "member", th.BasicUser.Email)
|
||||
|
||||
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
user := result.Data.(*model.User)
|
||||
if user.Roles != "system_user" {
|
||||
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] + "'")
|
||||
continue
|
||||
}
|
||||
if cresult := <-a.Srv.Store.User().VerifyEmail(user.Id, user.Email); cresult.Err != nil {
|
||||
CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error())
|
||||
if _, err := a.Srv.Store.User().VerifyEmail(user.Id, user.Email); err != nil {
|
||||
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)
|
||||
|
||||
if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if user, err := th.App.Srv.Store.User().GetByEmail(email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
user := result.Data.(*model.User)
|
||||
require.Equal(t, email, user.Email)
|
||||
}
|
||||
}
|
||||
@@ -85,13 +84,12 @@ func TestChangeUserEmail(t *testing.T) {
|
||||
newEmail := model.NewId() + "@mattermost-test.com"
|
||||
|
||||
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")
|
||||
}
|
||||
if result := <-th.App.Srv.Store.User().GetByEmail(newEmail); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if user, err := th.App.Srv.Store.User().GetByEmail(newEmail); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
user := result.Data.(*model.User)
|
||||
if user.Email != newEmail {
|
||||
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 {
|
||||
var user *model.User
|
||||
if result := <-a.Srv.Store.User().GetByEmail(userArg); result.Err == nil {
|
||||
user = result.Data.(*model.User)
|
||||
}
|
||||
user, _ := a.Srv.Store.User().GetByEmail(userArg)
|
||||
|
||||
if user == 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
|
||||
}
|
||||
|
||||
<-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)
|
||||
|
||||
userID = user.Id
|
||||
|
||||
@@ -949,55 +949,45 @@ func (us SqlUserStore) GetSystemAdminProfiles() store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetByEmail(email string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
email = strings.ToLower(email)
|
||||
func (us SqlUserStore) GetByEmail(email string) (*model.User, *model.AppError) {
|
||||
email = strings.ToLower(email)
|
||||
|
||||
query := us.usersQuery.Where("Email = ?", email)
|
||||
query := us.usersQuery.Where("Email = ?", email)
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetByEmail", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlUserStore.GetByEmail", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
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)
|
||||
}
|
||||
user := model.User{}
|
||||
if err := us.GetReplica().SelectOne(&user, queryString, args...); err != nil {
|
||||
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 {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if authData == nil || *authData == "" {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData='', authService="+authService, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
func (us SqlUserStore) GetByAuth(authData *string, authService string) (*model.User, *model.AppError) {
|
||||
if authData == nil || *authData == "" {
|
||||
return nil, model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData='', authService="+authService, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
query := us.usersQuery.
|
||||
Where("u.AuthData = ?", authData).
|
||||
Where("u.AuthService = ?", authService)
|
||||
query := us.usersQuery.
|
||||
Where("u.AuthData = ?", authData).
|
||||
Where("u.AuthService = ?", authService)
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
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
|
||||
} else if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
result.Data = &user
|
||||
})
|
||||
user := model.User{}
|
||||
if err := us.GetReplica().SelectOne(&user, queryString, args...); err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError)
|
||||
} 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)
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
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 {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
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 {
|
||||
result.Err = model.NewAppError("SqlUserStore.VerifyEmail", "store.sql_user.verify_email.app_error", nil, "userId="+userId+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
func (us SqlUserStore) VerifyEmail(userId, email string) (string, *model.AppError) {
|
||||
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 {
|
||||
return "", 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 {
|
||||
|
||||
@@ -268,12 +268,12 @@ type UserStore interface {
|
||||
GetProfiles(options *model.UserGetOptions) StoreChannel
|
||||
GetProfileByIds(userId []string, allowFromCache bool, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
||||
InvalidatProfileCacheForUser(userId string)
|
||||
GetByEmail(email string) StoreChannel
|
||||
GetByAuth(authData *string, authService string) StoreChannel
|
||||
GetByEmail(email string) (*model.User, *model.AppError)
|
||||
GetByAuth(authData *string, authService string) (*model.User, *model.AppError)
|
||||
GetAllUsingAuthService(authService string) StoreChannel
|
||||
GetByUsername(username string) StoreChannel
|
||||
GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) StoreChannel
|
||||
VerifyEmail(userId, email string) StoreChannel
|
||||
VerifyEmail(userId, email string) (string, *model.AppError)
|
||||
GetEtagForAllProfiles() StoreChannel
|
||||
GetEtagForProfiles(teamId string) 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
|
||||
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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(*string, string) store.StoreChannel); ok {
|
||||
var r0 *model.User
|
||||
if rf, ok := ret.Get(0).(func(*string, string) *model.User); ok {
|
||||
r0 = rf(authData, 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, 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
|
||||
func (_m *UserStore) GetByEmail(email string) store.StoreChannel {
|
||||
func (_m *UserStore) GetByEmail(email string) (*model.User, *model.AppError) {
|
||||
ret := _m.Called(email)
|
||||
|
||||
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(email)
|
||||
} 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(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
|
||||
@@ -884,17 +902,24 @@ func (_m *UserStore) UpdateUpdateAt(userId string) store.StoreChannel {
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func(string, string) string); ok {
|
||||
r0 = rf(userId, email)
|
||||
} 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) *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)) }()
|
||||
|
||||
t.Run("get u1 by email", func(t *testing.T) {
|
||||
result := <-ss.User().GetByEmail(u1.Email)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, u1, result.Data.(*model.User))
|
||||
u, err := ss.User().GetByEmail(u1.Email)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, u1, u)
|
||||
})
|
||||
|
||||
t.Run("get u2 by email", func(t *testing.T) {
|
||||
result := <-ss.User().GetByEmail(u2.Email)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, u2, result.Data.(*model.User))
|
||||
u, err := ss.User().GetByEmail(u2.Email)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, u2, u)
|
||||
})
|
||||
|
||||
t.Run("get u3 by email", func(t *testing.T) {
|
||||
result := <-ss.User().GetByEmail(u3.Email)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, u3, result.Data.(*model.User))
|
||||
u, err := ss.User().GetByEmail(u3.Email)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, u3, u)
|
||||
})
|
||||
|
||||
t.Run("get by empty email", func(t *testing.T) {
|
||||
result := <-ss.User().GetByEmail("")
|
||||
require.NotNil(t, result.Err)
|
||||
require.Equal(t, result.Err.Id, store.MISSING_ACCOUNT_ERROR)
|
||||
_, err := ss.User().GetByEmail("")
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, err.Id, store.MISSING_ACCOUNT_ERROR)
|
||||
})
|
||||
|
||||
t.Run("get by unknown", func(t *testing.T) {
|
||||
result := <-ss.User().GetByEmail("unknown")
|
||||
require.NotNil(t, result.Err)
|
||||
require.Equal(t, result.Err.Id, store.MISSING_ACCOUNT_ERROR)
|
||||
_, err := ss.User().GetByEmail("unknown")
|
||||
require.NotNil(t, err)
|
||||
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)) }()
|
||||
|
||||
t.Run("get by u1 auth", func(t *testing.T) {
|
||||
result := <-ss.User().GetByAuth(u1.AuthData, u1.AuthService)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, u1, result.Data.(*model.User))
|
||||
u, err := ss.User().GetByAuth(u1.AuthData, u1.AuthService)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, u1, u)
|
||||
})
|
||||
|
||||
t.Run("get by u3 auth", func(t *testing.T) {
|
||||
result := <-ss.User().GetByAuth(u3.AuthData, u3.AuthService)
|
||||
require.Nil(t, result.Err)
|
||||
assert.Equal(t, u3, result.Data.(*model.User))
|
||||
u, err := ss.User().GetByAuth(u3.AuthData, u3.AuthService)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, u3, u)
|
||||
})
|
||||
|
||||
t.Run("get by u1 auth, unknown service", func(t *testing.T) {
|
||||
result := <-ss.User().GetByAuth(u1.AuthData, "unknown")
|
||||
require.NotNil(t, result.Err)
|
||||
require.Equal(t, result.Err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
|
||||
_, err := ss.User().GetByAuth(u1.AuthData, "unknown")
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
|
||||
})
|
||||
|
||||
t.Run("get by unknown auth, u1 service", func(t *testing.T) {
|
||||
unknownAuth := ""
|
||||
result := <-ss.User().GetByAuth(&unknownAuth, u1.AuthService)
|
||||
require.NotNil(t, result.Err)
|
||||
require.Equal(t, result.Err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
|
||||
_, err := ss.User().GetByAuth(&unknownAuth, u1.AuthService)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
|
||||
})
|
||||
|
||||
t.Run("get by unknown auth, unknown service", func(t *testing.T) {
|
||||
unknownAuth := ""
|
||||
result := <-ss.User().GetByAuth(&unknownAuth, "unknown")
|
||||
require.NotNil(t, result.Err)
|
||||
require.Equal(t, result.Err.Id, store.MISSING_AUTH_ACCOUNT_ERROR)
|
||||
_, err := ss.User().GetByAuth(&unknownAuth, "unknown")
|
||||
require.NotNil(t, err)
|
||||
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)
|
||||
}
|
||||
|
||||
if r1 := <-ss.User().GetByEmail(u1.Email); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if user, err := ss.User().GetByEmail(u1.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
user := r1.Data.(*model.User)
|
||||
if user.Password != hashedPassword {
|
||||
t.Fatal("Password was not updated correctly")
|
||||
}
|
||||
@@ -1643,10 +1642,9 @@ func testUserStoreUpdateAuthData(t *testing.T, ss store.Store) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if r1 := <-ss.User().GetByEmail(u1.Email); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if user, err := ss.User().GetByEmail(u1.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
user := r1.Data.(*model.User)
|
||||
if user.AuthService != service {
|
||||
t.Fatal("AuthService was not updated correctly")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user