Skip to content

Commit 7eae056

Browse files
committed
fix
1 parent 8ae3bb1 commit 7eae056

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,8 +3426,7 @@ config.disable_gravatar = Disable Gravatar
34263426
config.enable_federated_avatar = Enable Federated Avatars
34273427
config.open_with_editor_app_help = The "Open with" editors for the clone menu. If left empty, the default will be used. Expand to see the default.
34283428
3429-
config.git_guide = Git Guide
3430-
config.git_guide.remote_name = Git Remote Name
3429+
config.git_guide_remote_name = Repository remote name for git commands in the guide
34313430
34323431
config.git_config = Git Configuration
34333432
config.git_disable_diff_highlight = Disable Diff Syntax Highlight

routers/web/admin/config.go

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ func ConfigSettings(ctx *context.Context) {
196196
}
197197

198198
func ChangeConfig(ctx *context.Context) {
199-
key := strings.TrimSpace(ctx.FormString("key"))
200-
value := ctx.FormString("value")
201199
cfg := setting.Config()
202200

203201
marshalBool := func(v string) (string, error) { //nolint:unparam // error is always nil
@@ -248,21 +246,38 @@ func ChangeConfig(ctx *context.Context) {
248246
cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps,
249247
cfg.Template.GitRemoteName.DynKey(): marshalString,
250248
}
251-
marshaller, hasMarshaller := marshallers[key]
252-
if !hasMarshaller {
253-
ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key))
254-
return
255-
}
256-
marshaledValue, err := marshaller(value)
257-
if err != nil {
258-
ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key))
259-
return
260-
}
261-
if err = system_model.SetSettings(ctx, map[string]string{key: marshaledValue}); err != nil {
262-
ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key))
263-
return
249+
250+
_ = ctx.Req.ParseForm()
251+
queryKeys := ctx.Req.Form["key"]
252+
queryValues := ctx.Req.Form["value"]
253+
loop:
254+
for i, key := range queryKeys {
255+
if i >= len(queryValues) {
256+
ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key))
257+
break loop
258+
}
259+
value := queryValues[i]
260+
261+
marshaller, hasMarshaller := marshallers[key]
262+
if !hasMarshaller {
263+
ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key))
264+
break loop
265+
}
266+
267+
marshaledValue, err := marshaller(value)
268+
if err != nil {
269+
ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key))
270+
break loop
271+
}
272+
273+
if err = system_model.SetSettings(ctx, map[string]string{key: marshaledValue}); err != nil {
274+
ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key))
275+
break loop
276+
}
264277
}
265278

266279
config.GetDynGetter().InvalidateCache()
267-
ctx.JSONOK()
280+
if !ctx.Written() {
281+
ctx.JSONOK()
282+
}
268283
}

templates/admin/config_settings.tmpl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,22 @@
2424
{{ctx.Locale.Tr "repository"}}
2525
</h4>
2626
<div class="ui attached segment">
27-
<form class="ui form form-fetch-action" method="post" action="{{AppSubUrl}}/-/admin/config?key={{.SystemConfig.Repository.OpenWithEditorApps.DynKey}}">
27+
<form class="ui form form-fetch-action" method="post" action="{{AppSubUrl}}/-/admin/config">
2828
<div class="field">
2929
<details>
3030
<summary>{{ctx.Locale.Tr "admin.config.open_with_editor_app_help"}}</summary>
3131
<pre class="tw-px-4">{{.DefaultOpenWithEditorAppsString}}</pre>
3232
</details>
3333
</div>
3434
<div class="field">
35+
<input type="hidden" name="key" value="{{.SystemConfig.Repository.OpenWithEditorApps.DynKey}}">
3536
<textarea name="value">{{(.SystemConfig.Repository.OpenWithEditorApps.Value ctx).ToTextareaString}}</textarea>
3637
</div>
37-
<div class="field">
38-
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>
39-
</div>
40-
</form>
41-
</div>
4238

43-
<h4 class="ui top attached header">
44-
{{ctx.Locale.Tr "admin.config.git_guide"}}
45-
</h4>
46-
<div class="ui attached segment">
47-
<form class="ui form form-fetch-action" method="post" action="{{AppSubUrl}}/-/admin/config?key={{.SystemConfig.Template.GitRemoteName.DynKey}}">
48-
<div class="field" data-field-patched="true">
49-
<label for="remote_name">{{ctx.Locale.Tr "admin.config.git_guide.remote_name"}}</label>
50-
<input id="remote_name" name="value" value="{{.SystemConfig.Template.GitRemoteName.Value ctx}}" maxlength="100" dir="auto" required>
39+
<div class="field">
40+
<label>{{ctx.Locale.Tr "admin.config.git_guide_remote_name"}}</label>
41+
<input type="hidden" name="key" value="{{.SystemConfig.Template.GitRemoteName.DynKey}}">
42+
<input name="value" value="{{.SystemConfig.Template.GitRemoteName.Value ctx}}" maxlength="100" dir="auto" required pattern="^[A-Za-z0-9][\-_A-Za-z0-9]*$">
5143
</div>
5244
<div class="field">
5345
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>

0 commit comments

Comments
 (0)