diff options
author | Jason Song <i@wolfogre.com> | 2023-01-17 23:00:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-17 17:00:19 +0200 |
commit | 21c91b7dff29107eeadfeec9ed6305fd43fa49b4 (patch) | |
tree | faebdb46400280cefc02798b1b9db1e4ed59ed01 /routers | |
parent | e763fab6851c278150a02c983e739a37e17ce988 (diff) | |
download | gitea-21c91b7dff29107eeadfeec9ed6305fd43fa49b4.tar.gz gitea-21c91b7dff29107eeadfeec9ed6305fd43fa49b4.zip |
Set disable_gravatar/enable_federated_avatar when offline mode is true (#22479)
When offline mode is true, we should set `disable_gravatar` to `true`
and `enable_federated_avatar` to `false` in system settings.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/admin/config.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index eaa02588ca..1f71e81785 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -5,9 +5,11 @@ package admin import ( + "fmt" "net/http" "net/url" "os" + "strconv" "strings" system_model "code.gitea.io/gitea/models/system" @@ -201,6 +203,16 @@ func ChangeConfig(ctx *context.Context) { value := ctx.FormString("value") version := ctx.FormInt("version") + if check, ok := changeConfigChecks[key]; ok { + if err := check(ctx, value); err != nil { + log.Warn("refused to set setting: %v", err) + ctx.JSON(http.StatusOK, map[string]string{ + "err": ctx.Tr("admin.config.set_setting_failed", key), + }) + return + } + } + if err := system_model.SetSetting(&system_model.Setting{ SettingKey: key, SettingValue: value, @@ -217,3 +229,18 @@ func ChangeConfig(ctx *context.Context) { "version": version + 1, }) } + +var changeConfigChecks = map[string]func(ctx *context.Context, newValue string) error{ + system_model.KeyPictureDisableGravatar: func(_ *context.Context, newValue string) error { + if v, _ := strconv.ParseBool(newValue); setting.OfflineMode && !v { + return fmt.Errorf("%q should be true when OFFLINE_MODE is true", system_model.KeyPictureDisableGravatar) + } + return nil + }, + system_model.KeyPictureEnableFederatedAvatar: func(_ *context.Context, newValue string) error { + if v, _ := strconv.ParseBool(newValue); setting.OfflineMode && v { + return fmt.Errorf("%q cannot be false when OFFLINE_MODE is true", system_model.KeyPictureEnableFederatedAvatar) + } + return nil + }, +} |