Skip to content
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 500 when reviewer is deleted with integration tests #6856

Merged
merged 2 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions integrations/pull_review_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package integrations

import (
"net/http"
"testing"
)

func TestPullView_ReviewerMissed(t *testing.T) {
prepareTestEnv(t)
session := loginUser(t, "user1")

req := NewRequest(t, "GET", "/pulls")
session.MakeRequest(t, req, http.StatusOK)

req = NewRequest(t, "GET", "/user2/repo1/pulls/3")
session.MakeRequest(t, req, http.StatusOK)
}
12 changes: 12 additions & 0 deletions models/fixtures/comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@
tree_path: "README.md"
created_unix: 946684812
invalidated: true

-
id: 7
type: 21 # code comment
poster_id: 100
issue_id: 3
content: "a review from a deleted user"
line: -4
review_id: 10
tree_path: "README.md"
created_unix: 946684812
invalidated: true
9 changes: 9 additions & 0 deletions models/fixtures/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,12 @@
content: "New review 3 rejected"
updated_unix: 946684810
created_unix: 946684810

-
id: 10
type: 3
reviewer_id: 100
issue_id: 3
content: "a deleted user's review"
updated_unix: 946684810
created_unix: 946684810
1 change: 1 addition & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ func (c *Comment) loadReview(e Engine) (err error) {
return err
}
}
c.Review.Issue = c.Issue
return nil
}

Expand Down
9 changes: 7 additions & 2 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@ func ViewIssue(ctx *context.Context) {
// Render comments and and fetch participants.
participants[0] = issue.Poster
for _, comment = range issue.Comments {
comment.Issue = issue

if err := comment.LoadPoster(); err != nil {
ctx.ServerError("LoadPoster", err)
return
Expand Down Expand Up @@ -850,8 +852,11 @@ func ViewIssue(ctx *context.Context) {
continue
}
if err = comment.Review.LoadAttributes(); err != nil {
ctx.ServerError("Review.LoadAttributes", err)
return
if !models.IsErrUserNotExist(err) {
ctx.ServerError("Review.LoadAttributes", err)
return
}
comment.Review.Reviewer = models.NewGhostUser()
}
if err = comment.Review.LoadCodeComments(); err != nil {
ctx.ServerError("Review.LoadCodeComments", err)
Expand Down