diff options
author | 6543 <6543@obermui.de> | 2021-01-22 03:56:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-21 21:56:19 -0500 |
commit | a0e424da859a5bf52fe1f08c08a9dcbe3e9d92eb (patch) | |
tree | f2326a97f31b4816c5e0cba98bf60392898b3728 /models/issue_comment.go | |
parent | 0e2e73410e1e222633c007969d384d392d0420a3 (diff) | |
download | gitea-a0e424da859a5bf52fe1f08c08a9dcbe3e9d92eb.tar.gz gitea-a0e424da859a5bf52fe1f08c08a9dcbe3e9d92eb.zip |
Enhance Ghost comment mitigation Settings (#14392)
* refactor models.DeleteComment and delete related reactions too
* use deleteComment for UserDeleteWithCommentsMaxDays in DeleteUser
* nits
* Use time.Duration as other time settings have
* docs
* Resolve Fixme & fix potential deadlock
* Disabled by Default
* Update Config Value Description
* switch args
* Update models/issue_comment.go
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r-- | models/issue_comment.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go index dd979edcda..d8f4f0537a 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -1037,33 +1037,41 @@ func UpdateComment(c *Comment, doer *User) error { } // DeleteComment deletes the comment -func DeleteComment(comment *Comment, doer *User) error { +func DeleteComment(comment *Comment) error { sess := x.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err } - if _, err := sess.Delete(&Comment{ + if err := deleteComment(sess, comment); err != nil { + return err + } + + return sess.Commit() +} + +func deleteComment(e Engine, comment *Comment) error { + if _, err := e.Delete(&Comment{ ID: comment.ID, }); err != nil { return err } if comment.Type == CommentTypeComment { - if _, err := sess.Exec("UPDATE `issue` SET num_comments = num_comments - 1 WHERE id = ?", comment.IssueID); err != nil { + if _, err := e.Exec("UPDATE `issue` SET num_comments = num_comments - 1 WHERE id = ?", comment.IssueID); err != nil { return err } } - if _, err := sess.Where("comment_id = ?", comment.ID).Cols("is_deleted").Update(&Action{IsDeleted: true}); err != nil { + if _, err := e.Where("comment_id = ?", comment.ID).Cols("is_deleted").Update(&Action{IsDeleted: true}); err != nil { return err } - if err := comment.neuterCrossReferences(sess); err != nil { + if err := comment.neuterCrossReferences(e); err != nil { return err } - return sess.Commit() + return deleteReaction(e, &ReactionOptions{Comment: comment}) } // CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS |