Finished implementing setting for dependencies

This commit is contained in:
kolaente 2017-11-28 00:33:51 +01:00 committed by Konrad
parent c81041f80d
commit db4f578e04
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
13 changed files with 62 additions and 38 deletions

View File

@ -291,6 +291,9 @@ DEFAULT_ALLOW_CREATE_ORGANIZATION = true
; Default value for EnableTimetracking
; Repositories will use timetracking by default depending on this setting
DEFAULT_ENABLE_TIMETRACKING = true
; Default value for EnableDependencies
; Repositories will use depencies by default depending on this setting
DEFAULT_ENABLE_DEPENDENCIES = true
; Default value for AllowOnlyContributorsToTrackTime
; Only users with write permissions could track time if this is true
DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME = true

View File

@ -147,7 +147,7 @@ var migrations = []Migration{
// v48 -> v49
NewMigration("add repo indexer status", addRepoIndexerStatus),
// v49 -> v50
NewMigration("add issue_dependency table", addIssueDependencyTables),
NewMigration("add issue_dependencies", addIssueDependencies),
}
// Migrate database to current version

View File

@ -7,11 +7,12 @@ package migrations
import (
"fmt"
"code.gitea.io/gitea/modules/setting"
"github.com/go-xorm/xorm"
"time"
)
func addIssueDependencyTables(x *xorm.Engine) (err error) {
func addIssueDependencies(x *xorm.Engine) (err error) {
type IssueDependency struct {
ID int64 `xorm:"pk autoincr"`
@ -28,5 +29,34 @@ func addIssueDependencyTables(x *xorm.Engine) (err error) {
return fmt.Errorf("Error creating issue_dependency_table column definition: %v", err)
}
// RepoUnit describes all units of a repository
type RepoUnit struct {
ID int64
RepoID int64 `xorm:"INDEX(s)"`
Type int `xorm:"INDEX(s)"`
Index int
Config map[string]interface{} `xorm:"JSON"`
CreatedUnix int64 `xorm:"INDEX CREATED"`
Created time.Time `xorm:"-"`
}
//Updating existing issue units
units := make([]*RepoUnit, 0, 100)
err = x.Where("`type` = ?", V16UnitTypeIssues).Find(&units)
if err != nil {
return fmt.Errorf("Query repo units: %v", err)
}
for _, unit := range units {
if unit.Config == nil {
unit.Config = make(map[string]interface{})
}
if _, ok := unit.Config["EnableDependencies"]; !ok {
unit.Config["EnableDependencies"] = setting.Service.DefaultEnableDependencies
}
if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
return err
}
}
return err
}

View File

@ -1306,7 +1306,11 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
units = append(units, RepoUnit{
RepoID: repo.ID,
Type: tp,
Config: &IssuesConfig{EnableTimetracker: setting.Service.DefaultEnableTimetracking, AllowOnlyContributorsToTrackTime: setting.Service.DefaultAllowOnlyContributorsToTrackTime},
Config: &IssuesConfig{
EnableTimetracker: setting.Service.DefaultEnableTimetracking,
AllowOnlyContributorsToTrackTime: setting.Service.DefaultAllowOnlyContributorsToTrackTime,
EnableDependencies: setting.Service.DefaultEnableDependencies,
},
})
} else {
units = append(units, RepoUnit{

View File

@ -40,8 +40,9 @@ ________ .___ .__
| ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \
/_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ >
\/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/
*/
*/
// IsDependenciesEnabled returns if dependecies are enabled and returns the default setting if not set.
func (repo *Repository) IsDependenciesEnabled() bool {
var u *RepoUnit
var err error

View File

@ -73,7 +73,7 @@ func (cfg *ExternalTrackerConfig) ToDB() ([]byte, error) {
type IssuesConfig struct {
EnableTimetracker bool
AllowOnlyContributorsToTrackTime bool
EnableDependencies bool
EnableDependencies bool
}
// FromDB fills up a IssuesConfig from serialized format.
@ -91,7 +91,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
switch colName {
case "type":
switch UnitType(Cell2Int64(val)) {
case UnitTypeCode, UnitTypePullRequests, UnitTypeReleases, UnitTypeIssueDependencies,
case UnitTypeCode, UnitTypePullRequests, UnitTypeReleases,
UnitTypeWiki:
r.Config = new(UnitConfig)
case UnitTypeExternalWiki:
@ -145,12 +145,6 @@ func (r *RepoUnit) IssuesConfig() *IssuesConfig {
func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig {
return r.Config.(*ExternalTrackerConfig)
}
// IssueDependenciesConfig returns config for UnitTypeIssueDependencies
func (r *RepoUnit) IssueDependenciesConfig() *UnitConfig {
return r.Config.(*UnitConfig)
}
func getUnitsByRepoID(e Engine, repoID int64) (units []*RepoUnit, err error) {
return units, e.Where("repo_id = ?", repoID).Find(&units)
}

View File

@ -16,7 +16,6 @@ const (
UnitTypeWiki // 5 Wiki
UnitTypeExternalWiki // 6 ExternalWiki
UnitTypeExternalTracker // 7 ExternalTracker
UnitTypeIssueDependencies // 8 Issue Dependencies
)
var (
@ -29,7 +28,6 @@ var (
UnitTypeWiki,
UnitTypeExternalWiki,
UnitTypeExternalTracker,
UnitTypeIssueDependencies,
}
// defaultRepoUnits contains the default unit types
@ -128,14 +126,6 @@ var (
4,
}
UnitIssueDependencies = Unit{
UnitTypeIssueDependencies,
"repo.issue_dependency",
"/issues",
"repo.issue_dependency.desc",
5,
}
// Units contains all the units
Units = map[UnitType]Unit{
UnitTypeCode: UnitCode,
@ -145,6 +135,5 @@ var (
UnitTypeReleases: UnitReleases,
UnitTypeWiki: UnitWiki,
UnitTypeExternalWiki: UnitExternalWiki,
UnitTypeIssueDependencies: UnitIssueDependencies,
}
)

View File

@ -724,6 +724,5 @@ func UnitTypes() macaron.Handler {
ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki
ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki
ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker
ctx.Data["UnitTypeIssueDependencies"] = models.UnitTypeIssueDependencies
}
}

View File

@ -717,7 +717,6 @@ func ViewIssue(ctx *context.Context) {
}
// Get Dependencies
ctx.Data["IssueDependenciesEnabled"] = repo.UnitEnabled(models.UnitTypeIssueDependencies)
ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies()
ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies()

View File

@ -30,7 +30,7 @@ func AddDependency(c *context.Context) {
}
// Check if the Repo is allowed to have dependencies
if !c.Repo.Repository.UnitEnabled(models.UnitTypeIssueDependencies) {
if !c.Repo.CanUseDependencies(issue, c.User) {
c.Handle(404, "MustEnableIssueDependencies", nil)
return
}

View File

@ -28,6 +28,12 @@ func RemoveDependency(c *context.Context) {
return
}
// Check if the Repo is allowed to have dependencies
if !c.Repo.CanUseDependencies(issue, c.User) {
c.Handle(404, "MustEnableIssueDependencies", nil)
return
}
// Dependency Type
depTypeStr := c.Req.PostForm.Get("dependencyType")

View File

@ -200,6 +200,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
Config: &models.IssuesConfig{
EnableTimetracker: form.EnableTimetracker,
AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime,
EnableDependencies: form.EnableIssueDependencies,
},
})
}
@ -213,14 +214,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
})
}
if form.EnableIssueDependencies {
units = append(units, models.RepoUnit{
RepoID: repo.ID,
Type: models.UnitTypeIssueDependencies,
Config: new(models.UnitConfig),
})
}
if err := models.UpdateRepositoryUnits(repo, units); err != nil {
ctx.Handle(500, "UpdateRepositoryUnits", err)
return

View File

@ -191,8 +191,7 @@
{{end}}
{{end}}
{{if .IsSigned}}
{{if .IssueDependenciesEnabled}}
{{if .Repository.IsDependenciesEnabled}}
<div class="ui divider"></div>
<div class="ui depending">
@ -210,9 +209,11 @@
{{range .BlockedByDependencies}}
<div class="item">
<div class="right floated content">
{{if $.CanUseDependencies}}
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blockedBy');">
<i class="delete icon text red"></i>
</a>
{{end}}
{{if .IsClosed}}
<div class="ui red mini label">
<i class="octicon octicon-issue-closed"></i>
@ -242,9 +243,11 @@
{{range .BlockingDependencies}}
<div class="item">
<div class="right floated content">
{{if $.CanUseDependencies}}
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blocking');">
<i class="delete icon text red"></i>
</a>
{{end}}
{{if .IsClosed}}
<div class="ui red tiny label">
<i class="octicon octicon-issue-closed"></i>
@ -265,6 +268,8 @@
{{if (and (not .BlockedByDependencies) (not .BlockingDependencies))}}
<p>{{.i18n.Tr "repo.issues.dependency.no_dependencies"}}</p>
{{end}}
{{if .CanUseDependencies}}
<div>
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/dependency/add" id="addDependencyForm">
{{$.CsrfTokenHtml}}
@ -283,10 +288,11 @@
</div>
</form>
</div>
{{end}}
</div>
</div>
</div>
{{if .CanUseDependencies}}
<input type="hidden" id="repolink" value="{{$.RepoLink}}">
<!-- I know, there is probably a better way to do this -->
<input type="hidden" id="issueIndex" value="{{.Issue.Index}}"/>
@ -315,5 +321,5 @@
</div>
</div>
</div>
{{end}}
{{end}}
{{end}}