FIX: Do not delete old chat messages if chat disabled (#21214)

Further followup to 24ec06ff85,
where I prevented other chat scheduled jobs from running if
chat was disabled. We should not be running any plugin scheduled
jobs if that plugin is disabled, it can cause unexpected
behaviour.
This commit is contained in:
Martin Brennan 2023-04-24 14:42:50 +10:00 committed by GitHub
parent 7464634f69
commit 896707c7ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -6,6 +6,8 @@ module Jobs
daily at: 0.hours
def execute(args = {})
return if !SiteSetting.chat_enabled
delete_public_channel_messages
delete_dm_channel_messages
end

View File

@ -79,7 +79,10 @@ describe Jobs::Chat::DeleteOldMessages do
)
end
before { freeze_time(base_date) }
before do
freeze_time(base_date)
SiteSetting.chat_enabled = true
end
it "doesn't delete messages when settings are 0" do
SiteSetting.chat_channel_retention_days = 0
@ -109,6 +112,16 @@ describe Jobs::Chat::DeleteOldMessages do
SiteSetting.chat_channel_retention_days = 800
expect { described_class.new.execute }.not_to change { Chat::Message.in_public_channel.count }
end
context "when chat is disabled" do
before { SiteSetting.chat_enabled = false }
it "does nothing" do
expect { described_class.new.execute }.not_to change {
Chat::Message.in_public_channel.count
}
end
end
end
describe "dm channels" do
@ -132,5 +145,13 @@ describe Jobs::Chat::DeleteOldMessages do
SiteSetting.chat_dm_retention_days = 800
expect { described_class.new.execute }.not_to change { Chat::Message.in_dm_channel.count }
end
context "when chat is disabled" do
before { SiteSetting.chat_enabled = false }
it "does nothing" do
expect { described_class.new.execute }.not_to change { Chat::Message.in_dm_channel.count }
end
end
end
end