6
6
package admin
7
7
8
8
import (
9
+ "fmt"
9
10
"net/http"
10
11
"net/url"
11
12
"os"
13
+ "strconv"
12
14
"strings"
13
15
14
16
system_model "code.gitea.io/gitea/models/system"
@@ -202,6 +204,16 @@ func ChangeConfig(ctx *context.Context) {
202
204
value := ctx .FormString ("value" )
203
205
version := ctx .FormInt ("version" )
204
206
207
+ if check , ok := changeConfigChecks [key ]; ok {
208
+ if err := check (ctx , value ); err != nil {
209
+ log .Warn ("refused to set setting: %v" , err )
210
+ ctx .JSON (http .StatusOK , map [string ]string {
211
+ "err" : ctx .Tr ("admin.config.set_setting_failed" , key ),
212
+ })
213
+ return
214
+ }
215
+ }
216
+
205
217
if err := system_model .SetSetting (& system_model.Setting {
206
218
SettingKey : key ,
207
219
SettingValue : value ,
@@ -218,3 +230,18 @@ func ChangeConfig(ctx *context.Context) {
218
230
"version" : version + 1 ,
219
231
})
220
232
}
233
+
234
+ var changeConfigChecks = map [string ]func (ctx * context.Context , newValue string ) error {
235
+ system_model .KeyPictureDisableGravatar : func (_ * context.Context , newValue string ) error {
236
+ if v , _ := strconv .ParseBool (newValue ); setting .OfflineMode && ! v {
237
+ return fmt .Errorf ("%q should be true when OFFLINE_MODE is true" , system_model .KeyPictureDisableGravatar )
238
+ }
239
+ return nil
240
+ },
241
+ system_model .KeyPictureEnableFederatedAvatar : func (_ * context.Context , newValue string ) error {
242
+ if v , _ := strconv .ParseBool (newValue ); setting .OfflineMode && v {
243
+ return fmt .Errorf ("%q cannot be false when OFFLINE_MODE is true" , system_model .KeyPictureEnableFederatedAvatar )
244
+ }
245
+ return nil
246
+ },
247
+ }
0 commit comments