55package admin
66
77import (
8+ "fmt"
89 "net/http"
910 "net/url"
1011 "os"
12+ "strconv"
1113 "strings"
1214
1315 system_model "code.gitea.io/gitea/models/system"
@@ -201,6 +203,16 @@ func ChangeConfig(ctx *context.Context) {
201203 value := ctx .FormString ("value" )
202204 version := ctx .FormInt ("version" )
203205
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+
204216 if err := system_model .SetSetting (& system_model.Setting {
205217 SettingKey : key ,
206218 SettingValue : value ,
@@ -217,3 +229,18 @@ func ChangeConfig(ctx *context.Context) {
217229 "version" : version + 1 ,
218230 })
219231}
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