@@ -196,17 +196,21 @@ func ConfigSettings(ctx *context.Context) {
196
196
}
197
197
198
198
func ChangeConfig (ctx * context.Context ) {
199
- key := strings .TrimSpace (ctx .FormString ("key" ))
200
- value := ctx .FormString ("value" )
201
199
cfg := setting .Config ()
202
200
203
- marshalBool := func (v string ) (string , error ) { //nolint:unparam // error is always nil
204
- if b , _ := strconv .ParseBool (v ); b {
205
- return "true" , nil
201
+ marshalBool := func (v string ) ([]byte , error ) {
202
+ b , _ := strconv .ParseBool (v )
203
+ return json .Marshal (b )
204
+ }
205
+
206
+ marshalString := func (emptyDefault string ) func (v string ) ([]byte , error ) {
207
+ return func (v string ) ([]byte , error ) {
208
+ return json .Marshal (util .IfZero (v , emptyDefault ))
206
209
}
207
- return "false" , nil
208
210
}
209
- marshalOpenWithApps := func (value string ) (string , error ) {
211
+
212
+ marshalOpenWithApps := func (value string ) ([]byte , error ) {
213
+ // TODO: move the block alongside OpenWithEditorAppsType.ToTextareaString
210
214
lines := strings .Split (value , "\n " )
211
215
var openWithEditorApps setting.OpenWithEditorAppsType
212
216
for _ , line := range lines {
@@ -224,32 +228,47 @@ func ChangeConfig(ctx *context.Context) {
224
228
OpenURL : strings .TrimSpace (openURL ),
225
229
})
226
230
}
227
- b , err := json .Marshal (openWithEditorApps )
228
- if err != nil {
229
- return "" , err
230
- }
231
- return string (b ), nil
231
+ return json .Marshal (openWithEditorApps )
232
232
}
233
- marshallers := map [string ]func (string ) (string , error ){
233
+ marshallers := map [string ]func (string ) ([] byte , error ){
234
234
cfg .Picture .DisableGravatar .DynKey (): marshalBool ,
235
235
cfg .Picture .EnableFederatedAvatar .DynKey (): marshalBool ,
236
236
cfg .Repository .OpenWithEditorApps .DynKey (): marshalOpenWithApps ,
237
+ cfg .Repository .GitGuideRemoteName .DynKey (): marshalString (cfg .Repository .GitGuideRemoteName .DefaultValue ()),
237
238
}
238
- marshaller , hasMarshaller := marshallers [key ]
239
- if ! hasMarshaller {
240
- ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
241
- return
239
+
240
+ _ = ctx .Req .ParseForm ()
241
+ configKeys := ctx .Req .Form ["key" ]
242
+ configValues := ctx .Req .Form ["value" ]
243
+ configSettings := map [string ]string {}
244
+ loop:
245
+ for i , key := range configKeys {
246
+ if i >= len (configValues ) {
247
+ ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
248
+ break loop
249
+ }
250
+ value := configValues [i ]
251
+
252
+ marshaller , hasMarshaller := marshallers [key ]
253
+ if ! hasMarshaller {
254
+ ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
255
+ break loop
256
+ }
257
+
258
+ marshaledValue , err := marshaller (value )
259
+ if err != nil {
260
+ ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
261
+ break loop
262
+ }
263
+ configSettings [key ] = string (marshaledValue )
242
264
}
243
- marshaledValue , err := marshaller (value )
244
- if err != nil {
245
- ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
265
+ if ctx .Written () {
246
266
return
247
267
}
248
- if err = system_model .SetSettings (ctx , map [ string ] string { key : marshaledValue } ); err != nil {
249
- ctx .JSONError ( ctx . Tr ( "admin.config.set_setting_failed " , key ) )
268
+ if err : = system_model .SetSettings (ctx , configSettings ); err != nil {
269
+ ctx .ServerError ( "SetSettings " , err )
250
270
return
251
271
}
252
-
253
272
config .GetDynGetter ().InvalidateCache ()
254
273
ctx .JSONOK ()
255
274
}
0 commit comments