From ba57e30f13906ad7104da7892dc3dc79721ed2fe Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Thu, 2 Dec 2021 10:43:43 +0800 Subject: [PATCH] fix 500 error while use a reserved name in org rename (#17878) fix #17876 Signed-off-by: a1012112796 <1012112796@qq.com> --- models/user/user.go | 6 ------ routers/web/org/setting.go | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/models/user/user.go b/models/user/user.go index 62f2aa472d..80ddcdba37 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -10,7 +10,6 @@ import ( "crypto/sha256" "crypto/subtle" "encoding/hex" - "errors" "fmt" "net/url" "os" @@ -73,11 +72,6 @@ const ( EmailNotificationsDisabled = "disabled" ) -var ( - // ErrUserNameIllegal user name contains illegal characters error - ErrUserNameIllegal = errors.New("User name contains illegal characters") -) - // User represents the object of individual and member of organization. type User struct { ID int64 `xorm:"pk autoincr"` diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index 0a328dfa4e..6c7f9ed62b 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -73,7 +73,7 @@ func SettingsPost(ctx *context.Context) { ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form) return } else if err = user_model.ChangeUserName(org.AsUser(), form.Name); err != nil { - if err == user_model.ErrUserNameIllegal { + if db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) { ctx.Data["OrgName"] = true ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form) } else {