* Enhance Ghost comment mitigation Settings (#14392) * refactor models.DeleteComment and delete related reactions too * use deleteComment for UserDeleteWithCommentsMaxDays in DeleteUser * Resolve Fixme & fix potential deadlock * rm refactor * make diff eaven less
This commit is contained in:
parent
fb274ec54b
commit
4d2a6c40f8
5 changed files with 23 additions and 14 deletions
|
@ -77,7 +77,7 @@ func removeStorageWithNotice(e Engine, bucket storage.ObjectStorage, title, path
|
||||||
if err := bucket.Delete(path); err != nil {
|
if err := bucket.Delete(path); err != nil {
|
||||||
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
|
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
|
||||||
log.Warn(title+" [%s]: %v", path, err)
|
log.Warn(title+" [%s]: %v", path, err)
|
||||||
if err = createNotice(x, NoticeRepository, desc); err != nil {
|
if err = createNotice(e, NoticeRepository, desc); err != nil {
|
||||||
log.Error("CreateRepositoryNotice: %v", err)
|
log.Error("CreateRepositoryNotice: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ func isUserAssignedToIssue(e Engine, issue *Issue, user *User) (isAssigned bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearAssigneeByUserID deletes all assignments of an user
|
// ClearAssigneeByUserID deletes all assignments of an user
|
||||||
func clearAssigneeByUserID(sess *xorm.Session, userID int64) (err error) {
|
func clearAssigneeByUserID(sess Engine, userID int64) (err error) {
|
||||||
_, err = sess.Delete(&IssueAssignees{AssigneeID: userID})
|
_, err = sess.Delete(&IssueAssignees{AssigneeID: userID})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1077,6 +1077,10 @@ func DeleteComment(comment *Comment, doer *User) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := deleteReaction(sess, &ReactionOptions{Comment: comment}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return sess.Commit()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,11 +178,15 @@ func CreateCommentReaction(doer *User, issue *Issue, comment *Comment, content s
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteReaction(e *xorm.Session, opts *ReactionOptions) error {
|
func deleteReaction(e Engine, opts *ReactionOptions) error {
|
||||||
reaction := &Reaction{
|
reaction := &Reaction{
|
||||||
Type: opts.Type,
|
Type: opts.Type,
|
||||||
UserID: opts.Doer.ID,
|
}
|
||||||
IssueID: opts.Issue.ID,
|
if opts.Doer != nil {
|
||||||
|
reaction.UserID = opts.Doer.ID
|
||||||
|
}
|
||||||
|
if opts.Issue != nil {
|
||||||
|
reaction.IssueID = opts.Issue.ID
|
||||||
}
|
}
|
||||||
if opts.Comment != nil {
|
if opts.Comment != nil {
|
||||||
reaction.CommentID = opts.Comment.ID
|
reaction.CommentID = opts.Comment.ID
|
||||||
|
|
|
@ -40,7 +40,6 @@ import (
|
||||||
"golang.org/x/crypto/scrypt"
|
"golang.org/x/crypto/scrypt"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
"xorm.io/xorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserType defines the user type
|
// UserType defines the user type
|
||||||
|
@ -1020,8 +1019,7 @@ func deleteBeans(e Engine, beans ...interface{}) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: need some kind of mechanism to record failure. HINT: system notice
|
func deleteUser(e Engine, u *User) error {
|
||||||
func deleteUser(e *xorm.Session, u *User) error {
|
|
||||||
// Note: A user owns any repository or belongs to any organization
|
// Note: A user owns any repository or belongs to any organization
|
||||||
// cannot perform delete operation.
|
// cannot perform delete operation.
|
||||||
|
|
||||||
|
@ -1135,18 +1133,21 @@ func deleteUser(e *xorm.Session, u *User) error {
|
||||||
return fmt.Errorf("Delete: %v", err)
|
return fmt.Errorf("Delete: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: system notice
|
|
||||||
// Note: There are something just cannot be roll back,
|
// Note: There are something just cannot be roll back,
|
||||||
// so just keep error logs of those operations.
|
// so just keep error logs of those operations.
|
||||||
path := UserPath(u.Name)
|
path := UserPath(u.Name)
|
||||||
if err := util.RemoveAll(path); err != nil {
|
if err = util.RemoveAll(path); err != nil {
|
||||||
return fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
|
err = fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
|
||||||
|
_ = createNotice(e, NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(u.Avatar) > 0 {
|
if len(u.Avatar) > 0 {
|
||||||
avatarPath := u.CustomAvatarRelativePath()
|
avatarPath := u.CustomAvatarRelativePath()
|
||||||
if err := storage.Avatars.Delete(avatarPath); err != nil {
|
if err = storage.Avatars.Delete(avatarPath); err != nil {
|
||||||
return fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
|
err = fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
|
||||||
|
_ = createNotice(e, NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue