Finished implementing setting for dependencies
This commit is contained in:
parent
c81041f80d
commit
db4f578e04
|
|
@ -291,6 +291,9 @@ DEFAULT_ALLOW_CREATE_ORGANIZATION = true
|
||||||
; Default value for EnableTimetracking
|
; Default value for EnableTimetracking
|
||||||
; Repositories will use timetracking by default depending on this setting
|
; Repositories will use timetracking by default depending on this setting
|
||||||
DEFAULT_ENABLE_TIMETRACKING = true
|
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
|
; Default value for AllowOnlyContributorsToTrackTime
|
||||||
; Only users with write permissions could track time if this is true
|
; Only users with write permissions could track time if this is true
|
||||||
DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME = true
|
DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME = true
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ var migrations = []Migration{
|
||||||
// v48 -> v49
|
// v48 -> v49
|
||||||
NewMigration("add repo indexer status", addRepoIndexerStatus),
|
NewMigration("add repo indexer status", addRepoIndexerStatus),
|
||||||
// v49 -> v50
|
// v49 -> v50
|
||||||
NewMigration("add issue_dependency table", addIssueDependencyTables),
|
NewMigration("add issue_dependencies", addIssueDependencies),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate database to current version
|
// Migrate database to current version
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ package migrations
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addIssueDependencyTables(x *xorm.Engine) (err error) {
|
func addIssueDependencies(x *xorm.Engine) (err error) {
|
||||||
|
|
||||||
type IssueDependency struct {
|
type IssueDependency struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
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)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1306,7 +1306,11 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
|
||||||
units = append(units, RepoUnit{
|
units = append(units, RepoUnit{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Type: tp,
|
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 {
|
} else {
|
||||||
units = append(units, RepoUnit{
|
units = append(units, RepoUnit{
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,9 @@ ________ .___ .__
|
||||||
| ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \
|
| ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \
|
||||||
/_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ >
|
/_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ >
|
||||||
\/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/
|
\/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// IsDependenciesEnabled returns if dependecies are enabled and returns the default setting if not set.
|
||||||
func (repo *Repository) IsDependenciesEnabled() bool {
|
func (repo *Repository) IsDependenciesEnabled() bool {
|
||||||
var u *RepoUnit
|
var u *RepoUnit
|
||||||
var err error
|
var err error
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ func (cfg *ExternalTrackerConfig) ToDB() ([]byte, error) {
|
||||||
type IssuesConfig struct {
|
type IssuesConfig struct {
|
||||||
EnableTimetracker bool
|
EnableTimetracker bool
|
||||||
AllowOnlyContributorsToTrackTime bool
|
AllowOnlyContributorsToTrackTime bool
|
||||||
EnableDependencies bool
|
EnableDependencies bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromDB fills up a IssuesConfig from serialized format.
|
// FromDB fills up a IssuesConfig from serialized format.
|
||||||
|
|
@ -91,7 +91,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
|
||||||
switch colName {
|
switch colName {
|
||||||
case "type":
|
case "type":
|
||||||
switch UnitType(Cell2Int64(val)) {
|
switch UnitType(Cell2Int64(val)) {
|
||||||
case UnitTypeCode, UnitTypePullRequests, UnitTypeReleases, UnitTypeIssueDependencies,
|
case UnitTypeCode, UnitTypePullRequests, UnitTypeReleases,
|
||||||
UnitTypeWiki:
|
UnitTypeWiki:
|
||||||
r.Config = new(UnitConfig)
|
r.Config = new(UnitConfig)
|
||||||
case UnitTypeExternalWiki:
|
case UnitTypeExternalWiki:
|
||||||
|
|
@ -145,12 +145,6 @@ func (r *RepoUnit) IssuesConfig() *IssuesConfig {
|
||||||
func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig {
|
func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig {
|
||||||
return r.Config.(*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) {
|
func getUnitsByRepoID(e Engine, repoID int64) (units []*RepoUnit, err error) {
|
||||||
return units, e.Where("repo_id = ?", repoID).Find(&units)
|
return units, e.Where("repo_id = ?", repoID).Find(&units)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ const (
|
||||||
UnitTypeWiki // 5 Wiki
|
UnitTypeWiki // 5 Wiki
|
||||||
UnitTypeExternalWiki // 6 ExternalWiki
|
UnitTypeExternalWiki // 6 ExternalWiki
|
||||||
UnitTypeExternalTracker // 7 ExternalTracker
|
UnitTypeExternalTracker // 7 ExternalTracker
|
||||||
UnitTypeIssueDependencies // 8 Issue Dependencies
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -29,7 +28,6 @@ var (
|
||||||
UnitTypeWiki,
|
UnitTypeWiki,
|
||||||
UnitTypeExternalWiki,
|
UnitTypeExternalWiki,
|
||||||
UnitTypeExternalTracker,
|
UnitTypeExternalTracker,
|
||||||
UnitTypeIssueDependencies,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaultRepoUnits contains the default unit types
|
// defaultRepoUnits contains the default unit types
|
||||||
|
|
@ -128,14 +126,6 @@ var (
|
||||||
4,
|
4,
|
||||||
}
|
}
|
||||||
|
|
||||||
UnitIssueDependencies = Unit{
|
|
||||||
UnitTypeIssueDependencies,
|
|
||||||
"repo.issue_dependency",
|
|
||||||
"/issues",
|
|
||||||
"repo.issue_dependency.desc",
|
|
||||||
5,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Units contains all the units
|
// Units contains all the units
|
||||||
Units = map[UnitType]Unit{
|
Units = map[UnitType]Unit{
|
||||||
UnitTypeCode: UnitCode,
|
UnitTypeCode: UnitCode,
|
||||||
|
|
@ -145,6 +135,5 @@ var (
|
||||||
UnitTypeReleases: UnitReleases,
|
UnitTypeReleases: UnitReleases,
|
||||||
UnitTypeWiki: UnitWiki,
|
UnitTypeWiki: UnitWiki,
|
||||||
UnitTypeExternalWiki: UnitExternalWiki,
|
UnitTypeExternalWiki: UnitExternalWiki,
|
||||||
UnitTypeIssueDependencies: UnitIssueDependencies,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -724,6 +724,5 @@ func UnitTypes() macaron.Handler {
|
||||||
ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki
|
ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki
|
||||||
ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki
|
ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki
|
||||||
ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker
|
ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker
|
||||||
ctx.Data["UnitTypeIssueDependencies"] = models.UnitTypeIssueDependencies
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -717,7 +717,6 @@ func ViewIssue(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Dependencies
|
// Get Dependencies
|
||||||
ctx.Data["IssueDependenciesEnabled"] = repo.UnitEnabled(models.UnitTypeIssueDependencies)
|
|
||||||
ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies()
|
ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies()
|
||||||
ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies()
|
ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func AddDependency(c *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the Repo is allowed to have dependencies
|
// 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)
|
c.Handle(404, "MustEnableIssueDependencies", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ func RemoveDependency(c *context.Context) {
|
||||||
return
|
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
|
// Dependency Type
|
||||||
depTypeStr := c.Req.PostForm.Get("dependencyType")
|
depTypeStr := c.Req.PostForm.Get("dependencyType")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
|
||||||
Config: &models.IssuesConfig{
|
Config: &models.IssuesConfig{
|
||||||
EnableTimetracker: form.EnableTimetracker,
|
EnableTimetracker: form.EnableTimetracker,
|
||||||
AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime,
|
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 {
|
if err := models.UpdateRepositoryUnits(repo, units); err != nil {
|
||||||
ctx.Handle(500, "UpdateRepositoryUnits", err)
|
ctx.Handle(500, "UpdateRepositoryUnits", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -191,8 +191,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .IsSigned}}
|
{{if .Repository.IsDependenciesEnabled}}
|
||||||
{{if .IssueDependenciesEnabled}}
|
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
|
|
||||||
<div class="ui depending">
|
<div class="ui depending">
|
||||||
|
|
@ -210,9 +209,11 @@
|
||||||
{{range .BlockedByDependencies}}
|
{{range .BlockedByDependencies}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="right floated content">
|
<div class="right floated content">
|
||||||
|
{{if $.CanUseDependencies}}
|
||||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blockedBy');">
|
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blockedBy');">
|
||||||
<i class="delete icon text red"></i>
|
<i class="delete icon text red"></i>
|
||||||
</a>
|
</a>
|
||||||
|
{{end}}
|
||||||
{{if .IsClosed}}
|
{{if .IsClosed}}
|
||||||
<div class="ui red mini label">
|
<div class="ui red mini label">
|
||||||
<i class="octicon octicon-issue-closed"></i>
|
<i class="octicon octicon-issue-closed"></i>
|
||||||
|
|
@ -242,9 +243,11 @@
|
||||||
{{range .BlockingDependencies}}
|
{{range .BlockingDependencies}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="right floated content">
|
<div class="right floated content">
|
||||||
|
{{if $.CanUseDependencies}}
|
||||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blocking');">
|
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blocking');">
|
||||||
<i class="delete icon text red"></i>
|
<i class="delete icon text red"></i>
|
||||||
</a>
|
</a>
|
||||||
|
{{end}}
|
||||||
{{if .IsClosed}}
|
{{if .IsClosed}}
|
||||||
<div class="ui red tiny label">
|
<div class="ui red tiny label">
|
||||||
<i class="octicon octicon-issue-closed"></i>
|
<i class="octicon octicon-issue-closed"></i>
|
||||||
|
|
@ -265,6 +268,8 @@
|
||||||
{{if (and (not .BlockedByDependencies) (not .BlockingDependencies))}}
|
{{if (and (not .BlockedByDependencies) (not .BlockingDependencies))}}
|
||||||
<p>{{.i18n.Tr "repo.issues.dependency.no_dependencies"}}</p>
|
<p>{{.i18n.Tr "repo.issues.dependency.no_dependencies"}}</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{if .CanUseDependencies}}
|
||||||
<div>
|
<div>
|
||||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/dependency/add" id="addDependencyForm">
|
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/dependency/add" id="addDependencyForm">
|
||||||
{{$.CsrfTokenHtml}}
|
{{$.CsrfTokenHtml}}
|
||||||
|
|
@ -283,10 +288,11 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{if .CanUseDependencies}}
|
||||||
<input type="hidden" id="repolink" value="{{$.RepoLink}}">
|
<input type="hidden" id="repolink" value="{{$.RepoLink}}">
|
||||||
<!-- I know, there is probably a better way to do this -->
|
<!-- I know, there is probably a better way to do this -->
|
||||||
<input type="hidden" id="issueIndex" value="{{.Issue.Index}}"/>
|
<input type="hidden" id="issueIndex" value="{{.Issue.Index}}"/>
|
||||||
|
|
@ -315,5 +321,5 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user