From 6ad92ee862ea48500a25ce7f30d6022b81b5cc8c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 18 Jan 2021 23:43:17 +0100 Subject: [PATCH 01/10] refactor models.DeleteComment and delete related reactions too --- models/issue_comment.go | 25 +++++++++++++++++++------ models/issue_reaction.go | 2 +- models/user.go | 3 +-- services/comments/comments.go | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index dd979edcda526..3e6b65f48c2e7 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -1037,33 +1037,46 @@ 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() + if err := deleteReaction(e, &ReactionOptions{Comment: comment}); err != nil { + return err + } + + return nil } // CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS diff --git a/models/issue_reaction.go b/models/issue_reaction.go index 104afce5c1929..e4d5e31e318d8 100644 --- a/models/issue_reaction.go +++ b/models/issue_reaction.go @@ -178,7 +178,7 @@ 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{ Type: opts.Type, UserID: opts.Doer.ID, diff --git a/models/user.go b/models/user.go index 584c9d032d74c..b3a1ebae34799 100644 --- a/models/user.go +++ b/models/user.go @@ -38,7 +38,6 @@ import ( "golang.org/x/crypto/scrypt" "golang.org/x/crypto/ssh" "xorm.io/builder" - "xorm.io/xorm" ) // UserType defines the user type @@ -1072,7 +1071,7 @@ func deleteBeans(e Engine, beans ...interface{}) (err error) { } // FIXME: need some kind of mechanism to record failure. HINT: system notice -func deleteUser(e *xorm.Session, u *User) error { +func deleteUser(e Engine, u *User) error { // Note: A user owns any repository or belongs to any organization // cannot perform delete operation. diff --git a/services/comments/comments.go b/services/comments/comments.go index ad79eec4fb91d..7cf91f284fe6c 100644 --- a/services/comments/comments.go +++ b/services/comments/comments.go @@ -44,7 +44,7 @@ func UpdateComment(c *models.Comment, doer *models.User, oldContent string) erro // DeleteComment deletes the comment func DeleteComment(comment *models.Comment, doer *models.User) error { - if err := models.DeleteComment(comment, doer); err != nil { + if err := models.DeleteComment(comment); err != nil { return err } From d813b88cc873e54596af75ee467996d948129154 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 18 Jan 2021 23:43:44 +0100 Subject: [PATCH 02/10] use deleteComment for UserDeleteWithCommentsMaxDays in DeleteUser --- models/user.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/models/user.go b/models/user.go index b3a1ebae34799..954a7465572fc 100644 --- a/models/user.go +++ b/models/user.go @@ -1152,10 +1152,21 @@ func deleteUser(e Engine, u *User) error { if setting.Service.UserDeleteWithCommentsMaxDays != 0 && u.CreatedUnix.AsTime().Add(time.Duration(setting.Service.UserDeleteWithCommentsMaxDays)*24*time.Hour).After(time.Now()) { - if err = deleteBeans(e, - &Comment{PosterID: u.ID}, - ); err != nil { - return fmt.Errorf("deleteBeans: %v", err) + const batchSize = 50 + for start := 0; ; start += batchSize { + comments := make([]*Comment, 0, batchSize) + if err = e.Where("type=? AND poster_id=?", CommentTypeComment, u.ID).Limit(batchSize, start).Find(&comments); err != nil { + return err + } + if len(comments) == 0 { + break + } + + for i := range comments { + if err = deleteComment(e, comments[i]); err != nil { + return err + } + } } } From 9c74390cf218b67dd46bc3b8b39501c9d9358452 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 18 Jan 2021 23:53:47 +0100 Subject: [PATCH 03/10] nits --- models/issue_assignees.go | 2 +- models/user.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/issue_assignees.go b/models/issue_assignees.go index 05e1797c19969..6716f2fc70f80 100644 --- a/models/issue_assignees.go +++ b/models/issue_assignees.go @@ -82,7 +82,7 @@ func isUserAssignedToIssue(e Engine, issue *Issue, user *User) (isAssigned bool, } // 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}) return } diff --git a/models/user.go b/models/user.go index 954a7465572fc..6304ab767cb79 100644 --- a/models/user.go +++ b/models/user.go @@ -1209,13 +1209,13 @@ func deleteUser(e Engine, u *User) error { // Note: There are something just cannot be roll back, // so just keep error logs of those operations. 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) } if len(u.Avatar) > 0 { 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) } } From 0de512a65bd0f5bd4cbead2c84633c0678a351bf Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 19 Jan 2021 00:01:10 +0100 Subject: [PATCH 04/10] Use time.Duration as other time settings have --- models/user.go | 4 ++-- modules/setting/service.go | 5 +++-- options/locale/locale_en-US.ini | 2 +- routers/user/setting/account.go | 6 +++--- templates/user/settings/account.tmpl | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/models/user.go b/models/user.go index 6304ab767cb79..bf8960a76e623 100644 --- a/models/user.go +++ b/models/user.go @@ -1150,8 +1150,8 @@ func deleteUser(e Engine, u *User) error { return fmt.Errorf("deleteBeans: %v", err) } - if setting.Service.UserDeleteWithCommentsMaxDays != 0 && - u.CreatedUnix.AsTime().Add(time.Duration(setting.Service.UserDeleteWithCommentsMaxDays)*24*time.Hour).After(time.Now()) { + if setting.Service.UserDeleteWithCommentsMaxTime != 0 && + u.CreatedUnix.AsTime().Add(setting.Service.UserDeleteWithCommentsMaxTime).After(time.Now()) { const batchSize = 50 for start := 0; ; start += batchSize { comments := make([]*Comment, 0, batchSize) diff --git a/modules/setting/service.go b/modules/setting/service.go index 86f46898ac109..506f5fe0ddf81 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -6,6 +6,7 @@ package setting import ( "regexp" + "time" "code.gitea.io/gitea/modules/structs" ) @@ -50,7 +51,7 @@ var Service struct { AutoWatchNewRepos bool AutoWatchOnChanges bool DefaultOrgMemberVisible bool - UserDeleteWithCommentsMaxDays int + UserDeleteWithCommentsMaxTime time.Duration // OpenID settings EnableOpenIDSignIn bool @@ -103,7 +104,7 @@ func newService() { Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes)) Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility] Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool() - Service.UserDeleteWithCommentsMaxDays = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_DAYS").MustInt(0) + Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_DAYS").MustDuration(0) sec = Cfg.Section("openid") Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 69cfb290440b9..4f0406139671c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -648,7 +648,7 @@ repos_none = You do not own any repositories delete_account = Delete Your Account delete_prompt = This operation will permanently delete your user account. It CAN NOT be undone. -delete_with_all_comments = Your account is younger than %d days. To avoid ghost comments, all issue/PR comments will be deleted with it. +delete_with_all_comments = Your account is younger than %d. To avoid ghost comments, all issue/PR comments will be deleted with it. confirm_delete_account = Confirm Deletion delete_account_title = Delete User Account delete_account_desc = Are you sure you want to permanently delete this user account? diff --git a/routers/user/setting/account.go b/routers/user/setting/account.go index 3b4191f0beeb2..42c2c59b7e752 100644 --- a/routers/user/setting/account.go +++ b/routers/user/setting/account.go @@ -302,8 +302,8 @@ func loadAccountData(ctx *context.Context) { ctx.Data["ActivationsPending"] = pendingActivation ctx.Data["CanAddEmails"] = !pendingActivation || !setting.Service.RegisterEmailConfirm - if setting.Service.UserDeleteWithCommentsMaxDays != 0 { - ctx.Data["UserDeleteWithCommentsMaxDays"] = setting.Service.UserDeleteWithCommentsMaxDays - ctx.Data["UserDeleteWithComments"] = ctx.User.CreatedUnix.AsTime().Add(time.Duration(setting.Service.UserDeleteWithCommentsMaxDays) * 24 * time.Hour).After(time.Now()) + if setting.Service.UserDeleteWithCommentsMaxTime != 0 { + ctx.Data["UserDeleteWithCommentsMaxTime"] = setting.Service.UserDeleteWithCommentsMaxTime.String() + ctx.Data["UserDeleteWithComments"] = ctx.User.CreatedUnix.AsTime().Add(setting.Service.UserDeleteWithCommentsMaxTime).After(time.Now()) } } diff --git a/templates/user/settings/account.tmpl b/templates/user/settings/account.tmpl index 4f7d8a50c705a..04ab539088397 100644 --- a/templates/user/settings/account.tmpl +++ b/templates/user/settings/account.tmpl @@ -174,7 +174,7 @@

