mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
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>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package system
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.dev/models/system"
|
|
"gitea.dev/modules/json"
|
|
"gitea.dev/modules/util"
|
|
)
|
|
|
|
type DBStore struct{}
|
|
|
|
func (f *DBStore) Get(ctx context.Context, item StateItem) error {
|
|
content, err := system.GetAppStateContent(ctx, item.StateName())
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get app state item %s: %w", item.StateName(), err)
|
|
}
|
|
if content == "" {
|
|
return nil
|
|
}
|
|
err = json.Unmarshal(util.UnsafeStringToBytes(content), item)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to unmarshal app state item %s: %w", item.StateName(), err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (f *DBStore) Set(ctx context.Context, item StateItem) error {
|
|
b, err := json.Marshal(item)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal app state item %s: %w", item.StateName(), err)
|
|
}
|
|
err = system.SaveAppStateContent(ctx, item.StateName(), util.UnsafeBytesToString(b))
|
|
if err != nil {
|
|
return fmt.Errorf("failed to save app state item %s: %w", item.StateName(), err)
|
|
}
|
|
return nil
|
|
}
|