mirror of
https://github.com/go-gitea/gitea
synced 2024-12-21 02:24:18 +01:00
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.
This commit is contained in:
parent
e763fab685
commit
21c91b7dff
2 changed files with 37 additions and 0 deletions
|
@ -268,6 +268,16 @@ func Init() error {
|
||||||
if setting_module.OfflineMode {
|
if setting_module.OfflineMode {
|
||||||
disableGravatar = true
|
disableGravatar = true
|
||||||
enableFederatedAvatar = false
|
enableFederatedAvatar = false
|
||||||
|
if !GetSettingBool(KeyPictureDisableGravatar) {
|
||||||
|
if err := SetSettingNoVersion(KeyPictureDisableGravatar, "true"); err != nil {
|
||||||
|
return fmt.Errorf("Failed to set setting %q: %w", KeyPictureDisableGravatar, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if GetSettingBool(KeyPictureEnableFederatedAvatar) {
|
||||||
|
if err := SetSettingNoVersion(KeyPictureEnableFederatedAvatar, "false"); err != nil {
|
||||||
|
return fmt.Errorf("Failed to set setting %q: %w", KeyPictureEnableFederatedAvatar, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if enableFederatedAvatar || !disableGravatar {
|
if enableFederatedAvatar || !disableGravatar {
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
system_model "code.gitea.io/gitea/models/system"
|
system_model "code.gitea.io/gitea/models/system"
|
||||||
|
@ -201,6 +203,16 @@ func ChangeConfig(ctx *context.Context) {
|
||||||
value := ctx.FormString("value")
|
value := ctx.FormString("value")
|
||||||
version := ctx.FormInt("version")
|
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{
|
if err := system_model.SetSetting(&system_model.Setting{
|
||||||
SettingKey: key,
|
SettingKey: key,
|
||||||
SettingValue: value,
|
SettingValue: value,
|
||||||
|
@ -217,3 +229,18 @@ func ChangeConfig(ctx *context.Context) {
|
||||||
"version": version + 1,
|
"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
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue