FIX: Don't try to delete inactive admins

FIX: Don’t try to delete inactive admins

diff --git a/app/jobs/scheduled/clean_up_inactive_users.rb b/app/jobs/scheduled/clean_up_inactive_users.rb
index 8bebeb2..25d3f3b 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
       destroyer =
       User.joins("LEFT JOIN posts ON posts.user_id =")
-        .where(last_posted_at: nil, trust_level: TrustLevel.levels[:newuser])
+        .where(last_posted_at: nil, trust_level: TrustLevel.levels[:newuser], admin: false)
           "posts.user_id IS NULL AND users.last_seen_at < ?",
diff --git a/spec/jobs/clean_up_inactive_users_spec.rb b/spec/jobs/clean_up_inactive_users_spec.rb
index 7790f05..d0c357b 100644
--- a/spec/jobs/clean_up_inactive_users_spec.rb
+++ b/spec/jobs/clean_up_inactive_users_spec.rb
@@ -32,4 +32,12 @@ RSpec.describe Jobs::CleanUpInactiveUsers do
     expect(User.exists?(id: eq(false)
+  it "doesn't delete inactive admins" do
+    SiteSetting.clean_up_inactive_users_after_days = 4
+    admin = Fabricate(:admin, last_seen_at: 5.days.ago, trust_level: TrustLevel.levels[:newuser])
+    expect {{}) }.to_not change { User.count }
+    expect(User.exists?( eq(true)
+  end

GitHub sha: 6d77156a

Hmmm, let’s check for moderator as well :wink:

1 Like

Do we really want to exclude inactive moderators? It makes sense for admins, because the InvalidateInactiveAdmins job deactivates them after some time. But I’m not sure why we should keep mods around when they have never posted, are TL0 and haven’t been seen for more than clean_up_inactive_users_after_days.

I think the reason is… it could be the CEOs account.

It is an odd technical debt / relic that “staff” can be TL0, it pretty much does not compute.


FIX: Don’t try to delete inactive moderators