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