Fix bug in updateUserForOriginalFields().

This commit is contained in:
Yang Luo
2021-12-25 00:19:17 +08:00
parent 4b4c9be71b
commit b60856be5e
2 changed files with 20 additions and 2 deletions

View File

@ -106,7 +106,7 @@ func (syncer *Syncer) updateUser(user *OriginalUser) bool {
func (syncer *Syncer) updateUserForOriginalFields(user *User) bool { func (syncer *Syncer) updateUserForOriginalFields(user *User) bool {
owner, name := util.GetOwnerAndNameFromId(user.GetId()) owner, name := util.GetOwnerAndNameFromId(user.GetId())
oldUser := getUser(owner, name) oldUser := getUserById(owner, name)
if oldUser == nil { if oldUser == nil {
return false return false
} }
@ -117,7 +117,7 @@ func (syncer *Syncer) updateUserForOriginalFields(user *User) bool {
columns := syncer.getCasdoorColumns() columns := syncer.getCasdoorColumns()
columns = append(columns, "affiliation", "hash", "pre_hash") columns = append(columns, "affiliation", "hash", "pre_hash")
affected, err := adapter.Engine.ID(core.PK{user.Owner, user.Name}).Cols(columns...).Update(user) affected, err := adapter.Engine.ID(core.PK{oldUser.Owner, oldUser.Name}).Cols(columns...).Update(user)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -181,6 +181,24 @@ func getUser(owner string, name string) *User {
} }
} }
func getUserById(owner string, id string) *User {
if owner == "" || id == "" {
return nil
}
user := User{Owner: owner, Id: id}
existed, err := adapter.Engine.Get(&user)
if err != nil {
panic(err)
}
if existed {
return &user
} else {
return nil
}
}
func GetUserByEmail(owner string, email string) *User { func GetUserByEmail(owner string, email string) *User {
if owner == "" || email == "" { if owner == "" || email == "" {
return nil return nil