Skip to content

Commit 3473062

Browse files
committed
feat: update implementation
1 parent 7128278 commit 3473062

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

modules/setting/admin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var Admin struct {
1313
DefaultEmailNotification string
1414
UserDisabledFeatures container.Set[string]
1515
ExternalUserDisableFeatures container.Set[string]
16-
ExternalUserLockFullName bool
1716
}
1817

1918
func loadAdminFrom(rootCfg ConfigProvider) {
@@ -22,7 +21,6 @@ func loadAdminFrom(rootCfg ConfigProvider) {
2221
Admin.DefaultEmailNotification = sec.Key("DEFAULT_EMAIL_NOTIFICATIONS").MustString("enabled")
2322
Admin.UserDisabledFeatures = container.SetOf(sec.Key("USER_DISABLED_FEATURES").Strings(",")...)
2423
Admin.ExternalUserDisableFeatures = container.SetOf(sec.Key("EXTERNAL_USER_DISABLE_FEATURES").Strings(",")...).Union(Admin.UserDisabledFeatures)
25-
Admin.ExternalUserLockFullName = sec.Key("EXTERNAL_USER_LOCK_FULL_NAME").MustBool(false)
2624
}
2725

2826
const (
@@ -31,4 +29,6 @@ const (
3129
UserFeatureManageGPGKeys = "manage_gpg_keys"
3230
UserFeatureManageMFA = "manage_mfa"
3331
UserFeatureManageCredentials = "manage_credentials"
32+
UserFeatureChangeUsername = "change_username"
33+
UserFeatureChangeFullName = "change_full_name"
3434
)

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ lang_select_error = Select a language from the list.
579579
580580
username_been_taken = The username is already taken.
581581
username_change_not_local_user = Non-local users are not allowed to change their username.
582+
change_username_disabled = Changing username is disabled.
583+
change_full_name_disabled = Changing full name is disabled.
582584
username_has_not_been_changed = Username has not been changed
583585
repo_name_been_taken = The repository name is already used.
584586
repository_force_private = Force Private is enabled: private repositories cannot be made public.

routers/web/user/setting/profile.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ func Profile(ctx *context.Context) {
5050

5151
ctx.Data["UserDisabledFeatures"] = user_model.DisabledFeaturesWithLoginType(ctx.Doer)
5252

53-
ctx.Data["ExternalUserLockFullName"] = setting.Admin.ExternalUserLockFullName
54-
5553
ctx.HTML(http.StatusOK, tplSettingsProfile)
5654
}
5755

@@ -71,6 +69,11 @@ func ProfilePost(ctx *context.Context) {
7169
form := web.GetForm(ctx).(*forms.UpdateProfileForm)
7270

7371
if form.Name != "" {
72+
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureChangeUsername) {
73+
ctx.Flash.Error(ctx.Tr("user.form.change_username_disabled"))
74+
ctx.Redirect(setting.AppSubURL + "/user/settings")
75+
return
76+
}
7477
if err := user_service.RenameUser(ctx, ctx.Doer, form.Name); err != nil {
7578
switch {
7679
case user_model.IsErrUserIsNotLocal(err):
@@ -93,7 +96,6 @@ func ProfilePost(ctx *context.Context) {
9396
}
9497

9598
opts := &user_service.UpdateOptions{
96-
FullName: optional.Some(form.FullName),
9799
KeepEmailPrivate: optional.Some(form.KeepEmailPrivate),
98100
Description: optional.Some(form.Description),
99101
Website: optional.Some(form.Website),
@@ -102,8 +104,13 @@ func ProfilePost(ctx *context.Context) {
102104
KeepActivityPrivate: optional.Some(form.KeepActivityPrivate),
103105
}
104106

105-
if !ctx.Doer.IsLocal() && setting.Admin.ExternalUserLockFullName {
106-
opts.FullName = optional.None[string]()
107+
if form.FullName != "" {
108+
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureChangeFullName) {
109+
ctx.Flash.Error(ctx.Tr("user.form.change_full_name_disabled"))
110+
ctx.Redirect(setting.AppSubURL + "/user/settings")
111+
return
112+
}
113+
opts.FullName = optional.Some(form.FullName)
107114
}
108115

109116
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {

templates/user/settings/profile.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
<span class="text red tw-hidden" id="name-change-prompt"> {{ctx.Locale.Tr "settings.change_username_prompt"}}</span>
1313
<span class="text red tw-hidden" id="name-change-redirect-prompt"> {{ctx.Locale.Tr "settings.change_username_redirect_prompt"}}</span>
1414
</label>
15-
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}disabled{{end}} maxlength="40">
16-
{{if or (not .SignedUser.IsLocal) .IsReverseProxy}}
15+
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (or (not .SignedUser.IsLocal) ($.UserDisabledFeatures.Contains "change_username")) .IsReverseProxy}}disabled{{end}} maxlength="40">
16+
{{if or (or (not .SignedUser.IsLocal) ($.UserDisabledFeatures.Contains "change_username")) .IsReverseProxy}}
1717
<p class="help text blue">{{ctx.Locale.Tr "settings.password_username_disabled"}}</p>
1818
{{end}}
1919
</div>
2020
<div class="field {{if .Err_FullName}}error{{end}}">
2121
<label for="full_name">{{ctx.Locale.Tr "settings.full_name"}}</label>
22-
<input id="full_name" name="full_name" value="{{.SignedUser.FullName}}" {{if and (not .SignedUser.IsLocal) .ExternalUserLockFullName}}disabled{{end}} maxlength="100">
23-
{{if and (not .SignedUser.IsLocal) .ExternalUserLockFullName}}
22+
<input id="full_name" name="full_name" value="{{.SignedUser.FullName}}" {{if ($.UserDisabledFeatures.Contains "change_full_name")}}disabled{{end}} maxlength="100">
23+
{{if ($.UserDisabledFeatures.Contains "change_full_name")}}
2424
<p class="help text blue">{{ctx.Locale.Tr "settings.password_full_name_disabled"}}</p>
2525
{{end}}
2626
</div>

0 commit comments

Comments
 (0)