2017-09-12 14:48:13 +08:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-09-12 14:48:13 +08:00
|
|
|
|
2021-12-10 09:27:50 +08:00
|
|
|
package repo
|
2017-09-12 14:48:13 +08:00
|
|
|
|
2021-11-10 03:57:58 +08:00
|
|
|
import (
|
2021-12-10 09:27:50 +08:00
|
|
|
"context"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-11-10 03:57:58 +08:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2021-12-10 09:27:50 +08:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2021-11-10 03:57:58 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
)
|
2017-09-12 14:48:13 +08:00
|
|
|
|
|
|
|
// ___________.__ ___________ __
|
|
|
|
// \__ ___/|__| _____ ___\__ ___/___________ ____ | | __ ___________
|
|
|
|
// | | | |/ \_/ __ \| | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
|
|
|
|
// | | | | Y Y \ ___/| | | | \// __ \\ \___| <\ ___/| | \/
|
|
|
|
// |____| |__|__|_| /\___ >____| |__| (____ /\___ >__|_ \\___ >__|
|
|
|
|
// \/ \/ \/ \/ \/ \/
|
|
|
|
|
2018-04-09 23:15:32 +08:00
|
|
|
// CanEnableTimetracker returns true when the server admin enabled time tracking
|
|
|
|
// This overrules IsTimetrackerEnabled
|
|
|
|
func (repo *Repository) CanEnableTimetracker() bool {
|
|
|
|
return setting.Service.EnableTimetracking
|
|
|
|
}
|
|
|
|
|
2017-09-12 14:48:13 +08:00
|
|
|
// IsTimetrackerEnabled returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
|
2022-12-03 10:48:26 +08:00
|
|
|
func (repo *Repository) IsTimetrackerEnabled() bool { // Notice: It will be used in template so don't remove directly
|
2021-12-14 06:59:39 +08:00
|
|
|
return repo.IsTimetrackerEnabledCtx(db.DefaultContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsTimetrackerEnabledCtx returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
|
|
|
|
func (repo *Repository) IsTimetrackerEnabledCtx(ctx context.Context) bool {
|
2018-04-09 23:15:32 +08:00
|
|
|
if !setting.Service.EnableTimetracking {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-09-12 14:48:13 +08:00
|
|
|
var u *RepoUnit
|
|
|
|
var err error
|
2021-12-14 06:59:39 +08:00
|
|
|
if u, err = repo.GetUnitCtx(ctx, unit.TypeIssues); err != nil {
|
2017-09-12 14:48:13 +08:00
|
|
|
return setting.Service.DefaultEnableTimetracking
|
|
|
|
}
|
|
|
|
return u.IssuesConfig().EnableTimetracker
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllowOnlyContributorsToTrackTime returns value of IssuesConfig or the default value
|
|
|
|
func (repo *Repository) AllowOnlyContributorsToTrackTime() bool {
|
|
|
|
var u *RepoUnit
|
|
|
|
var err error
|
2021-11-10 03:57:58 +08:00
|
|
|
if u, err = repo.GetUnit(unit.TypeIssues); err != nil {
|
2017-09-12 14:48:13 +08:00
|
|
|
return setting.Service.DefaultAllowOnlyContributorsToTrackTime
|
|
|
|
}
|
|
|
|
return u.IssuesConfig().AllowOnlyContributorsToTrackTime
|
|
|
|
}
|
2021-12-10 09:27:50 +08:00
|
|
|
|
|
|
|
// IsDependenciesEnabled returns if dependencies are enabled and returns the default setting if not set.
|
|
|
|
func (repo *Repository) IsDependenciesEnabled() bool {
|
|
|
|
return repo.IsDependenciesEnabledCtx(db.DefaultContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDependenciesEnabledCtx returns if dependencies are enabled and returns the default setting if not set.
|
|
|
|
func (repo *Repository) IsDependenciesEnabledCtx(ctx context.Context) bool {
|
|
|
|
var u *RepoUnit
|
|
|
|
var err error
|
2021-12-14 06:59:39 +08:00
|
|
|
if u, err = repo.GetUnitCtx(ctx, unit.TypeIssues); err != nil {
|
2021-12-10 09:27:50 +08:00
|
|
|
log.Trace("%s", err)
|
|
|
|
return setting.Service.DefaultEnableDependencies
|
|
|
|
}
|
|
|
|
return u.IssuesConfig().EnableDependencies
|
|
|
|
}
|