mirror of
https://github.com/go-gitea/gitea
synced 2024-11-18 22:39:30 +01:00
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
This commit is contained in:
parent
6a4eb126bd
commit
66923e02d2
@ -1507,6 +1507,8 @@ LEVEL = Info
|
||||
;; - manage_gpg_keys: a user cannot configure gpg keys
|
||||
;; - manage_mfa: a user cannot configure mfa devices
|
||||
;; - manage_credentials: a user cannot configure emails, passwords, or openid
|
||||
;; - change_username: a user cannot change their username
|
||||
;; - change_full_name: a user cannot change their full name
|
||||
;;EXTERNAL_USER_DISABLE_FEATURES =
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -29,4 +29,6 @@ const (
|
||||
UserFeatureManageGPGKeys = "manage_gpg_keys"
|
||||
UserFeatureManageMFA = "manage_mfa"
|
||||
UserFeatureManageCredentials = "manage_credentials"
|
||||
UserFeatureChangeUsername = "change_username"
|
||||
UserFeatureChangeFullName = "change_full_name"
|
||||
)
|
||||
|
@ -580,6 +580,8 @@ lang_select_error = Select a language from the list.
|
||||
|
||||
username_been_taken = The username is already taken.
|
||||
username_change_not_local_user = Non-local users are not allowed to change their username.
|
||||
change_username_disabled = Changing username is disabled.
|
||||
change_full_name_disabled = Changing full name is disabled.
|
||||
username_has_not_been_changed = Username has not been changed
|
||||
repo_name_been_taken = The repository name is already used.
|
||||
repository_force_private = Force Private is enabled: private repositories cannot be made public.
|
||||
@ -705,7 +707,8 @@ public_profile = Public Profile
|
||||
biography_placeholder = Tell us a little bit about yourself! (You can use Markdown)
|
||||
location_placeholder = Share your approximate location with others
|
||||
profile_desc = Control how your profile is show to other users. Your primary email address will be used for notifications, password recovery and web-based Git operations.
|
||||
password_username_disabled = Non-local users are not allowed to change their username. Please contact your site administrator for more details.
|
||||
password_username_disabled = You are not allowed to change their username. Please contact your site administrator for more details.
|
||||
password_full_name_disabled = You are not allowed to change their full name. Please contact your site administrator for more details.
|
||||
full_name = Full Name
|
||||
website = Website
|
||||
location = Location
|
||||
|
@ -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
|
||||
|
@ -12,14 +12,17 @@
|
||||
<span class="text red tw-hidden" id="name-change-prompt"> {{ctx.Locale.Tr "settings.change_username_prompt"}}</span>
|
||||
<span class="text red tw-hidden" id="name-change-redirect-prompt"> {{ctx.Locale.Tr "settings.change_username_redirect_prompt"}}</span>
|
||||
</label>
|
||||
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}disabled{{end}} maxlength="40">
|
||||
{{if or (not .SignedUser.IsLocal) .IsReverseProxy}}
|
||||
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) ($.UserDisabledFeatures.Contains "change_username") .IsReverseProxy}}disabled{{end}} maxlength="40">
|
||||
{{if or (not .SignedUser.IsLocal) ($.UserDisabledFeatures.Contains "change_username") .IsReverseProxy}}
|
||||
<p class="help text blue">{{ctx.Locale.Tr "settings.password_username_disabled"}}</p>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="field {{if .Err_FullName}}error{{end}}">
|
||||
<label for="full_name">{{ctx.Locale.Tr "settings.full_name"}}</label>
|
||||
<input id="full_name" name="full_name" value="{{.SignedUser.FullName}}" maxlength="100">
|
||||
<input id="full_name" name="full_name" value="{{.SignedUser.FullName}}" {{if ($.UserDisabledFeatures.Contains "change_full_name")}}disabled{{end}} maxlength="100">
|
||||
{{if ($.UserDisabledFeatures.Contains "change_full_name")}}
|
||||
<p class="help text blue">{{ctx.Locale.Tr "settings.password_full_name_disabled"}}</p>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="field {{if .Err_Email}}error{{end}}">
|
||||
<label>{{ctx.Locale.Tr "email"}}</label>
|
||||
|
Loading…
Reference in New Issue
Block a user