From 2382f1b057bb582abc87a030f0463e3b1f6fb118 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 6 May 2019 20:09:31 +0800 Subject: [PATCH] fix 500 when reviewer is deleted with integration tests (#6856) --- integrations/pull_review_test.go | 20 ++++++++++++++++++++ models/fixtures/comment.yml | 12 ++++++++++++ models/fixtures/review.yml | 9 +++++++++ models/issue_comment.go | 1 + routers/repo/issue.go | 9 +++++++-- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 integrations/pull_review_test.go diff --git a/integrations/pull_review_test.go b/integrations/pull_review_test.go new file mode 100644 index 000000000000..b4ddc0e7419a --- /dev/null +++ b/integrations/pull_review_test.go @@ -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) +} diff --git a/models/fixtures/comment.yml b/models/fixtures/comment.yml index 6abd26973b56..864313cac342 100644 --- a/models/fixtures/comment.yml +++ b/models/fixtures/comment.yml @@ -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 \ No newline at end of file diff --git a/models/fixtures/review.yml b/models/fixtures/review.yml index 515f0d77f853..a0122dea99f9 100644 --- a/models/fixtures/review.yml +++ b/models/fixtures/review.yml @@ -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 \ No newline at end of file diff --git a/models/issue_comment.go b/models/issue_comment.go index a1c2364b0b95..a7d6e2e3e8f1 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -447,6 +447,7 @@ func (c *Comment) loadReview(e Engine) (err error) { return err } } + c.Review.Issue = c.Issue return nil } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 4b76bf5ad971..c2749fcb4753 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -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 @@ -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)