Files
gitea/modules/system/appstate_test.go
T
1f614953a2 enhance: allow admins to force user activity visibility (#40002)
Adds `[service] FORCE_USER_ACTIVITY_VISIBILITY` so admins can force the
activity of all users to be `public` or `private`, e.g. for company
instances that require public activity.

- When the value changes, the next start overwrites the "Hide Activity"
setting of all users. New users get the forced value too.
- The "Hide Activity" checkbox is disabled with an explanatory tooltip
while forced, and `PATCH /api/v1/user/settings` rejects a conflicting
`hide_activity` with 422.

| Before | After |
| --- | --- |
| <img width="122" height="17" alt="before"
src="https://github.com/user-attachments/assets/d138acec-5d40-4a0a-881c-0097e5197a8f"
/> | <img width="258" height="46" alt="after"
src="https://github.com/user-attachments/assets/7e8f7d1b-3303-4473-8d3b-aa35ef8fb20d"
/> |

Fixes: https://github.com/go-gitea/gitea/issues/37961

Assisted-by: Claude Code:claude-opus-5-5

---------

Co-authored-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-11-13 17:32:29 +00:00

63 lines
1.2 KiB
Go

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package system
import (
"testing"
"gitea.dev/models/unittest"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{FixtureFiles: []string{ /* load nothing */ }})
}
type testItem1 struct {
Val1 string
Val2 int
}
func (*testItem1) StateName() string {
return "test-item1"
}
type testItem2 struct {
K string
}
func (*testItem2) StateName() string {
return "test-item2"
}
func TestAppStateDB(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
as := &DBStore{}
item1 := new(testItem1)
assert.NoError(t, as.Get(t.Context(), item1))
assert.Empty(t, item1.Val1)
assert.Equal(t, 0, item1.Val2)
item1 = new(testItem1)
item1.Val1 = "a"
item1.Val2 = 2
assert.NoError(t, as.Set(t.Context(), item1))
item2 := new(testItem2)
item2.K = "V"
assert.NoError(t, as.Set(t.Context(), item2))
item1 = new(testItem1)
assert.NoError(t, as.Get(t.Context(), item1))
assert.Equal(t, "a", item1.Val1)
assert.Equal(t, 2, item1.Val2)
item2 = new(testItem2)
assert.NoError(t, as.Get(t.Context(), item2))
assert.Equal(t, "V", item2.K)
}