0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-02-01 09:43:00 +01:00
This commit is contained in:
Lunny Xiao 2025-08-01 10:58:34 -07:00
parent 840a5cadfc
commit 880192ea5d
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 18 additions and 21 deletions

View File

@ -105,9 +105,18 @@
-
id: 12
type: 22 # review
poster_id: 100
type: 22 # review comment
poster_id: 1
issue_id: 3
content: ""
review_id: 10
created_unix: 946684812
review_id: 5
created_unix: 946684810
-
id: 13
type: 21 # code comment
poster_id: 1
issue_id: 3
content: "Some codes need to be changed"
review_id: 5
created_unix: 946684810

View File

@ -1168,15 +1168,10 @@ func DeleteComment(ctx context.Context, comment *Comment) (*Comment, error) {
return nil, err
}
if has && reviewComment.Content == "" {
if err := reviewComment.LoadAttachments(ctx); err != nil {
if _, err := db.GetEngine(ctx).ID(reviewComment.ID).Delete(new(Comment)); err != nil {
return nil, err
}
if len(reviewComment.Attachments) == 0 {
if _, err := db.GetEngine(ctx).ID(reviewComment.ID).Delete(new(Comment)); err != nil {
return nil, err
}
deletedReviewComment = &reviewComment
}
deletedReviewComment = &reviewComment
}
comment.ReviewID = 0 // reset review ID to 0 for the notification
}

View File

@ -8,7 +8,6 @@ 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"
@ -18,11 +17,8 @@ import (
func Test_DeleteCommentWithReview(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 7})
assert.NoError(t, comment.LoadAttachments(t.Context()))
assert.Len(t, comment.Attachments, 1)
assert.Equal(t, int64(13), comment.Attachments[0].ID)
assert.Equal(t, int64(10), comment.ReviewID)
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 13})
assert.Equal(t, int64(5), comment.ReviewID)
review := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: comment.ReviewID})
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
@ -33,8 +29,5 @@ func Test_DeleteCommentWithReview(t *testing.T) {
// the review should be deleted as well
unittest.AssertNotExistsBean(t, &issues_model.Review{ID: review.ID})
// the attachment should be deleted as well
newAttachment, err := repo_model.GetAttachmentByID(t.Context(), comment.Attachments[0].ID)
assert.Error(t, err)
assert.Nil(t, newAttachment)
unittest.AssertNotExistsBean(t, &issues_model.Comment{ID: deletedReviewComment.ID})
}