Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,16 @@ LEVEL = Info
;;
;; Default value for KeepEmailPrivate
;; Each new user will get the value of this setting copied into their profile
;; Deprecated: Moved to database based configuration which can be set from UI
;DEFAULT_KEEP_EMAIL_PRIVATE = false
;;
;; Default value for AllowCreateOrganization
;; Every new user will have rights set to create organizations depending on this setting
;; Deprecated: Moved to database based configuration which can be set from UI
;DEFAULT_ALLOW_CREATE_ORGANIZATION = true
;; Default value for IsRestricted
;; Every new user will have restricted permissions depending on this setting
;; Deprecated: Moved to database based configuration which can be set from UI
;DEFAULT_USER_IS_RESTRICTED = false
;;
;; Either "public", "limited" or "private", default is "public"
Expand All @@ -870,13 +873,16 @@ LEVEL = Info
;;
;; Default value for DefaultOrgMemberVisible
;; True will make the membership of the users visible when added to the organisation
;; Deprecated: Moved to database based configuration which can be set from UI
;DEFAULT_ORG_MEMBER_VISIBLE = false
;;
;; Default value for EnableDependencies
;; Repositories will use dependencies by default depending on this setting
;; Deprecated: Moved to database based configuration which can be set from UI
;DEFAULT_ENABLE_DEPENDENCIES = true
;;
;; Dependencies can be added from any repository where the user is granted access or only from the current repository depending on this setting.
;; Deprecated: Moved to database based configuration which can be set from UI
;ALLOW_CROSS_REPOSITORY_DEPENDENCIES = true
;;
;; Default map service. No external API support has been included. A service has to allow
Expand All @@ -889,17 +895,21 @@ LEVEL = Info
; USER_LOCATION_MAP_URL =
;;
;; Enable heatmap on users profiles.
;; Deprecated: Moved to database based configuration which can be set from UI
;ENABLE_USER_HEATMAP = true
;;
;; Enable Timetracking
;; Deprecated: Moved to database based configuration which can be set from UI
;ENABLE_TIMETRACKING = true
;;
;; Default value for EnableTimetracking
;; Repositories will use timetracking by default depending on this setting
;; Deprecated: Moved to database based configuration which can be set from UI
;DEFAULT_ENABLE_TIMETRACKING = true
;;
;; Default value for AllowOnlyContributorsToTrackTime
;; Only users with write permissions can track time if this is true
;; Deprecated: Moved to database based configuration which can be set from UI
;DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME = true
;;
;; Value for the domain part of the user's email address in the git log if user
Expand All @@ -918,10 +928,12 @@ LEVEL = Info
;; Default value for AutoWatchNewRepos
;; When adding a repo to a team or creating a new repo all team members will watch the
;; repo automatically if enabled
;; Deprecated: Moved to database based configuration which can be set from UI
;AUTO_WATCH_NEW_REPOS = true
;;
;; Default value for AutoWatchOnChanges
;; Make the user watch a repository When they commit for the first time
;; Deprecated: Moved to database based configuration which can be set from UI
;AUTO_WATCH_ON_CHANGES = false
;;
;; Minimum amount of time a user must exist before comments are kept when the user is deleted.
Expand Down
8 changes: 7 additions & 1 deletion models/issues/issue_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"testing"

issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/system"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting/config"

