diff --git a/models/repo_issue.go b/models/repo_issue.go index 10356d2c9..946c6b06f 100644 --- a/models/repo_issue.go +++ b/models/repo_issue.go @@ -32,3 +32,21 @@ func (repo *Repository) AllowOnlyContributorsToTrackTime() bool { } return u.IssuesConfig().AllowOnlyContributorsToTrackTime } + +/* +________ .___ .__ +\______ \ ____ ______ ____ ____ __| _/____ ____ ____ |__| ____ ______ + | | \_/ __ \\____ \_/ __ \ / \ / __ |/ __ \ / \_/ ___\| |/ __ \ / ___/ + | ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \ +/_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ > + \/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/ + */ + +func (repo *Repository) IsDependenciesEnabled() bool { + var u *RepoUnit + var err error + if u, err = repo.GetUnit(UnitTypeIssues); err != nil { + return setting.Service.DefaultEnableDependencies + } + return u.IssuesConfig().EnableDependencies +} diff --git a/models/repo_unit.go b/models/repo_unit.go index 6ac61968b..cec0fc6b2 100644 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -73,6 +73,7 @@ func (cfg *ExternalTrackerConfig) ToDB() ([]byte, error) { type IssuesConfig struct { EnableTimetracker bool AllowOnlyContributorsToTrackTime bool + EnableDependencies bool } // FromDB fills up a IssuesConfig from serialized format. diff --git a/modules/context/repo.go b/modules/context/repo.go index 4a48cdfd5..7c8749cc0 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -103,6 +103,14 @@ func (r *Repository) CanUseTimetracker(issue *models.Issue, user *models.User) b r.IsWriter() || issue.IsPoster(user.ID) || issue.AssigneeID == user.ID) } +// CanUseDependencies returns whether or not a user can create dependencies. +func (r *Repository) CanUseDependencies(issue *models.Issue, user *models.User) bool { + // Checking for following: + // 1. Is dependencies enabled + // 2. Has the user write access? + return r.Repository.IsDependenciesEnabled() && r.IsWriter() +} + // GetCommitsCount returns cached commit count for current view func (r *Repository) GetCommitsCount() (int64, error) { var contextName string diff --git a/modules/setting/setting.go b/modules/setting/setting.go index d4f92dee3..7ebae297c 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1138,6 +1138,7 @@ var Service struct { DefaultKeepEmailPrivate bool DefaultAllowCreateOrganization bool DefaultEnableTimetracking bool + DefaultEnableDependencies bool DefaultAllowOnlyContributorsToTrackTime bool NoReplyAddress string @@ -1161,6 +1162,7 @@ func newService() { Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool() Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true) Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").MustBool(true) + Service.DefaultEnableDependencies = sec.Key("DEFAULT_ENABLE_DEPENDENCIES").MustBool(true) Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true) Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") diff --git a/routers/repo/issue.go b/routers/repo/issue.go index e8940f55a..5a14b53de 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -624,6 +624,9 @@ func ViewIssue(ctx *context.Context) { } } + // Check if the user can use the dependencies + ctx.Data["CanUseDependencies"] = ctx.Repo.CanUseDependencies(issue, ctx.User) + // Render comments and and fetch participants. participants[0] = issue.Poster for _, comment = range issue.Comments { diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 7ef9c95e0..5eca9ac6c 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -152,11 +152,11 @@ - -
-
- - +
+
+ + +