mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-21 03:43:02 +00:00
revert unnecessary change in this pull request
This commit is contained in:
parent
9c251fdb56
commit
0c9f37dbde
@ -102,12 +102,3 @@
|
||||
review_id: 22
|
||||
assignee_id: 5
|
||||
created_unix: 946684817
|
||||
|
||||
-
|
||||
id: 12
|
||||
type: 22 # review
|
||||
poster_id: 100
|
||||
issue_id: 3
|
||||
content: ""
|
||||
review_id: 10
|
||||
created_unix: 946684812
|
||||
|
@ -1113,20 +1113,20 @@ func UpdateComment(ctx context.Context, c *Comment, contentVersion int, doer *us
|
||||
}
|
||||
|
||||
// DeleteComment deletes the comment
|
||||
func DeleteComment(ctx context.Context, comment *Comment) (*Comment, error) {
|
||||
func DeleteComment(ctx context.Context, comment *Comment) error {
|
||||
if _, err := db.GetEngine(ctx).ID(comment.ID).NoAutoCondition().Delete(comment); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := db.DeleteByBean(ctx, &ContentHistory{
|
||||
CommentID: comment.ID,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if comment.Type.CountedAsConversation() {
|
||||
if err := UpdateIssueNumComments(ctx, comment.IssueID); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.GetEngine(ctx).Table("action").
|
||||
@ -1134,54 +1134,14 @@ func DeleteComment(ctx context.Context, comment *Comment) (*Comment, error) {
|
||||
Update(map[string]any{
|
||||
"is_deleted": true,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var deletedReviewComment *Comment
|
||||
|
||||
// delete review & review comment if the code comment is the last comment of the review
|
||||
if comment.Type == CommentTypeCode && comment.ReviewID > 0 {
|
||||
if err := comment.LoadReview(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if comment.Review != nil && comment.Review.Type == ReviewTypeComment {
|
||||
res, err := db.GetEngine(ctx).ID(comment.ReviewID).
|
||||
Where("NOT EXISTS (SELECT 1 FROM comment WHERE review_id = ? AND `type` = ?)", comment.ReviewID, CommentTypeCode).
|
||||
Delete(new(Review))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res > 0 {
|
||||
var reviewComment Comment
|
||||
has, err := db.GetEngine(ctx).Where("review_id = ?", comment.ReviewID).
|
||||
And("`type` = ?", CommentTypeReview).Get(&reviewComment)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if has && reviewComment.Content == "" {
|
||||
if err := reviewComment.LoadAttachments(ctx); 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
|
||||
}
|
||||
}
|
||||
comment.ReviewID = 0 // reset review ID to 0 for the notification
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if err := comment.neuterCrossReferences(ctx); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if err := DeleteReaction(ctx, &ReactionOptions{CommentID: comment.ID}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return deletedReviewComment, nil
|
||||
return DeleteReaction(ctx, &ReactionOptions{CommentID: comment.ID})
|
||||
}
|
||||
|
||||
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
|
||||
|
@ -726,7 +726,7 @@ func deleteIssueComment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
|
||||
if err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
|
@ -325,18 +325,12 @@ func DeleteComment(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
deletedReviewComment, err := issue_service.DeleteComment(ctx, ctx.Doer, comment)
|
||||
if err != nil {
|
||||
if err := issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
|
||||
ctx.ServerError("DeleteComment", err)
|
||||
return
|
||||
}
|
||||
|
||||
res := map[string]any{}
|
||||
if deletedReviewComment != nil {
|
||||
res["deletedReviewCommentHashTag"] = deletedReviewComment.HashTag()
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
ctx.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
// ChangeCommentReaction create a reaction for comment
|
||||
|
@ -132,42 +132,40 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, contentVersion
|
||||
}
|
||||
|
||||
// deleteComment deletes the comment
|
||||
func deleteComment(ctx context.Context, comment *issues_model.Comment, removeAttachments bool) (*issues_model.Comment, error) {
|
||||
return db.WithTx2(ctx, func(ctx context.Context) (*issues_model.Comment, error) {
|
||||
func deleteComment(ctx context.Context, comment *issues_model.Comment, removeAttachments bool) error {
|
||||
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||
if removeAttachments {
|
||||
// load attachments before deleting the comment
|
||||
if err := comment.LoadAttachments(ctx); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// deletedReviewComment should be a review comment with no content and no attachments
|
||||
deletedReviewComment, err := issues_model.DeleteComment(ctx, comment)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err := issues_model.DeleteComment(ctx, comment); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if removeAttachments {
|
||||
// mark comment attachments as deleted
|
||||
if _, err := repo_model.MarkAttachmentsDeleted(ctx, comment.Attachments); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
return deletedReviewComment, nil
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) (*issues_model.Comment, error) {
|
||||
deletedReviewComment, err := deleteComment(ctx, comment, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) error {
|
||||
if err := deleteComment(ctx, comment, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
attachment.AddAttachmentsToCleanQueue(ctx, comment.Attachments)
|
||||
|
||||
notify_service.DeleteComment(ctx, doer, comment)
|
||||
|
||||
return deletedReviewComment, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCommentPushCommits Load push commits
|
||||
|
@ -1,40 +0,0 @@
|
||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package issue
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
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)
|
||||
review := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: comment.ReviewID})
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
// since this is the last comment of the review, it should be deleted when the comment is deleted
|
||||
deletedReviewComment, err := DeleteComment(db.DefaultContext, user1, comment)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, deletedReviewComment)
|
||||
|
||||
// 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)
|
||||
}
|
@ -315,8 +315,7 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue, deleteAttachmen
|
||||
}
|
||||
|
||||
for _, comment := range issue.Comments {
|
||||
_, err := deleteComment(ctx, comment, deleteAttachments)
|
||||
if err != nil {
|
||||
if err := deleteComment(ctx, comment, deleteAttachments); err != nil {
|
||||
return nil, fmt.Errorf("deleteComment [comment_id: %d]: %w", comment.ID, err)
|
||||
}
|
||||
toBeCleanedAttachments = append(toBeCleanedAttachments, comment.Attachments...)
|
||||
|
@ -122,7 +122,7 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (toBeCleane
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err = issues_model.DeleteComment(ctx, comment); err != nil {
|
||||
if err = issues_model.DeleteComment(ctx, comment); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user