From f5531a5a437fe549b29de58f28b2ee27efd9e455 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Dieguez Date: Tue, 27 Oct 2020 10:41:20 +0100 Subject: [PATCH] [MM-29523] EmailVerified flag can be user as parameter (#16031) * EmailVerified flag can be used as a parameter But only when if the user creator is an admin --- api4/user_test.go | 17 ++++++++++++++--- model/user.go | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/api4/user_test.go b/api4/user_test.go index 78717c3ef3..d839ad722c 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -24,11 +24,20 @@ func TestCreateUser(t *testing.T) { th := Setup(t) defer th.TearDown() - user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID} + user := model.User{ + Email: th.GenerateTestEmail(), + Nickname: "Corey Hulen", + Password: "hello1", + Username: GenerateTestUsername(), + Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID, + EmailVerified: true, + } ruser, resp := th.Client.CreateUser(&user) CheckNoError(t, resp) CheckCreatedStatus(t, resp) + // Creating a user as a regular user with verified flag should not verify the new user. + require.False(t, ruser.EmailVerified) _, _ = th.Client.Login(user.Email, user.Password) @@ -67,9 +76,11 @@ func TestCreateUser(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false }) th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { - user2 := &model.User{Email: th.GenerateTestEmail(), Password: "Password1", Username: GenerateTestUsername()} - _, resp = client.CreateUser(user2) + user2 := &model.User{Email: th.GenerateTestEmail(), Password: "Password1", Username: GenerateTestUsername(), EmailVerified: true} + ruser2, resp := client.CreateUser(user2) CheckNoError(t, resp) + // Creating a user as sysadmin should verify the user with the EmailVerified flag. + require.True(t, ruser2.EmailVerified) r, err := client.DoApiPost("/users", "garbage") require.NotNil(t, err, "should have errored") diff --git a/model/user.go b/model/user.go index 4e4d067c78..a053e53438 100644 --- a/model/user.go +++ b/model/user.go @@ -540,11 +540,11 @@ func (u *User) SanitizeInput(isAdmin bool) { if !isAdmin { u.AuthData = NewString("") u.AuthService = "" + u.EmailVerified = false } u.LastPasswordUpdate = 0 u.LastPictureUpdate = 0 u.FailedAttempts = 0 - u.EmailVerified = false u.MfaActive = false u.MfaSecret = "" }