Updating user attributes on oauth login (#5324)
Moving update function to app package Fixing duplicate userID on create user test
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
04f4545bbd
Коммит
c0bb6f99f8
@@ -127,7 +127,6 @@ func (us SqlUserStore) Save(user *model.User) StoreChannel {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
@@ -164,7 +163,9 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreCha
|
||||
}
|
||||
|
||||
if user.IsOAuthUser() {
|
||||
user.Email = oldUser.Email
|
||||
if !trustedUpdateData {
|
||||
user.Email = oldUser.Email
|
||||
}
|
||||
} else if user.IsLDAPUser() && !trustedUpdateData {
|
||||
if user.Username != oldUser.Username ||
|
||||
user.Email != oldUser.Email {
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
)
|
||||
|
||||
func TestUserStoreSave(t *testing.T) {
|
||||
@@ -103,6 +104,32 @@ func TestUserStoreUpdate(t *testing.T) {
|
||||
if err := (<-store.User().Update(u2, false)).Err; err == nil {
|
||||
t.Fatal("Update should have failed because you can't modify AD/LDAP fields")
|
||||
}
|
||||
|
||||
u3 := &model.User{}
|
||||
u3.Email = model.NewId()
|
||||
oldEmail := u3.Email
|
||||
u3.AuthService = "gitlab"
|
||||
Must(store.User().Save(u3))
|
||||
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u3.Id}))
|
||||
|
||||
u3.Email = model.NewId()
|
||||
if result := <-store.User().Update(u3, false); result.Err != nil {
|
||||
t.Fatal("Update should not have failed")
|
||||
} else {
|
||||
newUser := result.Data.([2]*model.User)[0]
|
||||
if newUser.Email != oldEmail {
|
||||
t.Fatal("Email should not have been updated as the update is not trusted")
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-store.User().Update(u3, true); result.Err != nil {
|
||||
t.Fatal("Update should not have failed")
|
||||
} else {
|
||||
newUser := result.Data.([2]*model.User)[0]
|
||||
if newUser.Email != u3.Email {
|
||||
t.Fatal("Email should have been updated as the update is trusted")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserStoreUpdateUpdateAt(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user