2017-09-12 12:18:13 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-09-12 12:18:13 +05:30
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
package repo
|
2017-09-12 12:18:13 +05:30
|
|
|
|
2021-11-10 01:27:58 +05:30
|
|
|
import (
|
2021-12-10 06:57:50 +05:30
|
|
|
"context"
|
|
|
|
|
2021-11-10 01:27:58 +05:30
|
|
|
"code.gitea.io/gitea/models/unit"
|
2021-12-10 06:57:50 +05:30
|
|
|
"code.gitea.io/gitea/modules/log"
|
2021-11-10 01:27:58 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
)
|
2017-09-12 12:18:13 +05:30
|
|
|
|
|
|
|
// ___________.__ ___________ __
|
|
|
|
// \__ ___/|__| _____ ___\__ ___/___________ ____ | | __ ___________
|
|
|
|
// | | | |/ \_/ __ \| | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
|
|
|
|
// | | | | Y Y \ ___/| | | | \// __ \\ \___| <\ ___/| | \/
|
|
|
|
// |____| |__|__|_| /\___ >____| |__| (____ /\___ >__|_ \\___ >__|
|
|
|
|
// \/ \/ \/ \/ \/ \/
|
|
|
|
|
2018-04-09 20:45:32 +05:30
|
|
|
// 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 12:18:13 +05:30
|
|
|
// IsTimetrackerEnabled returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
|
2022-12-10 08:16:31 +05:30
|
|
|
func (repo *Repository) IsTimetrackerEnabled(ctx context.Context) bool {
|
2018-04-09 20:45:32 +05:30
|
|
|
if !setting.Service.EnableTimetracking {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-09-12 12:18:13 +05:30
|
|
|
var u *RepoUnit
|
|
|
|
var err error
|
2022-12-10 08:16:31 +05:30
|
|
|
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
|
2017-09-12 12:18:13 +05:30
|
|
|
return setting.Service.DefaultEnableTimetracking
|
|
|
|
}
|
|
|
|
return u.IssuesConfig().EnableTimetracker
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllowOnlyContributorsToTrackTime returns value of IssuesConfig or the default value
|
2022-12-10 08:16:31 +05:30
|
|
|
func (repo *Repository) AllowOnlyContributorsToTrackTime(ctx context.Context) bool {
|
2017-09-12 12:18:13 +05:30
|
|
|
var u *RepoUnit
|
|
|
|
var err error
|
2022-12-10 08:16:31 +05:30
|
|
|
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
|
2017-09-12 12:18:13 +05:30
|
|
|
return setting.Service.DefaultAllowOnlyContributorsToTrackTime
|
|
|
|
}
|
|
|
|
return u.IssuesConfig().AllowOnlyContributorsToTrackTime
|
|
|
|
}
|
2021-12-10 06:57:50 +05:30
|
|
|
|
|
|
|
// IsDependenciesEnabled returns if dependencies are enabled and returns the default setting if not set.
|
2022-12-10 08:16:31 +05:30
|
|
|
func (repo *Repository) IsDependenciesEnabled(ctx context.Context) bool {
|
2021-12-10 06:57:50 +05:30
|
|
|
var u *RepoUnit
|
|
|
|
var err error
|
2022-12-10 08:16:31 +05:30
|
|
|
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
|
2024-04-07 16:47:06 +05:30
|
|
|
log.Trace("IsDependenciesEnabled: %v", err)
|
2021-12-10 06:57:50 +05:30
|
|
|
return setting.Service.DefaultEnableDependencies
|
|
|
|
}
|
|
|
|
return u.IssuesConfig().EnableDependencies
|
|
|
|
}
|