{{svg "octicon-alert"}} {{.i18n.Tr "settings.delete_prompt" | Str2html}}

{{ if .UserDeleteWithComments }} -

{{.i18n.Tr "settings.delete_with_all_comments" .UserDeleteWithCommentsMaxDays | Str2html}}

+

{{.i18n.Tr "settings.delete_with_all_comments" .UserDeleteWithCommentsMaxTime | Str2html}}

{{ end }}
From b36d6bc5b24f3af2481d48aa5b6a975093088d11 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 19 Jan 2021 00:07:19 +0100 Subject: [PATCH 05/10] docs --- custom/conf/app.example.ini | 3 ++- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- modules/setting/service.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 8921e3a5decef..d1d1e5c1518e8 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -690,7 +690,8 @@ AUTO_WATCH_NEW_REPOS = true AUTO_WATCH_ON_CHANGES = false ; Default value for the minimum age a user has to exist before deletion to keep issue comments. ; If a user deletes his account before that amount of days, his comments will be deleted as well. -USER_DELETE_WITH_COMMENTS_MAX_DAYS = 0 +; Default is 2h, use 0 to disable it. +USER_DELETE_WITH_COMMENTS_MAX_TIME = 2h [webhook] ; Hook task queue length, increase if webhook shooting starts hanging diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 50d6a072276f2..2a8fe5b7e1efe 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -474,7 +474,7 @@ relation to port exhaustion. - `ALLOW_ONLY_EXTERNAL_REGISTRATION`: **false** Set to true to force registration only using third-party services. - `NO_REPLY_ADDRESS`: **DOMAIN** Default value for the domain part of the user's email address in the git log if he has set KeepEmailPrivate to true. The user's email will be replaced with a concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS. -- `USER_DELETE_WITH_COMMENTS_MAX_DAYS`: **0** If a user deletes his account before that amount of days, his comments will be deleted as well. +- `USER_DELETE_WITH_COMMENTS_MAX_TIME`: **2h** If a user deletes his account before that amount of days, his comments will be deleted as well. 0 to disable it. ## SSH Minimum Key Sizes (`ssh.minimum_key_sizes`) diff --git a/modules/setting/service.go b/modules/setting/service.go index 506f5fe0ddf81..0a83e7e1a9fa1 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -104,7 +104,7 @@ func newService() { Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes)) Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility] Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool() - Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_DAYS").MustDuration(0) + Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(2 * time.Hour) sec = Cfg.Section("openid") Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock) From 1ea20fd71b8e23fca4468ee92c15692c299270df Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 19 Jan 2021 00:16:12 +0100 Subject: [PATCH 06/10] Resolve Fixme & fix potential deadlock --- models/admin.go | 2 +- models/issue_comment.go | 6 +----- models/issue_reaction.go | 10 +++++++--- models/user.go | 21 +++++++++++++++------ options/locale/locale_en-US.ini | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/models/admin.go b/models/admin.go index 4635676d0cbc8..77f1c87c026cb 100644 --- a/models/admin.go +++ b/models/admin.go @@ -75,7 +75,7 @@ func removeStorageWithNotice(e Engine, bucket storage.ObjectStorage, title, path if err := bucket.Delete(path); err != nil { desc := fmt.Sprintf("%s [%s]: %v", title, 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) } } diff --git a/models/issue_comment.go b/models/issue_comment.go index 3e6b65f48c2e7..977b6da77de26 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -1072,11 +1072,7 @@ func deleteComment(e Engine, comment *Comment) error { return err } - if err := deleteReaction(e, &ReactionOptions{Comment: comment}); err != nil { - return err - } - - return nil + return deleteReaction(e, &ReactionOptions{Comment: comment}) } // CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS diff --git a/models/issue_reaction.go b/models/issue_reaction.go index e4d5e31e318d8..ad85e5747c3db 100644 --- a/models/issue_reaction.go +++ b/models/issue_reaction.go @@ -180,9 +180,13 @@ func CreateCommentReaction(doer *User, issue *Issue, comment *Comment, content s func deleteReaction(e Engine, opts *ReactionOptions) error { reaction := &Reaction{ - Type: opts.Type, - UserID: opts.Doer.ID, - IssueID: opts.Issue.ID, + Type: opts.Type, + } + if opts.Doer != nil { + reaction.UserID = opts.Doer.ID + } + if opts.Issue != nil { + reaction.IssueID = opts.Issue.ID } if opts.Comment != nil { reaction.CommentID = opts.Comment.ID diff --git a/models/user.go b/models/user.go index bf8960a76e623..746608aaa47cf 100644 --- a/models/user.go +++ b/models/user.go @@ -1070,7 +1070,6 @@ func deleteBeans(e Engine, beans ...interface{}) (err error) { return nil } -// FIXME: need some kind of mechanism to record failure. HINT: system notice func deleteUser(e Engine, u *User) error { // Note: A user owns any repository or belongs to any organization // cannot perform delete operation. @@ -1152,6 +1151,8 @@ func deleteUser(e Engine, u *User) error { if setting.Service.UserDeleteWithCommentsMaxTime != 0 && u.CreatedUnix.AsTime().Add(setting.Service.UserDeleteWithCommentsMaxTime).After(time.Now()) { + + // Delete Comments const batchSize = 50 for start := 0; ; start += batchSize { comments := make([]*Comment, 0, batchSize) @@ -1162,12 +1163,17 @@ func deleteUser(e Engine, u *User) error { break } - for i := range comments { - if err = deleteComment(e, comments[i]); err != nil { + for _, comment := range comments { + if err = deleteComment(e, comment); err != nil { return err } } } + + // Delete Reactions + if err = deleteReaction(e, &ReactionOptions{Doer: u}); err != nil { + return err + } } // ***** START: PublicKey ***** @@ -1205,18 +1211,21 @@ func deleteUser(e Engine, u *User) error { return fmt.Errorf("Delete: %v", err) } - // FIXME: system notice // Note: There are something just cannot be roll back, // so just keep error logs of those operations. path := UserPath(u.Name) 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 { avatarPath := u.CustomAvatarRelativePath() 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 } } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4f0406139671c..8f7fb2345ccf5 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -648,7 +648,7 @@ repos_none = You do not own any repositories delete_account = Delete Your Account delete_prompt = This operation will permanently delete your user account. It CAN NOT be undone. -delete_with_all_comments = Your account is younger than %d. To avoid ghost comments, all issue/PR comments will be deleted with it. +delete_with_all_comments = Your account is younger than %s. To avoid ghost comments, all issue/PR comments will be deleted with it. confirm_delete_account = Confirm Deletion delete_account_title = Delete User Account delete_account_desc = Are you sure you want to permanently delete this user account? From 5914572f24364cf4cdcdafba54edc1423e8200a9 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 19 Jan 2021 13:20:51 +0100 Subject: [PATCH 07/10] Disabled by Default --- custom/conf/app.example.ini | 3 +-- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- modules/setting/service.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index d1d1e5c1518e8..e32b34ff831c5 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -690,8 +690,7 @@ AUTO_WATCH_NEW_REPOS = true AUTO_WATCH_ON_CHANGES = false ; Default value for the minimum age a user has to exist before deletion to keep issue comments. ; If a user deletes his account before that amount of days, his comments will be deleted as well. -; Default is 2h, use 0 to disable it. -USER_DELETE_WITH_COMMENTS_MAX_TIME = 2h +USER_DELETE_WITH_COMMENTS_MAX_TIME = 0 [webhook] ; Hook task queue length, increase if webhook shooting starts hanging diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 2a8fe5b7e1efe..417a4e21f4d58 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -474,7 +474,7 @@ relation to port exhaustion. - `ALLOW_ONLY_EXTERNAL_REGISTRATION`: **false** Set to true to force registration only using third-party services. - `NO_REPLY_ADDRESS`: **DOMAIN** Default value for the domain part of the user's email address in the git log if he has set KeepEmailPrivate to true. The user's email will be replaced with a concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS. -- `USER_DELETE_WITH_COMMENTS_MAX_TIME`: **2h** If a user deletes his account before that amount of days, his comments will be deleted as well. 0 to disable it. +- `USER_DELETE_WITH_COMMENTS_MAX_TIME`: **0** If a user deletes his account before that amount of days, his comments will be deleted as well. ## SSH Minimum Key Sizes (`ssh.minimum_key_sizes`) diff --git a/modules/setting/service.go b/modules/setting/service.go index 0a83e7e1a9fa1..4410a600dd86e 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -104,7 +104,7 @@ func newService() { Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes)) Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility] Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool() - Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(2 * time.Hour) + Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(0) sec = Cfg.Section("openid") Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock) From 9ffbdc2f25304bb90828d0ca7febc705c1197c80 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 21 Jan 2021 22:05:14 +0100 Subject: [PATCH 08/10] Update Config Value Description --- custom/conf/app.example.ini | 3 +-- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index e32b34ff831c5..f2b65a0963db6 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -688,8 +688,7 @@ AUTO_WATCH_NEW_REPOS = true ; Default value for AutoWatchOnChanges ; Make the user watch a repository When they commit for the first time AUTO_WATCH_ON_CHANGES = false -; Default value for the minimum age a user has to exist before deletion to keep issue comments. -; If a user deletes his account before that amount of days, his comments will be deleted as well. +; Minimum amount of time a user must exist before comments are kept when the user is deleted. USER_DELETE_WITH_COMMENTS_MAX_TIME = 0 [webhook] diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 417a4e21f4d58..5d2670151cb55 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -474,7 +474,7 @@ relation to port exhaustion. - `ALLOW_ONLY_EXTERNAL_REGISTRATION`: **false** Set to true to force registration only using third-party services. - `NO_REPLY_ADDRESS`: **DOMAIN** Default value for the domain part of the user's email address in the git log if he has set KeepEmailPrivate to true. The user's email will be replaced with a concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS. -- `USER_DELETE_WITH_COMMENTS_MAX_TIME`: **0** If a user deletes his account before that amount of days, his comments will be deleted as well. +- `USER_DELETE_WITH_COMMENTS_MAX_TIME`: **0** Minimum amount of time a user must exist before comments are kept when the user is deleted. ## SSH Minimum Key Sizes (`ssh.minimum_key_sizes`) From e4079c77b2d2f935bd07b1c1b6d68b9d7519fa4b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 21 Jan 2021 22:07:44 +0100 Subject: [PATCH 09/10] switch args --- routers/api/v1/repo/issue_comment.go | 2 +- routers/repo/issue.go | 2 +- services/comments/comments.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 245c90d49aab0..af69ae981ad3b 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -509,7 +509,7 @@ func deleteIssueComment(ctx *context.APIContext) { return } - if err = comment_service.DeleteComment(comment, ctx.User); err != nil { + if err = comment_service.DeleteComment(ctx.User, comment); err != nil { ctx.Error(http.StatusInternalServerError, "DeleteCommentByID", err) return } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 6a532dc125a92..fbeae75ab5218 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -2125,7 +2125,7 @@ func DeleteComment(ctx *context.Context) { return } - if err = comment_service.DeleteComment(comment, ctx.User); err != nil { + if err = comment_service.DeleteComment(ctx.User, comment); err != nil { ctx.ServerError("DeleteCommentByID", err) return } diff --git a/services/comments/comments.go b/services/comments/comments.go index 7cf91f284fe6c..f8bdc8153b474 100644 --- a/services/comments/comments.go +++ b/services/comments/comments.go @@ -43,7 +43,7 @@ func UpdateComment(c *models.Comment, doer *models.User, oldContent string) erro } // DeleteComment deletes the comment -func DeleteComment(comment *models.Comment, doer *models.User) error { +func DeleteComment(doer *models.User, comment *models.Comment) error { if err := models.DeleteComment(comment); err != nil { return err } From d894287d76ff048b7c457498db7681088bc4e8ef Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 21 Jan 2021 22:20:59 +0100 Subject: [PATCH 10/10] Update models/issue_comment.go Co-authored-by: zeripath --- models/issue_comment.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index 977b6da77de26..d8f4f0537ac90 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -1052,7 +1052,6 @@ func DeleteComment(comment *Comment) error { } func deleteComment(e Engine, comment *Comment) error { - if _, err := e.Delete(&Comment{ ID: comment.ID, }); err != nil {