-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify user update methods #28733
Unify user update methods #28733
Conversation
log.Error("SyncExternalUsers[%s]: Error updating user %s: %v", source.authSource.Name, usr.Name, err) | ||
} | ||
|
||
if err := user_service.ReplacePrimaryEmailAddress(ctx, usr, su.Mail); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes #28660. If we decide this is not a bug but a breaking change, I will change this to AddOrSetPrimaryEmailAddress
and make a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this isn't expected behavior, so this shouldn't be considered as breaking
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
||
func AddOrSetPrimaryEmailAddress(ctx context.Context, u *user_model.User, emailStr string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently you can't really edit the user emails as admin. We only can set the primary address. This method mimics this behaviour but I propose to remove the email field from the admin user forms in future in favor of extended email edit endpoints.
…r-user-service
d28906b
to
89f71f6
Compare
if len(passwd) == 0 { | ||
u.Passwd = "" | ||
u.Salt = "" | ||
u.PasswdHashAlgo = "" | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not find a place where this is used in the current code base so I did not replicate it. Even if we use something like that, we should add a new method with a more descriptive name.
The only related place is
Lines 133 to 147 in a80debc
// Disable the user first | |
// NOTE: This is deliberately not within a transaction as it must disable the user immediately to prevent any further action by the user to be purged. | |
if err := user_model.UpdateUserCols(ctx, &user_model.User{ | |
ID: u.ID, | |
IsActive: false, | |
IsRestricted: true, | |
IsAdmin: false, | |
ProhibitLogin: true, | |
Passwd: "", | |
Salt: "", | |
PasswdHashAlgo: "", | |
MaxRepoCreation: 0, | |
}, "is_active", "is_restricted", "is_admin", "prohibit_login", "max_repo_creation", "passwd", "salt", "passwd_hash_algo"); err != nil { | |
return fmt.Errorf("unable to disable user: %s[%d] prior to purge. UpdateUserCols: %w", u.Name, u.ID, err) | |
} |
…r-user-service
models/user/user.go
Outdated
// ValidateUser check if user is valid to insert / update into database | ||
func ValidateUser(u *User, cols ...string) error { | ||
func ValidateUser(u *User, cols ...string) error { // TODO delete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be deleted?
…r-user-service
Ping for reviewers |
@KN4CK3R please fix the merge conflicts. 🍵 |
…r-user-service
* giteaofficial/main: [skip ci] Updated licenses and gitignores Show whether a PR is WIP inside popups (go-gitea#28975) Unify password changing and invalidate auth tokens (go-gitea#27625) Unify user update methods (go-gitea#28733) Do not render empty comments (go-gitea#29039)
Fixes go-gitea#28660 Fixes an admin api bug related to `user.LoginSource` Fixed `/user/emails` response not identical to GitHub api This PR unifies the user update methods. The goal is to keep the logic only at one place (having audit logs in mind). For example, do the password checks only in one method not everywhere a password is updated. After that PR is merged, the user creation should be next.
Fixes #28660
Fixes an admin api bug related to
user.LoginSource
Fixed
/user/emails
response not identical to GitHub apiThis PR unifies the user update methods. The goal is to keep the logic only at one place (having audit logs in mind). For example, do the password checks only in one method not everywhere a password is updated.
After that PR is merged, the user creation should be next.