mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 11:18:33 +08:00
FEATURE: Add site setting to disable staged user cleanup
... and disabled the cleanup during imports, otherwise a running Sidekiq might delete users before posts are created
This commit is contained in:
parent
60b47d622e
commit
edc8d58ac3
|
@ -6,12 +6,15 @@ module Jobs
|
|||
every 1.day
|
||||
|
||||
def execute(args)
|
||||
clean_up_after_days = SiteSetting.clean_up_unused_staged_users_after_days
|
||||
return if clean_up_after_days <= 0
|
||||
|
||||
destroyer = UserDestroyer.new(Discourse.system_user)
|
||||
|
||||
User.joins("LEFT JOIN posts ON posts.user_id = users.id")
|
||||
.where("posts.user_id IS NULL")
|
||||
.where(staged: true, admin: false, moderator: false)
|
||||
.where("users.created_at < ?", 1.year.ago)
|
||||
.where("users.created_at < ?", clean_up_after_days.days.ago)
|
||||
.find_each do |user|
|
||||
|
||||
begin
|
||||
|
|
|
@ -1992,6 +1992,7 @@ en:
|
|||
ignored_users_message_gap_days: "How long to wait before notifying moderators again about a user who has been ignored by many others."
|
||||
|
||||
clean_up_inactive_users_after_days: "Number of days before an inactive user (trust level 0 without any posts) is removed. To disable clean up set to 0."
|
||||
clean_up_unused_staged_users_after_days: "Number of days before an unused staged user (without any posts) is removed. To disable clean up set to 0."
|
||||
|
||||
user_selected_primary_groups: "Allow users to set their own primary group"
|
||||
|
||||
|
|
|
@ -589,6 +589,10 @@ users:
|
|||
default: 730
|
||||
min: 0
|
||||
max: 3650
|
||||
clean_up_unused_staged_users_after_days:
|
||||
default: 365
|
||||
min: 0
|
||||
max: 3650
|
||||
user_selected_primary_groups:
|
||||
default: false
|
||||
client: true
|
||||
|
|
|
@ -81,7 +81,9 @@ class ImportScripts::Base
|
|||
disable_emails: 'yes',
|
||||
max_attachment_size_kb: 102400,
|
||||
max_image_size_kb: 102400,
|
||||
authorized_extensions: '*'
|
||||
authorized_extensions: '*',
|
||||
clean_up_inactive_users_after_days: 0,
|
||||
clean_up_unused_staged_users_after_days: 0
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -32,6 +32,11 @@ RSpec.describe Jobs::CleanUpUnusedStagedUsers do
|
|||
before { staged_user.update!(moderator: true) }
|
||||
include_examples "does not delete"
|
||||
end
|
||||
|
||||
context "when job is disabled" do
|
||||
before { SiteSetting.clean_up_unused_staged_users_after_days = 0 }
|
||||
include_examples "does not delete"
|
||||
end
|
||||
end
|
||||
|
||||
context 'when staged user is not old enough' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user