diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 17:49:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 17:49:20 +0800 |
commit | a666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch) | |
tree | 9ab1434b759a8a2cb275a83149903a823851e309 /routers/web/user/setting | |
parent | 4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff) | |
download | gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip |
Move user related model into models/user (#17781)
* Move user related model into models/user
* Fix lint for windows
* Fix windows lint
* Fix windows lint
* Move some tests in models
* Merge
Diffstat (limited to 'routers/web/user/setting')
-rw-r--r-- | routers/web/user/setting/account.go | 12 | ||||
-rw-r--r-- | routers/web/user/setting/adopt.go | 3 | ||||
-rw-r--r-- | routers/web/user/setting/profile.go | 26 |
3 files changed, 21 insertions, 20 deletions
diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go index 603786697a..3b51fdb777 100644 --- a/routers/web/user/setting/account.go +++ b/routers/web/user/setting/account.go @@ -75,7 +75,7 @@ func AccountPost(ctx *context.Context) { ctx.ServerError("UpdateUser", err) return } - if err := models.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil { ctx.ServerError("UpdateUser", err) return } @@ -152,14 +152,14 @@ func EmailPost(ctx *context.Context) { // Set Email Notification Preference if ctx.FormString("_method") == "NOTIFICATION" { preference := ctx.FormString("preference") - if !(preference == models.EmailNotificationsEnabled || - preference == models.EmailNotificationsOnMention || - preference == models.EmailNotificationsDisabled) { + if !(preference == user_model.EmailNotificationsEnabled || + preference == user_model.EmailNotificationsOnMention || + preference == user_model.EmailNotificationsDisabled) { log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.User.Name) ctx.ServerError("SetEmailPreference", errors.New("option unrecognized")) return } - if err := models.SetEmailNotifications(ctx.User, preference); err != nil { + if err := user_model.SetEmailNotifications(ctx.User, preference); err != nil { log.Error("Set Email Notifications failed: %v", err) ctx.ServerError("SetEmailNotifications", err) return @@ -233,7 +233,7 @@ func DeleteAccount(ctx *context.Context) { ctx.Data["PageIsSettingsAccount"] = true if _, _, err := auth.UserSignIn(ctx.User.Name, ctx.FormString("password")); err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { loadAccountData(ctx) ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil) diff --git a/routers/web/user/setting/adopt.go b/routers/web/user/setting/adopt.go index 948cc1e936..56ab6ec999 100644 --- a/routers/web/user/setting/adopt.go +++ b/routers/web/user/setting/adopt.go @@ -8,6 +8,7 @@ import ( "path/filepath" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -27,7 +28,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) { action := ctx.FormString("action") ctxUser := ctx.User - root := models.UserPath(ctxUser.LowerName) + root := user_model.UserPath(ctxUser.LowerName) // check not a repo has, err := models.IsRepositoryExist(ctxUser, dir) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 1e515f2fd3..0475398a9a 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -49,7 +49,7 @@ func Profile(ctx *context.Context) { } // HandleUsernameChange handle username changes from user settings and admin interface -func HandleUsernameChange(ctx *context.Context, user *models.User, newName string) error { +func HandleUsernameChange(ctx *context.Context, user *user_model.User, newName string) error { // Non-local users are not allowed to change their username. if !user.IsLocal() { ctx.Flash.Error(ctx.Tr("form.username_change_not_local_user")) @@ -58,17 +58,17 @@ func HandleUsernameChange(ctx *context.Context, user *models.User, newName strin // Check if user name has been changed if user.LowerName != strings.ToLower(newName) { - if err := models.ChangeUserName(user, newName); err != nil { + if err := user_model.ChangeUserName(user, newName); err != nil { switch { - case models.IsErrUserAlreadyExist(err): + case user_model.IsErrUserAlreadyExist(err): ctx.Flash.Error(ctx.Tr("form.username_been_taken")) case user_model.IsErrEmailAlreadyUsed(err): ctx.Flash.Error(ctx.Tr("form.email_been_used")) - case models.IsErrNameReserved(err): + case db.IsErrNameReserved(err): ctx.Flash.Error(ctx.Tr("user.form.name_reserved", newName)) - case models.IsErrNamePatternNotAllowed(err): + case db.IsErrNamePatternNotAllowed(err): ctx.Flash.Error(ctx.Tr("user.form.name_pattern_not_allowed", newName)) - case models.IsErrNameCharsNotAllowed(err): + case db.IsErrNameCharsNotAllowed(err): ctx.Flash.Error(ctx.Tr("user.form.name_chars_not_allowed", newName)) default: ctx.ServerError("ChangeUserName", err) @@ -121,7 +121,7 @@ func ProfilePost(ctx *context.Context) { ctx.User.Description = form.Description ctx.User.KeepActivityPrivate = form.KeepActivityPrivate ctx.User.Visibility = form.Visibility - if err := models.UpdateUserSetting(ctx.User); err != nil { + if err := user_model.UpdateUserSetting(ctx.User); err != nil { if _, ok := err.(user_model.ErrEmailAlreadyUsed); ok { ctx.Flash.Error(ctx.Tr("form.email_been_used")) ctx.Redirect(setting.AppSubURL + "/user/settings") @@ -141,7 +141,7 @@ func ProfilePost(ctx *context.Context) { // UpdateAvatarSetting update user's avatar // FIXME: limit size. -func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *models.User) error { +func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *user_model.User) error { ctxUser.UseCustomAvatar = form.Source == forms.AvatarLocal if len(form.Gravatar) > 0 { if form.Avatar != nil { @@ -178,12 +178,12 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * } else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" { // No avatar is uploaded but setting has been changed to enable, // generate a random one when needed. - if err := models.GenerateRandomAvatar(ctxUser); err != nil { + if err := user_model.GenerateRandomAvatar(ctxUser); err != nil { log.Error("GenerateRandomAvatar[%d]: %v", ctxUser.ID, err) } } - if err := models.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil { return fmt.Errorf("UpdateUser: %v", err) } @@ -273,7 +273,7 @@ func Repos(ctx *context.Context) { repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum) repos := map[string]*models.Repository{} // We're going to iterate by pagesize. - root := models.UserPath(ctxUser.Name) + root := user_model.UserPath(ctxUser.Name) if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { if os.IsNotExist(err) { @@ -377,7 +377,7 @@ func UpdateUIThemePost(ctx *context.Context) { return } - if err := models.UpdateUserTheme(ctx.User, form.Theme); err != nil { + if err := user_model.UpdateUserTheme(ctx.User, form.Theme); err != nil { ctx.Flash.Error(ctx.Tr("settings.theme_update_error")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") return @@ -403,7 +403,7 @@ func UpdateUserLang(ctx *context.Context) { ctx.User.Language = form.Language } - if err := models.UpdateUserSetting(ctx.User); err != nil { + if err := user_model.UpdateUserSetting(ctx.User); err != nil { ctx.ServerError("UpdateUserSetting", err) return } |