Started implementing settign for dependencies

This commit is contained in:
kolaente 2017-11-27 22:36:26 +01:00 committed by Konrad
parent fc35252f68
commit 33c5033c8b
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
6 changed files with 37 additions and 5 deletions

View File

@ -32,3 +32,21 @@ func (repo *Repository) AllowOnlyContributorsToTrackTime() bool {
} }
return u.IssuesConfig().AllowOnlyContributorsToTrackTime 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
}

View File

@ -73,6 +73,7 @@ func (cfg *ExternalTrackerConfig) ToDB() ([]byte, error) {
type IssuesConfig struct { type IssuesConfig struct {
EnableTimetracker bool EnableTimetracker bool
AllowOnlyContributorsToTrackTime bool AllowOnlyContributorsToTrackTime bool
EnableDependencies bool
} }
// FromDB fills up a IssuesConfig from serialized format. // FromDB fills up a IssuesConfig from serialized format.

View File

@ -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) 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 // GetCommitsCount returns cached commit count for current view
func (r *Repository) GetCommitsCount() (int64, error) { func (r *Repository) GetCommitsCount() (int64, error) {
var contextName string var contextName string

View File

@ -1138,6 +1138,7 @@ var Service struct {
DefaultKeepEmailPrivate bool DefaultKeepEmailPrivate bool
DefaultAllowCreateOrganization bool DefaultAllowCreateOrganization bool
DefaultEnableTimetracking bool DefaultEnableTimetracking bool
DefaultEnableDependencies bool
DefaultAllowOnlyContributorsToTrackTime bool DefaultAllowOnlyContributorsToTrackTime bool
NoReplyAddress string NoReplyAddress string
@ -1161,6 +1162,7 @@ func newService() {
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool() Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true) Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").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.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true)
Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")

View File

@ -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. // Render comments and and fetch participants.
participants[0] = issue.Poster participants[0] = issue.Poster
for _, comment = range issue.Comments { for _, comment = range issue.Comments {

View File

@ -152,13 +152,13 @@
<label>{{.i18n.Tr "repo.settings.allow_only_contributors_to_track_time"}}</label> <label>{{.i18n.Tr "repo.settings.allow_only_contributors_to_track_time"}}</label>
</div> </div>
</div> </div>
</div>
<div class="field"> <div class="field">
<div class="ui checkbox"> <div class="ui checkbox">
<input name="enable_issue_dependencies" type="checkbox" {{if (.Repository.UnitEnabled $.UnitTypeIssueDependencies)}}checked{{end}}> <input name="enable_issue_dependencies" type="checkbox" {{if (.Repository.IsDependenciesEnabled)}}checked{{end}}>
<label>{{.i18n.Tr "repo.issues.dependency.setting"}}</label> <label>{{.i18n.Tr "repo.issues.dependency.setting"}}</label>
</div> </div>
</div> </div>
</div>
<div class="field"> <div class="field">
<div class="ui radio checkbox"> <div class="ui radio checkbox">
<input class="hidden enable-system-radio" tabindex="0" name="enable_external_tracker" type="radio" value="true" data-context="#internal_issue_box" data-target="#external_issue_box" {{if .Repository.UnitEnabled $.UnitTypeExternalTracker}}checked{{end}}/> <input class="hidden enable-system-radio" tabindex="0" name="enable_external_tracker" type="radio" value="true" data-context="#internal_issue_box" data-target="#external_issue_box" {{if .Repository.UnitEnabled $.UnitTypeExternalTracker}}checked{{end}}/>