[PRIVACY] Disable Gravatar by default (#837)
- Resolves #259 - Replaces #716 (thanks @silentcode !) - The main toggle _for now_ (due to the still weird settings migration to the database) is `GetDefaultDisableGravatar`, because it's used `loadPictureFrom` which in turn sets the default value for the install page which in turn is the explicit value that Forgejo will use to decide to enable or disable Gravatar after the install page. - Tests still rely on the fact that gravatar is enabled by default for some tests, so there's a small hack in `MainTest` for that. This is not enabled per-tests as this would otherwise just cause random test failures for when rebasing happens. - Unit tests ensures this value by default stays false. Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/837 (cherry picked from commitc6c7c1aa1e
) (cherry picked from commitf0bc5f63d4
)
This commit is contained in:
parent
39ac8b8fc1
commit
0905ce83ea
4 changed files with 33 additions and 1 deletions
|
@ -132,6 +132,10 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
|
|||
|
||||
setting.IncomingEmail.ReplyToAddress = "incoming+%{token}@localhost"
|
||||
|
||||
if err := system_model.SetSettingNoVersion(db.DefaultContext, system_model.KeyPictureDisableGravatar, "false"); err != nil {
|
||||
fatalTestError("system_model.SetSettingNoVersion: %v\n", err)
|
||||
}
|
||||
|
||||
if err = storage.Init(); err != nil {
|
||||
fatalTestError("storage.Init: %v\n", err)
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func loadAvatarsFrom(rootCfg ConfigProvider) error {
|
|||
}
|
||||
|
||||
func GetDefaultDisableGravatar() bool {
|
||||
return OfflineMode
|
||||
return true
|
||||
}
|
||||
|
||||
func GetDefaultEnableFederatedAvatar(disableGravatar bool) bool {
|
||||
|
|
20
modules/setting/picture_test.go
Normal file
20
modules/setting/picture_test.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2023 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package setting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDisableGravatar(t *testing.T) {
|
||||
assert.True(t, GetDefaultDisableGravatar())
|
||||
|
||||
cfg, err := NewConfigProviderFromData(``)
|
||||
assert.NoError(t, err)
|
||||
loadAvatarsFrom(cfg)
|
||||
|
||||
assert.True(t, DisableGravatar)
|
||||
}
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
system_model "code.gitea.io/gitea/models/system"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -176,6 +177,13 @@ func InitTest(requireGitea bool) {
|
|||
}
|
||||
|
||||
routers.GlobalInitInstalled(graceful.GetManager().HammerContext())
|
||||
|
||||
if err := system_model.SetSettingNoVersion(graceful.GetManager().HammerContext(), system_model.KeyPictureDisableGravatar, "false"); err != nil {
|
||||
log.Fatal("system_model.SetSettingNoVersion: %v", err)
|
||||
}
|
||||
if err := system_model.Init(graceful.GetManager().HammerContext()); err != nil {
|
||||
log.Fatal("system_model.Init: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
|
|
Loading…
Reference in a new issue