From 3b76f196684a870ae090031bcddb8b33a1c47cc1 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 12 Dec 2018 17:07:49 -0500 Subject: [PATCH] FIX: invalidating inactive admin emails should mark them as not active --- app/jobs/scheduled/invalidate_inactive_admins.rb | 1 + spec/jobs/invalidate_inactive_admins_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/jobs/scheduled/invalidate_inactive_admins.rb b/app/jobs/scheduled/invalidate_inactive_admins.rb index c31cea4d3a2..208a627c7f1 100644 --- a/app/jobs/scheduled/invalidate_inactive_admins.rb +++ b/app/jobs/scheduled/invalidate_inactive_admins.rb @@ -11,6 +11,7 @@ module Jobs .where('last_seen_at < ?', SiteSetting.invalidate_inactive_admin_email_after_days.days.ago) .each do |user| + user.deactivate user.email_tokens.update_all(confirmed: false, expired: true) Discourse.authenticators.each do |authenticator| diff --git a/spec/jobs/invalidate_inactive_admins_spec.rb b/spec/jobs/invalidate_inactive_admins_spec.rb index 1e8bbae8637..62cacc3dec3 100644 --- a/spec/jobs/invalidate_inactive_admins_spec.rb +++ b/spec/jobs/invalidate_inactive_admins_spec.rb @@ -11,7 +11,7 @@ describe Jobs::InvalidateInactiveAdmins do it "does nothing when all admins have been seen recently" do SiteSetting.invalidate_inactive_admin_email_after_days = 365 subject - expect(active_admin.active).to eq(true) + expect(active_admin.reload.active).to eq(true) expect(active_admin.email_tokens.where(confirmed: true).exists?).to eq(true) end @@ -24,14 +24,14 @@ describe Jobs::InvalidateInactiveAdmins do SiteSetting.invalidate_inactive_admin_email_after_days = 365 end - it 'marks email tokens as unconfirmed and keeps user as active' do + it 'marks email tokens as unconfirmed' do subject - expect(not_seen_admin.email_tokens.where(confirmed: true).exists?).to eq(false) + expect(not_seen_admin.reload.email_tokens.where(confirmed: true).exists?).to eq(false) end - it 'keeps the user active' do + it 'makes the user as not active' do subject - expect(not_seen_admin.active).to eq(true) + expect(not_seen_admin.reload.active).to eq(false) end context 'with social logins' do @@ -59,9 +59,9 @@ describe Jobs::InvalidateInactiveAdmins do it 'does nothing' do subject - expect(active_admin.active).to eq(true) + expect(active_admin.reload.active).to eq(true) expect(active_admin.email_tokens.where(confirmed: true).exists?).to eq(true) - expect(not_seen_admin.active).to eq(true) + expect(not_seen_admin.reload.active).to eq(true) expect(not_seen_admin.email_tokens.where(confirmed: true).exists?).to eq(true) end end