2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::InvalidateInactiveAdmins do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:job) { Jobs::InvalidateInactiveAdmins.new.execute({}) }
|
|
|
|
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:active_admin) { Fabricate(:admin, last_seen_at: 1.hour.ago) }
|
2018-12-12 15:32:14 -05:00
|
|
|
|
2023-06-21 10:00:19 -04:00
|
|
|
before { active_admin.email_tokens.update_all(confirmed: true) }
|
2018-12-12 15:32:14 -05:00
|
|
|
|
|
|
|
it "does nothing when all admins have been seen recently" do
|
|
|
|
SiteSetting.invalidate_inactive_admin_email_after_days = 365
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2018-12-12 17:07:49 -05:00
|
|
|
expect(active_admin.reload.active).to eq(true)
|
2018-12-12 15:32:14 -05:00
|
|
|
expect(active_admin.email_tokens.where(confirmed: true).exists?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an admin who hasn't been seen recently" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:not_seen_admin) { Fabricate(:admin, last_seen_at: 370.days.ago) }
|
2018-12-12 15:32:14 -05:00
|
|
|
before { not_seen_admin.email_tokens.update_all(confirmed: true) }
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when invalidate_inactive_admin_email_after_days = 365" do
|
2018-12-12 15:32:14 -05:00
|
|
|
before { SiteSetting.invalidate_inactive_admin_email_after_days = 365 }
|
|
|
|
|
2018-12-12 17:07:49 -05:00
|
|
|
it "marks email tokens as unconfirmed" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2018-12-12 17:07:49 -05:00
|
|
|
expect(not_seen_admin.reload.email_tokens.where(confirmed: true).exists?).to eq(false)
|
2018-12-12 15:32:14 -05:00
|
|
|
end
|
|
|
|
|
2020-01-28 07:16:24 -05:00
|
|
|
it "makes the user as not active and logs the action" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2020-01-28 07:16:24 -05:00
|
|
|
expect(not_seen_admin.reload.active).to eq(false)
|
|
|
|
|
|
|
|
log = UserHistory.last
|
|
|
|
expect(log.target_user_id).to eq(not_seen_admin.id)
|
|
|
|
expect(log.action).to eq(UserHistory.actions[:deactivate_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "adds a staff log" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2018-12-12 17:07:49 -05:00
|
|
|
expect(not_seen_admin.reload.active).to eq(false)
|
2018-12-12 15:32:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with social logins" do
|
|
|
|
before do
|
2019-03-07 06:31:04 -05:00
|
|
|
UserAssociatedAccount.create!(
|
|
|
|
provider_name: "google_oauth2",
|
|
|
|
user_id: not_seen_admin.id,
|
|
|
|
provider_uid: 100,
|
|
|
|
info: {
|
|
|
|
email: "bob@google.account.com",
|
|
|
|
},
|
|
|
|
)
|
2018-12-12 15:32:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "removes the social logins" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2019-03-07 06:31:04 -05:00
|
|
|
expect(UserAssociatedAccount.where(user_id: not_seen_admin.id).exists?).to eq(false)
|
2018-12-12 15:32:14 -05:00
|
|
|
end
|
|
|
|
end
|
2019-11-12 11:56:01 -05:00
|
|
|
|
|
|
|
it "doesn't deactivate admins with recent posts" do
|
|
|
|
Fabricate(:post, user: not_seen_admin)
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2019-11-12 11:56:01 -05:00
|
|
|
expect(not_seen_admin.reload.active).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't deactivate admins with recently used api keys" do
|
|
|
|
Fabricate(:api_key, user: not_seen_admin, last_used_at: 1.day.ago)
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2019-11-12 11:56:01 -05:00
|
|
|
expect(not_seen_admin.reload.active).to eq(true)
|
|
|
|
end
|
2018-12-12 15:32:14 -05:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when invalidate_inactive_admin_email_after_days = 0 to disable this feature" do
|
2018-12-12 15:32:14 -05:00
|
|
|
before { SiteSetting.invalidate_inactive_admin_email_after_days = 0 }
|
|
|
|
|
|
|
|
it "does nothing" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2018-12-12 17:07:49 -05:00
|
|
|
expect(active_admin.reload.active).to eq(true)
|
2018-12-12 15:32:14 -05:00
|
|
|
expect(active_admin.email_tokens.where(confirmed: true).exists?).to eq(true)
|
2018-12-12 17:07:49 -05:00
|
|
|
expect(not_seen_admin.reload.active).to eq(true)
|
2018-12-12 15:32:14 -05:00
|
|
|
expect(not_seen_admin.email_tokens.where(confirmed: true).exists?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|