summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-19 14:43:38 +0800
committerGitHub <noreply@github.com>2020-01-19 14:43:38 +0800
commitf540d0ac87fe776e71c5caeba20049f46a667efe (patch)
tree71c115e7b4081ac013c92cfa4e8ad88c43e9dbaa /routers/repo
parent0641965860bc5ebcb1c85067976099986d0136c6 (diff)
downloadgitea-f540d0ac87fe776e71c5caeba20049f46a667efe.tar.gz
gitea-f540d0ac87fe776e71c5caeba20049f46a667efe.zip
Fix issues/pulls dependencies problems (#9842)
* Fix issues/pulls dependencies problems * fix swagger and api param name * fix js
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/compare.go2
-rw-r--r--routers/repo/issue.go18
-rw-r--r--routers/repo/issue_dependency.go32
3 files changed, 30 insertions, 22 deletions
diff --git a/routers/repo/compare.go b/routers/repo/compare.go
index 5d8f52b007..833b7d9182 100644
--- a/routers/repo/compare.go
+++ b/routers/repo/compare.go
@@ -413,7 +413,7 @@ func CompareDiff(ctx *context.Context) {
if !nothingToCompare {
// Setup information for new form.
- RetrieveRepoMetas(ctx, ctx.Repo.Repository)
+ RetrieveRepoMetas(ctx, ctx.Repo.Repository, true)
if ctx.Written() {
return
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 4d83773774..c2aa1a83bb 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -343,7 +343,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
}
// RetrieveRepoMetas find all the meta information of a repository
-func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.Label {
+func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull bool) []*models.Label {
if !ctx.Repo.CanWrite(models.UnitTypeIssues) {
return nil
}
@@ -368,7 +368,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.
ctx.Data["Branches"] = brs
// Contains true if the user can create issue dependencies
- ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User)
+ ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User, isPull)
return labels
}
@@ -438,7 +438,7 @@ func NewIssue(ctx *context.Context) {
setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
renderAttachmentSettings(ctx)
- RetrieveRepoMetas(ctx, ctx.Repo.Repository)
+ RetrieveRepoMetas(ctx, ctx.Repo.Repository, false)
if ctx.Written() {
return
}
@@ -453,7 +453,7 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm, isPull b
err error
)
- labels := RetrieveRepoMetas(ctx, ctx.Repo.Repository)
+ labels := RetrieveRepoMetas(ctx, ctx.Repo.Repository, isPull)
if ctx.Written() {
return nil, nil, 0
}
@@ -665,6 +665,14 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["PageIsIssueList"] = true
}
+ if issue.IsPull && !ctx.Repo.CanRead(models.UnitTypeIssues) {
+ ctx.Data["IssueType"] = "pulls"
+ } else if !issue.IsPull && !ctx.Repo.CanRead(models.UnitTypePullRequests) {
+ ctx.Data["IssueType"] = "issues"
+ } else {
+ ctx.Data["IssueType"] = "all"
+ }
+
ctx.Data["RequireHighlightJS"] = true
ctx.Data["RequireDropzone"] = true
ctx.Data["RequireTribute"] = true
@@ -802,7 +810,7 @@ func ViewIssue(ctx *context.Context) {
}
// Check if the user can use the dependencies
- ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User)
+ ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull)
// check if dependencies can be created across repositories
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
diff --git a/routers/repo/issue_dependency.go b/routers/repo/issue_dependency.go
index d865a56518..055b5ed2af 100644
--- a/routers/repo/issue_dependency.go
+++ b/routers/repo/issue_dependency.go
@@ -14,14 +14,6 @@ import (
// AddDependency adds new dependencies
func AddDependency(ctx *context.Context) {
- // Check if the Repo is allowed to have dependencies
- if !ctx.Repo.CanCreateIssueDependencies(ctx.User) {
- ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
- return
- }
-
- depID := ctx.QueryInt64("newDependency")
-
issueIndex := ctx.ParamsInt64("index")
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
if err != nil {
@@ -29,6 +21,14 @@ func AddDependency(ctx *context.Context) {
return
}
+ // Check if the Repo is allowed to have dependencies
+ if !ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull) {
+ ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
+ return
+ }
+
+ depID := ctx.QueryInt64("newDependency")
+
if err = issue.LoadRepo(); err != nil {
ctx.ServerError("LoadRepo", err)
return
@@ -73,14 +73,6 @@ func AddDependency(ctx *context.Context) {
// RemoveDependency removes the dependency
func RemoveDependency(ctx *context.Context) {
- // Check if the Repo is allowed to have dependencies
- if !ctx.Repo.CanCreateIssueDependencies(ctx.User) {
- ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
- return
- }
-
- depID := ctx.QueryInt64("removeDependencyID")
-
issueIndex := ctx.ParamsInt64("index")
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
if err != nil {
@@ -88,6 +80,14 @@ func RemoveDependency(ctx *context.Context) {
return
}
+ // Check if the Repo is allowed to have dependencies
+ if !ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull) {
+ ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
+ return
+ }
+
+ depID := ctx.QueryInt64("removeDependencyID")
+
if err = issue.LoadRepo(); err != nil {
ctx.ServerError("LoadRepo", err)
return