summaryrefslogtreecommitdiffstats
path: root/routers/repo/issue.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-10-16 10:55:43 +0300
committerGitHub <noreply@github.com>2017-10-16 10:55:43 +0300
commitc1b0c9e7c4bbb669ea03694c30c9ff66a109ef17 (patch)
tree06c50be163dfa85264a72b54393eb29aa0f4128c /routers/repo/issue.go
parenta75d5c72bb9d85b2344ee98b4425290423b6e6b2 (diff)
downloadgitea-c1b0c9e7c4bbb669ea03694c30c9ff66a109ef17.tar.gz
gitea-c1b0c9e7c4bbb669ea03694c30c9ff66a109ef17.zip
Fix PR, milestone and label functionality if issue unit is disabled (#2710)
* Fix PR, milestone and label functionality if issue unit is disabled or not assigned to user * Fix multi-actions in PR page * Change error message * Fix comment update and delete functionality in PR
Diffstat (limited to 'routers/repo/issue.go')
-rw-r--r--routers/repo/issue.go43
1 files changed, 28 insertions, 15 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 091268116b..c24a4e4360 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -720,11 +720,16 @@ func ViewIssue(ctx *context.Context) {
func GetActionIssue(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.Error(404, "GetIssueByIndex")
- } else {
- ctx.Handle(500, "GetIssueByIndex", err)
- }
+ ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
+ return nil
+ }
+ if issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) ||
+ !issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) {
+ ctx.Handle(404, "IssueOrPullRequestUnitNotAllowed", nil)
+ return nil
+ }
+ if err = issue.LoadAttributes(); err != nil {
+ ctx.Handle(500, "LoadAttributes", nil)
return nil
}
return issue
@@ -749,6 +754,19 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
ctx.Handle(500, "GetIssuesByIDs", err)
return nil
}
+ // Check access rights for all issues
+ issueUnitEnabled := ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues)
+ prUnitEnabled := ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)
+ for _, issue := range issues {
+ if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled {
+ ctx.Handle(404, "IssueOrPullRequestUnitNotAllowed", nil)
+ return nil
+ }
+ if err = issue.LoadAttributes(); err != nil {
+ ctx.Handle(500, "LoadAttributes", nil)
+ return nil
+ }
+ }
return issues
}
@@ -884,9 +902,8 @@ func UpdateIssueStatus(ctx *context.Context) {
// NewComment create a comment for issue
func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
- if err != nil {
- ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
+ issue := GetActionIssue(ctx)
+ if ctx.Written() {
return
}
@@ -913,7 +930,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
if form.Status == "reopen" && issue.IsPull {
pull := issue.PullRequest
- pr, err = models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
+ pr, err := models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
if err != nil {
if !models.IsErrPullRequestNotExist(err) {
ctx.Handle(500, "GetUnmergedPullRequest", err)
@@ -935,7 +952,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
if pr != nil {
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
} else {
- if err = issue.ChangeStatus(ctx.User, ctx.Repo.Repository, form.Status == "close"); err != nil {
+ if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, form.Status == "close"); err != nil {
log.Error(4, "ChangeStatus: %v", err)
} else {
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
@@ -962,7 +979,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
return
}
- comment, err = models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
+ comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
if err != nil {
ctx.Handle(500, "CreateIssueComment", err)
return
@@ -1032,10 +1049,6 @@ func DeleteComment(ctx *context.Context) {
// Milestones render milestones page
func Milestones(ctx *context.Context) {
- MustEnableIssues(ctx)
- if ctx.Written() {
- return
- }
ctx.Data["Title"] = ctx.Tr("repo.milestones")
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true