Skip to content

Commit

Permalink
Check ctx.Written() for GetActionIssue (go-gitea#25698) (go-gitea…
Browse files Browse the repository at this point in the history
…#25711)

Backport go-gitea#25698 by @wolfogre

Fix go-gitea#25697.

Just avoid panic, maybe there's another bug to trigger this case.

Co-authored-by: Jason Song <i@wolfogre.com>
  • Loading branch information
GiteaBot and wolfogre authored Jul 6, 2023
1 parent 68e0c80 commit 03cacf9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ func GetActionIssue(ctx *context.Context) *issues_model.Issue {
return nil
}
if err = issue.LoadAttributes(ctx); err != nil {
ctx.ServerError("LoadAttributes", nil)
ctx.ServerError("LoadAttributes", err)
return nil
}
return issue
Expand Down Expand Up @@ -3258,6 +3258,9 @@ func filterXRefComments(ctx *context.Context, issue *issues_model.Issue) error {
// GetIssueAttachments returns attachments for the issue
func GetIssueAttachments(ctx *context.Context) {
issue := GetActionIssue(ctx)
if ctx.Written() {
return
}
attachments := make([]*api.Attachment, len(issue.Attachments))
for i := 0; i < len(issue.Attachments); i++ {
attachments[i] = convert.ToAttachment(issue.Attachments[i])
Expand Down
10 changes: 5 additions & 5 deletions routers/web/repo/issue_content_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// GetContentHistoryOverview get overview
func GetContentHistoryOverview(ctx *context.Context) {
issue := GetActionIssue(ctx)
if issue == nil {
if ctx.Written() {
return
}

Expand All @@ -43,11 +43,11 @@ func GetContentHistoryOverview(ctx *context.Context) {
// GetContentHistoryList get list
func GetContentHistoryList(ctx *context.Context) {
issue := GetActionIssue(ctx)
commentID := ctx.FormInt64("comment_id")
if issue == nil {
if ctx.Written() {
return
}

commentID := ctx.FormInt64("comment_id")
items, _ := issues_model.FetchIssueContentHistoryList(ctx, issue.ID, commentID)

// render history list to HTML for frontend dropdown items: (name, value)
Expand Down Expand Up @@ -113,7 +113,7 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *issues_model.Issue
// GetContentHistoryDetail get detail
func GetContentHistoryDetail(ctx *context.Context) {
issue := GetActionIssue(ctx)
if issue == nil {
if ctx.Written() {
return
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
// SoftDeleteContentHistory soft delete
func SoftDeleteContentHistory(ctx *context.Context) {
issue := GetActionIssue(ctx)
if issue == nil {
if ctx.Written() {
return
}

Expand Down
3 changes: 3 additions & 0 deletions routers/web/repo/issue_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
// IssuePinOrUnpin pin or unpin a Issue
func IssuePinOrUnpin(ctx *context.Context) {
issue := GetActionIssue(ctx)
if ctx.Written() {
return
}

// If we don't do this, it will crash when trying to add the pin event to the comment history
err := issue.LoadRepo(ctx)
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,10 +1470,10 @@ func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
// UpdatePullRequestTarget change pull request's target branch
func UpdatePullRequestTarget(ctx *context.Context) {
issue := GetActionIssue(ctx)
pr := issue.PullRequest
if ctx.Written() {
return
}
pr := issue.PullRequest
if !issue.IsPull {
ctx.Error(http.StatusNotFound)
return
Expand Down
11 changes: 7 additions & 4 deletions routers/web/repo/pull_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
// RenderNewCodeCommentForm will render the form for creating a new review comment
func RenderNewCodeCommentForm(ctx *context.Context) {
issue := GetActionIssue(ctx)
if ctx.Written() {
return
}
if !issue.IsPull {
return
}
Expand All @@ -52,10 +55,10 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
func CreateCodeComment(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CodeCommentForm)
issue := GetActionIssue(ctx)
if !issue.IsPull {
if ctx.Written() {
return
}
if ctx.Written() {
if !issue.IsPull {
return
}

Expand Down Expand Up @@ -185,10 +188,10 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
func SubmitReview(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.SubmitReviewForm)
issue := GetActionIssue(ctx)
if !issue.IsPull {
if ctx.Written() {
return
}
if ctx.Written() {
if !issue.IsPull {
return
}
if ctx.HasError() {
Expand Down

0 comments on commit 03cacf9

Please sign in to comment.