Skip to content

Commit 96eb99e

Browse files
lunnylafriks
authored andcommitted
fix 500 when reviewer is deleted with integration tests (#6856) (#6860)
1 parent 83560bf commit 96eb99e

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

integrations/pull_review_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
package integrations
5+
6+
import (
7+
"net/http"
8+
"testing"
9+
)
10+
11+
func TestPullView_ReviewerMissed(t *testing.T) {
12+
prepareTestEnv(t)
13+
session := loginUser(t, "user1")
14+
15+
req := NewRequest(t, "GET", "/pulls")
16+
session.MakeRequest(t, req, http.StatusOK)
17+
18+
req = NewRequest(t, "GET", "/user2/repo1/pulls/3")
19+
session.MakeRequest(t, req, http.StatusOK)
20+
}

models/fixtures/comment.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,15 @@
5252
tree_path: "README.md"
5353
created_unix: 946684812
5454
invalidated: true
55+
56+
-
57+
id: 7
58+
type: 21 # code comment
59+
poster_id: 100
60+
issue_id: 3
61+
content: "a review from a deleted user"
62+
line: -4
63+
review_id: 10
64+
tree_path: "README.md"
65+
created_unix: 946684812
66+
invalidated: true

models/fixtures/review.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@
7070
content: "New review 3 rejected"
7171
updated_unix: 946684810
7272
created_unix: 946684810
73+
74+
-
75+
id: 10
76+
type: 3
77+
reviewer_id: 100
78+
issue_id: 3
79+
content: "a deleted user's review"
80+
updated_unix: 946684810
81+
created_unix: 946684810

models/issue_comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ func (c *Comment) loadReview(e Engine) (err error) {
419419
return err
420420
}
421421
}
422+
c.Review.Issue = c.Issue
422423
return nil
423424
}
424425

routers/repo/issue.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ func ViewIssue(ctx *context.Context) {
753753
// Render comments and and fetch participants.
754754
participants[0] = issue.Poster
755755
for _, comment = range issue.Comments {
756+
comment.Issue = issue
757+
756758
if err := comment.LoadPoster(); err != nil {
757759
ctx.ServerError("LoadPoster", err)
758760
return
@@ -830,8 +832,11 @@ func ViewIssue(ctx *context.Context) {
830832
continue
831833
}
832834
if err = comment.Review.LoadAttributes(); err != nil {
833-
ctx.ServerError("Review.LoadAttributes", err)
834-
return
835+
if !models.IsErrUserNotExist(err) {
836+
ctx.ServerError("Review.LoadAttributes", err)
837+
return
838+
}
839+
comment.Review.Reviewer = models.NewGhostUser()
835840
}
836841
if err = comment.Review.LoadCodeComments(); err != nil {
837842
ctx.ServerError("Review.LoadCodeComments", err)

0 commit comments

Comments
 (0)