Rename UpdateUser functions.

This commit is contained in:
Yang Luo
2021-08-21 22:52:29 +08:00
parent 4ca307564c
commit 9c3117beb0
3 changed files with 16 additions and 7 deletions

View File

@ -32,6 +32,7 @@ type User struct {
Password string `xorm:"varchar(100)" json:"password"` Password string `xorm:"varchar(100)" json:"password"`
DisplayName string `xorm:"varchar(100)" json:"displayName"` DisplayName string `xorm:"varchar(100)" json:"displayName"`
Avatar string `xorm:"varchar(255)" json:"avatar"` Avatar string `xorm:"varchar(255)" json:"avatar"`
PermanentAvatar string `xorm:"varchar(255)" json:"permanentAvatar"`
Email string `xorm:"varchar(100)" json:"email"` Email string `xorm:"varchar(100)" json:"email"`
Phone string `xorm:"varchar(100)" json:"phone"` Phone string `xorm:"varchar(100)" json:"phone"`
Location string `xorm:"varchar(100)" json:"location"` Location string `xorm:"varchar(100)" json:"location"`
@ -146,7 +147,8 @@ func GetLastUser(owner string) *User {
func UpdateUser(id string, user *User) bool { func UpdateUser(id string, user *User) bool {
owner, name := util.GetOwnerAndNameFromId(id) owner, name := util.GetOwnerAndNameFromId(id)
if getUser(owner, name) == nil { oldUser := getUser(owner, name)
if oldUser == nil {
return false return false
} }
@ -162,9 +164,10 @@ func UpdateUser(id string, user *User) bool {
return affected != 0 return affected != 0
} }
func UpdateUserInternal(id string, user *User) bool { func UpdateUserForAllFields(id string, user *User) bool {
owner, name := util.GetOwnerAndNameFromId(id) owner, name := util.GetOwnerAndNameFromId(id)
if getUser(owner, name) == nil { oldUser := getUser(owner, name)
if oldUser == nil {
return false return false
} }
@ -178,7 +181,13 @@ func UpdateUserInternal(id string, user *User) bool {
return affected != 0 return affected != 0
} }
func UpdateUserForOriginal(user *User) bool { func UpdateUserForOriginalFields(user *User) bool {
owner, name := util.GetOwnerAndNameFromId(user.GetId())
oldUser := getUser(owner, name)
if oldUser == nil {
return false
}
affected, err := adapter.Engine.ID(core.PK{user.Owner, user.Name}).Cols("display_name", "password", "phone", "avatar", "affiliation", "score", "is_forbidden", "hash", "pre_hash").Update(user) affected, err := adapter.Engine.ID(core.PK{user.Owner, user.Name}).Cols("display_name", "password", "phone", "avatar", "affiliation", "score", "is_forbidden", "hash", "pre_hash").Update(user)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -135,7 +135,7 @@ func SetUserOAuthProperties(organization *Organization, user *User, providerType
} }
} }
affected := UpdateUserInternal(user.GetId(), user) affected := UpdateUserForAllFields(user.GetId(), user)
return affected return affected
} }

View File

@ -112,7 +112,7 @@ func syncUsers() {
updatedUser := createUserFromOriginalUser(oUser, affiliationMap) updatedUser := createUserFromOriginalUser(oUser, affiliationMap)
updatedUser.Hash = oHash updatedUser.Hash = oHash
updatedUser.PreHash = oHash updatedUser.PreHash = oHash
object.UpdateUserForOriginal(updatedUser) object.UpdateUserForOriginalFields(updatedUser)
fmt.Printf("Update from oUser to user: %v\n", updatedUser) fmt.Printf("Update from oUser to user: %v\n", updatedUser)
} }
} else { } else {
@ -133,7 +133,7 @@ func syncUsers() {
updatedUser := createUserFromOriginalUser(oUser, affiliationMap) updatedUser := createUserFromOriginalUser(oUser, affiliationMap)
updatedUser.Hash = oHash updatedUser.Hash = oHash
updatedUser.PreHash = oHash updatedUser.PreHash = oHash
object.UpdateUserForOriginal(updatedUser) object.UpdateUserForOriginalFields(updatedUser)
fmt.Printf("Update from oUser to user (2nd condition): %v\n", updatedUser) fmt.Printf("Update from oUser to user (2nd condition): %v\n", updatedUser)
} }
} }