Skip to content

Commit 28d5d51

Browse files
committed
check rename condition in the service method instead of outside
1 parent d426866 commit 28d5d51

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

routers/web/admin/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func EditUserPost(ctx *context.Context) {
347347
return
348348
}
349349

350-
if form.UserName != "" && form.UserName != u.Name {
350+
if form.UserName != "" {
351351
if err := user_service.RenameUser(ctx, u, form.UserName); err != nil {
352352
switch {
353353
case user_model.IsErrUserIsNotLocal(err):

services/user/user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import (
3232

3333
// RenameUser renames a user
3434
func RenameUser(ctx context.Context, u *user_model.User, newUserName string) error {
35+
if newUserName == u.Name {
36+
return nil
37+
}
38+
3539
// Non-local users are not allowed to change their username.
3640
if !u.IsOrganization() && !u.IsLocal() {
3741
return user_model.ErrUserIsNotLocal{
@@ -40,10 +44,6 @@ func RenameUser(ctx context.Context, u *user_model.User, newUserName string) err
4044
}
4145
}
4246

43-
if newUserName == u.Name {
44-
return nil
45-
}
46-
4747
if err := user_model.IsUsableUsername(newUserName); err != nil {
4848
return err
4949
}

0 commit comments

Comments
 (0)