diff options
author | Zisu Zhang <thezzisu@gmail.com> | 2024-10-06 04:41:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-05 20:41:38 +0000 |
commit | 66923e02d20e9d5b68ab20fbcdebd779eb4dbaf9 (patch) | |
tree | 08af3f6b45b7e9d25ccc4c1a64bf8c62f9227799 /routers/web/user/setting | |
parent | 6a4eb126bd911e36489979954f0b3a3ebc1ae19f (diff) | |
download | gitea-66923e02d20e9d5b68ab20fbcdebd779eb4dbaf9.tar.gz gitea-66923e02d20e9d5b68ab20fbcdebd779eb4dbaf9.zip |
Enhance USER_DISABLED_FEATURES to allow disabling change username or full name (#31959)
Fix #31958
Enhanced `USER_DISABLED_FEATURES`(also `EXTERNAL_USER_DISABLE_FEATURES`)
option in `[admin]` section.
Added following values:
- `change_username`: Disable change username
- `change_full_name`: Disable change full name
---
Progress:
- [x] Update code
- [x] Update translations
Diffstat (limited to 'routers/web/user/setting')
-rw-r--r-- | routers/web/user/setting/profile.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 554f6cd6ce..3b051c9b5f 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -69,6 +69,11 @@ func ProfilePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.UpdateProfileForm) if form.Name != "" { + if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureChangeUsername) { + ctx.Flash.Error(ctx.Tr("user.form.change_username_disabled")) + ctx.Redirect(setting.AppSubURL + "/user/settings") + return + } if err := user_service.RenameUser(ctx, ctx.Doer, form.Name); err != nil { switch { case user_model.IsErrUserIsNotLocal(err): @@ -91,7 +96,6 @@ func ProfilePost(ctx *context.Context) { } opts := &user_service.UpdateOptions{ - FullName: optional.Some(form.FullName), KeepEmailPrivate: optional.Some(form.KeepEmailPrivate), Description: optional.Some(form.Description), Website: optional.Some(form.Website), @@ -99,6 +103,16 @@ func ProfilePost(ctx *context.Context) { Visibility: optional.Some(form.Visibility), KeepActivityPrivate: optional.Some(form.KeepActivityPrivate), } + + if form.FullName != "" { + if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureChangeFullName) { + ctx.Flash.Error(ctx.Tr("user.form.change_full_name_disabled")) + ctx.Redirect(setting.AppSubURL + "/user/settings") + return + } + opts.FullName = optional.Some(form.FullName) + } + if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil { ctx.ServerError("UpdateUser", err) return |