FIX: Don’t try to delete inactive moderators

FIX: Don’t try to delete inactive moderators

follow-up to 6d77156a

diff --git a/app/jobs/scheduled/clean_up_inactive_users.rb b/app/jobs/scheduled/clean_up_inactive_users.rb
index f42fdc4..f0ccc89 100644
--- a/app/jobs/scheduled/clean_up_inactive_users.rb
+++ b/app/jobs/scheduled/clean_up_inactive_users.rb
@@ -9,7 +9,7 @@ module Jobs
       return if SiteSetting.clean_up_inactive_users_after_days <= 0
 
       User.joins("LEFT JOIN posts ON posts.user_id = users.id")
-        .where(last_posted_at: nil, trust_level: TrustLevel.levels[:newuser], admin: false)
+        .where(last_posted_at: nil, trust_level: TrustLevel.levels[:newuser], admin: false, moderator: false)
         .where(
           "posts.user_id IS NULL AND users.last_seen_at < ?",
           SiteSetting.clean_up_inactive_users_after_days.days.ago
diff --git a/spec/jobs/clean_up_inactive_users_spec.rb b/spec/jobs/clean_up_inactive_users_spec.rb
index 68e68bc..100a18d 100644
--- a/spec/jobs/clean_up_inactive_users_spec.rb
+++ b/spec/jobs/clean_up_inactive_users_spec.rb
@@ -42,4 +42,12 @@ RSpec.describe Jobs::CleanUpInactiveUsers do
     expect { described_class.new.execute({}) }.to_not change { User.count }
     expect(User.exists?(admin.id)).to eq(true)
   end
+
+  it "doesn't delete inactive mods" do
+    SiteSetting.clean_up_inactive_users_after_days = 4
+    moderator = Fabricate(:moderator, last_seen_at: 5.days.ago, trust_level: TrustLevel.levels[:newuser])
+
+    expect { described_class.new.execute({}) }.to_not change { User.count }
+    expect(User.exists?(moderator.id)).to eq(true)
+  end
 end

GitHub sha: bbab60fa

1 Like