"github.com/stretchr/testify/assert"
)
Expand All @@ -32,7 +34,11 @@ func TestIssueList_LoadRepositories(t *testing.T) {

func TestIssueList_LoadAttributes(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
setting.Service.EnableTimetracking = true
system.SetSettings(t.Context(), map[string]string{
setting.Config().Service.EnableTimeTracking.DynKey(): "true",
})
config.GetDynGetter().InvalidateCache()

issueList := issues_model.IssueList{
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}),
Expand Down
7 changes: 6 additions & 1 deletion models/issues/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/system"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting/config"

"github.com/stretchr/testify/assert"
"xorm.io/builder"
Expand Down Expand Up @@ -384,7 +386,10 @@ func TestCountIssues(t *testing.T) {

func TestIssueLoadAttributes(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
setting.Service.EnableTimetracking = true
system.SetSettings(t.Context(), map[string]string{
setting.Config().Service.EnableTimeTracking.DynKey(): "true",
})
config.GetDynGetter().InvalidateCache()

issueList := issues_model.IssueList{
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
Expand Down
3 changes: 2 additions & 1 deletion models/migrations/v1_6/v70.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package v1_6

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -99,7 +100,7 @@ func AddIssueDependencies(x *xorm.Engine) (err error) {
unit.Config = make(map[string]any)
}
if _, ok := unit.Config["EnableDependencies"]; !ok {
unit.Config["EnableDependencies"] = setting.Service.DefaultEnableDependencies
unit.Config["EnableDependencies"] = setting.Config().Service.DefaultEnableDependencies.Value(context.Background())
}
if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions models/organization/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func CreateOrganization(ctx context.Context, org *Organization, owner *user_mode
if err = db.Insert(ctx, &OrgUser{
UID: owner.ID,
OrgID: org.ID,
IsPublic: setting.Service.DefaultOrgMemberVisible,
IsPublic: setting.Config().Service.DefaultOrgMemberVisible.Value(ctx),
}); err != nil {
return fmt.Errorf("insert org-user relation: %w", err)
}
Expand Down Expand Up @@ -504,7 +504,7 @@ func AddOrgUser(ctx context.Context, orgID, uid int64) error {
ou := &OrgUser{
UID: uid,
OrgID: orgID,
IsPublic: setting.Service.DefaultOrgMemberVisible,
IsPublic: setting.Config().Service.DefaultOrgMemberVisible.Value(ctx),
}

if err := db.Insert(ctx, ou); err != nil {
Expand Down
13 changes: 11 additions & 2 deletions models/organization/org_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"testing"

"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/system"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting/config"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -141,12 +143,19 @@ func TestAddOrgUser(t *testing.T) {
assert.Equal(t, expectedNumMembers, org.NumMembers)
}

setting.Service.DefaultOrgMemberVisible = false
system.SetSettings(t.Context(), map[string]string{
setting.Config().Service.DefaultOrgMemberVisible.DynKey(): "false",
})
config.GetDynGetter().InvalidateCache()

testSuccess(3, 5, false)
testSuccess(3, 5, false)
testSuccess(6, 2, false)

setting.Service.DefaultOrgMemberVisible = true
system.SetSettings(t.Context(), map[string]string{
setting.Config().Service.DefaultOrgMemberVisible.DynKey(): "true",
})
config.GetDynGetter().InvalidateCache()
testSuccess(6, 3, true)

unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
Expand Down
19 changes: 6 additions & 13 deletions models/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,22 @@ import (
"code.gitea.io/gitea/modules/setting"
)

// ___________.__ ___________ __
// \__ ___/|__| _____ ___\__ ___/___________ ____ | | __ ___________
// | | | |/ \_/ __ \| | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
// | | | | Y Y \ ___/| | | | \// __ \\ \___| <\ ___/| | \/
// |____| |__|__|_| /\___ >____| |__| (____ /\___ >__|_ \\___ >__|
// \/ \/ \/ \/ \/ \/

// CanEnableTimetracker returns true when the server admin enabled time tracking
// This overrules IsTimetrackerEnabled
func (repo *Repository) CanEnableTimetracker() bool {
return setting.Service.EnableTimetracking
func (repo *Repository) CanEnableTimetracker(ctx context.Context) bool {
return setting.Config().Service.EnableTimeTracking.Value(ctx)
}

// IsTimetrackerEnabled returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
func (repo *Repository) IsTimetrackerEnabled(ctx context.Context) bool {
if !setting.Service.EnableTimetracking {
if !setting.Config().Service.EnableTimeTracking.Value(ctx) {
return false
}

var u *RepoUnit
var err error
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
return setting.Service.DefaultEnableTimetracking
return setting.Config().Service.DefaultEnableTimeTracking.Value(ctx)
}
return u.IssuesConfig().EnableTimetracker
}
Expand All @@ -43,7 +36,7 @@ func (repo *Repository) AllowOnlyContributorsToTrackTime(ctx context.Context) bo
var u *RepoUnit
var err error
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
return setting.Service.DefaultAllowOnlyContributorsToTrackTime
return setting.Config().Service.DefaultAllowOnlyContributorsToTrackTime.Value(ctx)
}
return u.IssuesConfig().AllowOnlyContributorsToTrackTime
}
Expand All @@ -54,7 +47,7 @@ func (repo *Repository) IsDependenciesEnabled(ctx context.Context) bool {
var err error
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
log.Trace("IsDependenciesEnabled: %v", err)
return setting.Service.DefaultEnableDependencies
return setting.Config().Service.DefaultEnableDependencies.Value(ctx)
}
return u.IssuesConfig().EnableDependencies
}
2 changes: 1 addition & 1 deletion models/repo/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func GetRepoWatchers(ctx context.Context, repoID int64, opts db.ListOptions) ([]

// WatchIfAuto subscribes to repo if AutoWatchOnChanges is set
func WatchIfAuto(ctx context.Context, userID, repoID int64, isWrite bool) error {
if !isWrite || !setting.Service.AutoWatchOnChanges {
if !isWrite || !setting.Config().Service.AutoWatchOnChanges.Value(ctx) {
return nil
}
watch, err := GetWatch(ctx, userID, repoID)
Expand Down
12 changes: 10 additions & 2 deletions models/repo/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (

"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/system"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting/config"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -71,7 +73,10 @@ func TestWatchIfAuto(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, watchers, repo.NumWatches)

setting.Service.AutoWatchOnChanges = false
assert.NoError(t, system.SetSettings(t.Context(), map[string]string{
setting.Config().Service.AutoWatchOnChanges.DynKey(): "false",
}))
config.GetDynGetter().InvalidateCache()

prevCount := repo.NumWatches

Expand All @@ -87,7 +92,10 @@ func TestWatchIfAuto(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, watchers, prevCount)

setting.Service.AutoWatchOnChanges = true
assert.NoError(t, system.SetSettings(t.Context(), map[string]string{
setting.Config().Service.AutoWatchOnChanges.DynKey(): "true",
}))
config.GetDynGetter().InvalidateCache()

// Must not add watch
assert.NoError(t, repo_model.WatchIfAuto(t.Context(), 8, 1, true))
Expand Down
6 changes: 3 additions & 3 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,13 @@ func createUser(ctx context.Context, u *User, meta *Meta, createdByAdmin bool, o
}

// set system defaults
u.KeepEmailPrivate = setting.Service.DefaultKeepEmailPrivate
u.KeepEmailPrivate = setting.Config().Service.DefaultKeepEmailPrivate.Value(ctx)
u.Visibility = setting.Service.DefaultUserVisibilityMode
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization && !setting.Admin.DisableRegularOrgCreation
u.AllowCreateOrganization = setting.Config().Service.DefaultAllowCreateOrganization.Value(ctx) && !setting.Admin.DisableRegularOrgCreation
u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification
u.MaxRepoCreation = -1
u.Theme = setting.UI.DefaultTheme
u.IsRestricted = setting.Service.DefaultUserIsRestricted
u.IsRestricted = setting.Config().Service.DefaultUserIsRestricted.Value(ctx)
u.IsActive = !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm)

// Ensure consistency of the dates.
Expand Down
2 changes: 1 addition & 1 deletion modules/eventsource/manager_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ loop:
}
then = now

if setting.Service.EnableTimetracking {
if setting.Config().Service.EnableTimeTracking.Value(ctx) {
usersStopwatches, err := issues_model.GetUIDsAndStopwatch(ctx)
if err != nil {
log.Error("Unable to get GetUIDsAndStopwatch: %v", err)
Expand Down
30 changes: 30 additions & 0 deletions modules/setting/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,25 @@ type RepositoryStruct struct {
GitGuideRemoteName *config.Value[string]
}

type ServiceStruct struct {
DefaultKeepEmailPrivate *config.Value[bool]
DefaultAllowCreateOrganization *config.Value[bool]
DefaultUserIsRestricted *config.Value[bool]
EnableTimeTracking *config.Value[bool]
DefaultEnableTimeTracking *config.Value[bool]
DefaultEnableDependencies *config.Value[bool]
AllowCrossRepositoryDependencies *config.Value[bool]
DefaultAllowOnlyContributorsToTrackTime *config.Value[bool]
EnableUserHeatmap *config.Value[bool]
AutoWatchNewRepos *config.Value[bool]
AutoWatchOnChanges *config.Value[bool]
DefaultOrgMemberVisible *config.Value[bool]
}

type ConfigStruct struct {
Picture *PictureStruct
Repository *RepositoryStruct
Service *ServiceStruct
}

var (
Expand All @@ -73,6 +89,20 @@ func initDefaultConfig() {
OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"),
GitGuideRemoteName: config.ValueJSON[string]("repository.git-guide-remote-name").WithDefault("origin"),
},
Service: &ServiceStruct{
DefaultKeepEmailPrivate: config.ValueJSON[bool]("service.default_keep_email_private").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "DEFAULT_KEEP_EMAIL_PRIVATE"}).WithDefault(false),
DefaultAllowCreateOrganization: config.ValueJSON[bool]("service.default_allow_create_organization").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "DEFAULT_ALLOW_CREATE_ORGANIZATION"}).WithDefault(true),
DefaultUserIsRestricted: config.ValueJSON[bool]("service.default_user_is_restricted").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "DEFAULT_USER_IS_RESTRICTED"}).WithDefault(false),
EnableTimeTracking: config.ValueJSON[bool]("service.enable_time_tracking").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "ENABLE_TIMETRACKING"}).WithDefault(true),
DefaultEnableTimeTracking: config.ValueJSON[bool]("service.default_enable_time_tracking").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "DEFAULT_ENABLE_TIMETRACKING"}).WithDefault(true),
DefaultEnableDependencies: config.ValueJSON[bool]("service.default_enable_dependencies").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "DEFAULT_ENABLE_DEPENDENCIES"}).WithDefault(true),
AllowCrossRepositoryDependencies: config.ValueJSON[bool]("service.allow_cross_repository_dependencies").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "ALLOW_CROSS_REPOSITORY_DEPENDENCIES"}).WithDefault(true),
DefaultAllowOnlyContributorsToTrackTime: config.ValueJSON[bool]("service.default_allow_only_contributors_to_track_time").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME"}).WithDefault(true),
EnableUserHeatmap: config.ValueJSON[bool]("service.enable_user_heatmap").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "ENABLE_USER_HEATMAP"}).WithDefault(true),
AutoWatchNewRepos: config.ValueJSON[bool]("service.auto_watch_new_repos").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "AUTO_WATCH_NEW_REPOS"}).WithDefault(true),
AutoWatchOnChanges: config.ValueJSON[bool]("service.auto_watch_on_changes").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "AUTO_WATCH_ON_CHANGES"}).WithDefault(false),
DefaultOrgMemberVisible: config.ValueJSON[bool]("service.default_org_member_visible").WithFileConfig(config.CfgSecKey{Sec: "service", Key: "DEFAULT_ORG_MEMBER_VISIBLE"}).WithDefault(false),
},
}
}

Expand Down
Loading
Loading