-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PR, milestone and label functionality if issue unit is disabled #2710
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef3792f
Fix PR, milestone and label functionality if issue unit is disabled o…
lafriks d2237b9
Fix multi-actions in PR page
lafriks 956aa30
Change error message
lafriks 5e68565
Fix comment update and delete functionality in PR
lafriks f1db8e5
Merge branch 'master' into fix/pr_with_ext_issues
lafriks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, "UnitEnabled", 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, "UnitEnabled", nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message should be UnitDisabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daviian no, there should be function name that returned error so that from log entries it would be possible to understand what happened
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From that point of view yes, but it is confusing at the first moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is how it is used in rest of the code :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks However in this case the UnitEnabled doesn't even return an error and 404 happens if the required unit is not enabled.