]> source.dussan.org Git - gitea.git/commitdiff
Only rename a user when they should receive a different name (#32247)
authorLunny Xiao <xiaolunwen@gmail.com>
Sun, 13 Oct 2024 03:13:55 +0000 (11:13 +0800)
committerGitHub <noreply@github.com>
Sun, 13 Oct 2024 03:13:55 +0000 (03:13 +0000)
Fix #31996

services/user/user.go

index 2287e36c716acfaf80dfadedd9fa39317a003ffc..9aded62a51af8c5b2e7bcbbdfa1e3e47683f84d5 100644 (file)
@@ -32,6 +32,10 @@ import (
 
 // RenameUser renames a user
 func RenameUser(ctx context.Context, u *user_model.User, newUserName string) error {
+       if newUserName == u.Name {
+               return nil
+       }
+
        // Non-local users are not allowed to change their username.
        if !u.IsOrganization() && !u.IsLocal() {
                return user_model.ErrUserIsNotLocal{
@@ -40,10 +44,6 @@ func RenameUser(ctx context.Context, u *user_model.User, newUserName string) err
                }
        }
 
-       if newUserName == u.Name {
-               return nil
-       }
-
        if err := user_model.IsUsableUsername(newUserName); err != nil {
                return err
        }