@@ -196,17 +196,21 @@ func ConfigSettings(ctx *context.Context) {
196196}
197197
198198func ChangeConfig (ctx * context.Context ) {
199- key := strings .TrimSpace (ctx .FormString ("key" ))
200- value := ctx .FormString ("value" )
201199 cfg := setting .Config ()
202200
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 ))
206209 }
207- return "false" , nil
208210 }
209- marshalOpenWithApps := func (value string ) (string , error ) {
211+
212+ marshalOpenWithApps := func (value string ) ([]byte , error ) {
213+ // TODO: move the block alongside OpenWithEditorAppsType.ToTextareaString
210214 lines := strings .Split (value , "\n " )
211215 var openWithEditorApps setting.OpenWithEditorAppsType
212216 for _ , line := range lines {
@@ -224,32 +228,47 @@ func ChangeConfig(ctx *context.Context) {
224228 OpenURL : strings .TrimSpace (openURL ),
225229 })
226230 }
227- b , err := json .Marshal (openWithEditorApps )
228- if err != nil {
229- return "" , err
230- }
231- return string (b ), nil
231+ return json .Marshal (openWithEditorApps )
232232 }
233- marshallers := map [string ]func (string ) (string , error ){
233+ marshallers := map [string ]func (string ) ([] byte , error ){
234234 cfg .Picture .DisableGravatar .DynKey (): marshalBool ,
235235 cfg .Picture .EnableFederatedAvatar .DynKey (): marshalBool ,
236236 cfg .Repository .OpenWithEditorApps .DynKey (): marshalOpenWithApps ,
237+ cfg .Repository .GitGuideRemoteName .DynKey (): marshalString (cfg .Repository .GitGuideRemoteName .DefaultValue ()),
237238 }
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 )
242264 }
243- marshaledValue , err := marshaller (value )
244- if err != nil {
245- ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
265+ if ctx .Written () {
246266 return
247267 }
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 )
250270 return
251271 }
252-
253272 config .GetDynGetter ().InvalidateCache ()
254273 ctx .JSONOK ()
255274}
0 commit comments