Skip to content

Commit d8501b4

Browse files
luisadameGusted
authored andcommitted
fix: don't display pending reviews as participants (#10528)
Fixes #10155 When participants are displayed, don't include those that only have made a pending review. Those should not yet be revealed as participants. Apart from adding automated tests, this is the manual verification process I've followed: 1. Set up three users 2. User 1 creates a repository, then creates a pull request adding a new file 3. User 2 creates a new code comment but doesn't not publish the review, shows as pending. 4. User 3 creates a new code comment and publishes the review. 5. From everyone's perspective the number of participants is: 2. And, the participants displayed in the list are 1 and 3. User 2, which hasn't yet published the review is not displayed. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10528 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: luisadame <luisadame@noreply.codeberg.org> Co-committed-by: luisadame <luisadame@noreply.codeberg.org>
1 parent 00b457e commit d8501b4

12 files changed

Lines changed: 89 additions & 7 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- id: 1001
2+
type: 21 # code comment
3+
poster_id: 10
4+
issue_id: 1
5+
review_id: 1001
6+
content: "Some code comment that is pending to be published"
7+
line: -4
8+
tree_path: "README.md"
9+
created_unix: 946684812
10+
invalidated: false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- id: 1001
2+
type: 0 # Pending review
3+
reviewer_id: 10
4+
issue_id: 1
5+
content: "Pending review for issue 1"
6+
updated_unix: 946684810
7+
created_unix: 946684810

models/issues/comment_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (comments CommentList) getReviewIDs() []int64 {
417417
})
418418
}
419419

420-
func (comments CommentList) loadReviews(ctx context.Context) error {
420+
func (comments CommentList) LoadReviews(ctx context.Context) error {
421421
if len(comments) == 0 {
422422
return nil
423423
}
@@ -476,7 +476,7 @@ func (comments CommentList) LoadAttributes(ctx context.Context) (err error) {
476476
return err
477477
}
478478

479-
if err = comments.loadReviews(ctx); err != nil {
479+
if err = comments.LoadReviews(ctx); err != nil {
480480
return err
481481
}
482482

models/issues/issue.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,12 @@ func GetParticipantsIDsByIssueID(ctx context.Context, issueID int64) ([]int64, e
591591
userIDs := make([]int64, 0, 5)
592592
return userIDs, db.GetEngine(ctx).
593593
Table("comment").
594-
Cols("poster_id").
595-
Where("issue_id = ?", issueID).
596-
And("type in (?,?,?)", CommentTypeComment, CommentTypeCode, CommentTypeReview).
597-
Distinct("poster_id").
594+
Cols("`comment`.poster_id").
595+
Where("`comment`.issue_id = ?", issueID).
596+
And("`comment`.type in (?,?,?)", CommentTypeComment, CommentTypeCode, CommentTypeReview).
597+
And("`review`.type is null or `review`.type != ?", ReviewTypePending).
598+
Join("LEFT", "`review`", "`review`.id = `comment`.review_id").
599+
Distinct("`comment`.poster_id").
598600
Find(&userIDs)
599601
}
600602

@@ -623,9 +625,11 @@ func (issue *Issue) GetParticipantIDsByIssue(ctx context.Context) ([]int64, erro
623625
if err := db.GetEngine(ctx).Table("comment").Cols("poster_id").
624626
Where("`comment`.issue_id = ?", issue.ID).
625627
And("`comment`.type in (?,?,?)", CommentTypeComment, CommentTypeCode, CommentTypeReview).
628+
And("`review`.type != ?", ReviewTypePending).
626629
And("`user`.is_active = ?", true).
627630
And("`user`.prohibit_login = ?", false).
628631
Join("INNER", "`user`", "`user`.id = `comment`.poster_id").
632+
Join("INNER", "`review`", "`review`.reviewer_id = `user`.id").
629633
Distinct("poster_id").
630634
Find(&userIDs); err != nil {
631635
return nil, fmt.Errorf("get poster IDs: %w", err)

models/issues/issue_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func TestGetIssuesByIDs(t *testing.T) {
8585
}
8686

8787
func TestGetParticipantIDsByIssue(t *testing.T) {
88+
defer unittest.OverrideFixtures("models/issues/TestGetParticipantIDsByIssue")()
8889
require.NoError(t, unittest.PrepareTestDatabase())
8990

9091
checkParticipants := func(issueID int64, userIDs []int) {
@@ -107,6 +108,7 @@ func TestGetParticipantIDsByIssue(t *testing.T) {
107108
// User 2 only labeled issue1 (see fixtures/comment.yml)
108109
// Users 3 and 5 made actual comments (see fixtures/comment.yml)
109110
// User 3 is inactive, thus not active participant
111+
// User 10 has a pending review, thus not an active participant, yet (see TestGetParticipantIDsByIssue/comment.yml)
110112
checkParticipants(1, []int{1, 5})
111113
}
112114

routers/web/repo/issue.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,17 +1654,27 @@ func ViewIssue(ctx *context.Context) {
16541654
ctx.ServerError("LoadAttachmentsByIssue", err)
16551655
return
16561656
}
1657+
16571658
if err := issue.Comments.LoadPosters(ctx); err != nil {
16581659
ctx.ServerError("LoadPosters", err)
16591660
return
16601661
}
16611662

1663+
if err := issue.Comments.LoadReviews(ctx); err != nil {
1664+
ctx.ServerError("LoadReviews", err)
1665+
return
1666+
}
1667+
16621668
for commentIdx, comment = range issue.Comments {
16631669
comment.Issue = issue
16641670
metas := ctx.Repo.Repository.ComposeMetas(ctx)
16651671
metas["scope"] = fmt.Sprintf("comment-%d", commentIdx)
16661672

1667-
if comment.Type == issues_model.CommentTypeComment || comment.Type == issues_model.CommentTypeReview {
1673+
if comment.Review != nil && comment.Review.Type == issues_model.ReviewTypePending {
1674+
continue
1675+
}
1676+
1677+
if comment.Type == issues_model.CommentTypeComment {
16681678
comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{
16691679
Links: markup.Links{
16701680
Base: ctx.Repo.RepoLink,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- id: 1001
2+
type: 21 # code comment
3+
poster_id: 10
4+
issue_id: 1
5+
review_id: 1001
6+
content: "Some code comment that is pending to be published"
7+
line: -4
8+
tree_path: "README.md"
9+
created_unix: 946684812
10+
invalidated: false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- id: 1001
2+
type: 0 # Pending review
3+
reviewer_id: 10
4+
issue_id: 1
5+
content: "Pending review for issue 1"
6+
updated_unix: 946684810
7+
created_unix: 946684810

services/mailer/mail_issue_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
)
1919

2020
func TestCloseIssue(t *testing.T) {
21+
defer unittest.OverrideFixtures("services/mailer/fixtures/TestCloseIssue")()
2122
defer require.NoError(t, unittest.PrepareTestDatabase())
2223

2324
called := false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- id: 1001
2+
type: 21 # code comment
3+
poster_id: 10
4+
issue_id: 2
5+
review_id: 1001
6+
content: "Some code comment that is pending to be published"
7+
line: -4
8+
tree_path: "README.md"
9+
created_unix: 946684812
10+
invalidated: false

0 commit comments

Comments
 (0)