summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go33
1 files changed, 29 insertions, 4 deletions
diff --git a/models/user.go b/models/user.go
index 7c523f8266..bbdec74525 100644
--- a/models/user.go
+++ b/models/user.go
@@ -157,7 +157,7 @@ func (u *User) SetLastLogin() {
// UpdateDiffViewStyle updates the users diff view style
func (u *User) UpdateDiffViewStyle(style string) error {
u.DiffViewStyle = style
- return UpdateUser(u)
+ return UpdateUserCols(u, "diff_view_style")
}
// AfterSet is invoked from XORM after setting the value of a field of this object.
@@ -860,7 +860,9 @@ func updateUser(e Engine, u *User) error {
if len(u.AvatarEmail) == 0 {
u.AvatarEmail = u.Email
}
- u.Avatar = base.HashEmail(u.AvatarEmail)
+ if len(u.AvatarEmail) > 0 {
+ u.Avatar = base.HashEmail(u.AvatarEmail)
+ }
}
u.LowerName = strings.ToLower(u.Name)
@@ -877,6 +879,29 @@ func UpdateUser(u *User) error {
return updateUser(x, u)
}
+// UpdateUserCols update user according special columns
+func UpdateUserCols(u *User, cols ...string) error {
+ // Organization does not need email
+ u.Email = strings.ToLower(u.Email)
+ if !u.IsOrganization() {
+ if len(u.AvatarEmail) == 0 {
+ u.AvatarEmail = u.Email
+ }
+ if len(u.AvatarEmail) > 0 {
+ u.Avatar = base.HashEmail(u.AvatarEmail)
+ }
+ }
+
+ u.LowerName = strings.ToLower(u.Name)
+ u.Location = base.TruncateString(u.Location, 255)
+ u.Website = base.TruncateString(u.Website, 255)
+ u.Description = base.TruncateString(u.Description, 255)
+
+ cols = append(cols, "updated_unix")
+ _, err := x.Id(u.ID).Cols(cols...).Update(u)
+ return err
+}
+
// UpdateUserSetting updates user's settings.
func UpdateUserSetting(u *User) error {
if !u.IsOrganization() {
@@ -1418,7 +1443,7 @@ func SyncExternalUsers() {
}
usr.IsActive = true
- err = UpdateUser(usr)
+ err = UpdateUserCols(usr, "full_name", "email", "is_admin", "is_active")
if err != nil {
log.Error(4, "SyncExternalUsers[%s]: Error updating user %s: %v", s.Name, usr.Name, err)
}
@@ -1440,7 +1465,7 @@ func SyncExternalUsers() {
log.Trace("SyncExternalUsers[%s]: Deactivating user %s", s.Name, usr.Name)
usr.IsActive = false
- err = UpdateUser(&usr)
+ err = UpdateUserCols(&usr, "is_active")
if err != nil {
log.Error(4, "SyncExternalUsers[%s]: Error deactivating user %s: %v", s.Name, usr.Name, err)
}