Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add site setting to disable staged user cleanup

Gerhard Schlageredc8d58ac345
diff --git a/app/jobs/scheduled/clean_up_unused_staged_users.rb b/app/jobs/scheduled/clean_up_unused_staged_users.rb
index 3769dffe6bd..be2cd173132 100644
--- a/app/jobs/scheduled/clean_up_unused_staged_users.rb
+++ b/app/jobs/scheduled/clean_up_unused_staged_users.rb
@@ -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
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 9bd64c7dbf5..d0af9b7136b 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -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"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index a1c1f93aba8..d42c7f7b0bc 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -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
diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb
index b5483d9a8b2..c827bc5e7ec 100644
--- a/script/import_scripts/base.rb
+++ b/script/import_scripts/base.rb
@@ -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
diff --git a/spec/jobs/clean_up_unused_staged_users_spec.rb b/spec/jobs/clean_up_unused_staged_users_spec.rb
index ec5cad00b48..11612f75cb0 100644
--- a/spec/jobs/clean_up_unused_staged_users_spec.rb
+++ b/spec/jobs/clean_up_unused_staged_users_spec.rb
@@ -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