mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-28 21:00:03 +02:00
Only validate changed columns when update user (#24867)
Fix #23211 Replace #23496
This commit is contained in:
parent
37895b61c0
commit
a523bd5889
2 changed files with 34 additions and 9 deletions
|
@ -621,7 +621,7 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
|
|||
}
|
||||
|
||||
// validate data
|
||||
if err := validateUser(u); err != nil {
|
||||
if err := ValidateUser(u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -767,19 +767,26 @@ func checkDupEmail(ctx context.Context, u *User) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// validateUser check if user is valid to insert / update into database
|
||||
func validateUser(u *User) error {
|
||||
if !setting.Service.AllowedUserVisibilityModesSlice.IsAllowedVisibility(u.Visibility) && !u.IsOrganization() {
|
||||
return fmt.Errorf("visibility Mode not allowed: %s", u.Visibility.String())
|
||||
// ValidateUser check if user is valid to insert / update into database
|
||||
func ValidateUser(u *User, cols ...string) error {
|
||||
if len(cols) == 0 || util.SliceContainsString(cols, "visibility", true) {
|
||||
if !setting.Service.AllowedUserVisibilityModesSlice.IsAllowedVisibility(u.Visibility) && !u.IsOrganization() {
|
||||
return fmt.Errorf("visibility Mode not allowed: %s", u.Visibility.String())
|
||||
}
|
||||
}
|
||||
|
||||
u.Email = strings.ToLower(u.Email)
|
||||
return ValidateEmail(u.Email)
|
||||
if len(cols) == 0 || util.SliceContainsString(cols, "email", true) {
|
||||
u.Email = strings.ToLower(u.Email)
|
||||
if err := ValidateEmail(u.Email); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateUser updates user's information.
|
||||
func UpdateUser(ctx context.Context, u *User, changePrimaryEmail bool, cols ...string) error {
|
||||
err := validateUser(u)
|
||||
err := ValidateUser(u, cols...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -845,7 +852,7 @@ func UpdateUser(ctx context.Context, u *User, changePrimaryEmail bool, cols ...s
|
|||
|
||||
// UpdateUserCols update user according special columns
|
||||
func UpdateUserCols(ctx context.Context, u *User, cols ...string) error {
|
||||
if err := validateUser(u); err != nil {
|
||||
if err := ValidateUser(u, cols...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue