diff options
author | Nanguan Lin <70063547+lng2020@users.noreply.github.com> | 2023-11-05 21:25:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-05 13:25:40 +0000 |
commit | 966dcb99e3eb96c466e36316200be341fedc453f (patch) | |
tree | 501ddb04e432a6f1139381f7d38641ce337ba102 /models | |
parent | 59f9ef9feebb19337b8a153e6cac0371ca706268 (diff) | |
download | gitea-966dcb99e3eb96c466e36316200be341fedc453f.tar.gz gitea-966dcb99e3eb96c466e36316200be341fedc453f.zip |
Fix 500 when deleting a dismissed review (#27903)
Fix #27767
Add a test to ensure its behavior
Diffstat (limited to 'models')
-rw-r--r-- | models/issues/review.go | 10 | ||||
-rw-r--r-- | models/issues/review_test.go | 30 |
2 files changed, 40 insertions, 0 deletions
diff --git a/models/issues/review.go b/models/issues/review.go index 1cb5379b2f..3db73a09eb 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -897,6 +897,16 @@ func DeleteReview(ctx context.Context, r *Review) error { return err } + opts = FindCommentsOptions{ + Type: CommentTypeDismissReview, + IssueID: r.IssueID, + ReviewID: r.ID, + } + + if _, err := sess.Where(opts.ToConds()).Delete(new(Comment)); err != nil { + return err + } + if _, err := sess.ID(r.ID).Delete(new(Review)); err != nil { return err } diff --git a/models/issues/review_test.go b/models/issues/review_test.go index 63e2aef2cc..1868cb1bfa 100644 --- a/models/issues/review_test.go +++ b/models/issues/review_test.go @@ -8,6 +8,7 @@ import ( "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -258,3 +259,32 @@ func TestDeleteReview(t *testing.T) { assert.NoError(t, err) assert.True(t, review1.Official) } + +func TestDeleteDismissedReview(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) + review, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{ + Content: "reject", + Type: issues_model.ReviewTypeReject, + Official: false, + Issue: issue, + Reviewer: user, + }) + assert.NoError(t, err) + assert.NoError(t, issues_model.DismissReview(db.DefaultContext, review, true)) + comment, err := issues_model.CreateComment(db.DefaultContext, &issues_model.CreateCommentOptions{ + Type: issues_model.CommentTypeDismissReview, + Doer: user, + Repo: repo, + Issue: issue, + ReviewID: review.ID, + Content: "dismiss", + }) + assert.NoError(t, err) + unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: comment.ID}) + assert.NoError(t, issues_model.DeleteReview(db.DefaultContext, review)) + unittest.AssertNotExistsBean(t, &issues_model.Comment{ID: comment.ID}) +} |