mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
fix: Disable syncing IMAP if the account is suspended (#11031)
This PR disables the IMAP syncing if the account is suspended.
This commit is contained in:
@@ -561,7 +561,7 @@ GEM
|
|||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
raabro (1.4.0)
|
raabro (1.4.0)
|
||||||
racc (1.8.1)
|
racc (1.8.1)
|
||||||
rack (2.2.11)
|
rack (2.2.12)
|
||||||
rack-attack (6.7.0)
|
rack-attack (6.7.0)
|
||||||
rack (>= 1.0, < 4)
|
rack (>= 1.0, < 4)
|
||||||
rack-contrib (2.5.0)
|
rack-contrib (2.5.0)
|
||||||
|
|||||||
@@ -2,8 +2,15 @@ class Inboxes::FetchImapEmailInboxesJob < ApplicationJob
|
|||||||
queue_as :scheduled_jobs
|
queue_as :scheduled_jobs
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
Inbox.where(channel_type: 'Channel::Email').all.find_each(batch_size: 100) do |inbox|
|
email_inboxes = Inbox.where(channel_type: 'Channel::Email')
|
||||||
::Inboxes::FetchImapEmailsJob.perform_later(inbox.channel) if inbox.channel.imap_enabled
|
email_inboxes.find_each(batch_size: 100) do |inbox|
|
||||||
|
::Inboxes::FetchImapEmailsJob.perform_later(inbox.channel) if should_fetch_emails?(inbox)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def should_fetch_emails?(inbox)
|
||||||
|
inbox.channel.imap_enabled && !inbox.account.suspended?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,11 +2,19 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe Inboxes::FetchImapEmailInboxesJob do
|
RSpec.describe Inboxes::FetchImapEmailInboxesJob do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
let(:suspended_account) { create(:account, status: 'suspended') }
|
||||||
|
|
||||||
let(:imap_email_channel) do
|
let(:imap_email_channel) do
|
||||||
create(:channel_email, imap_enabled: true, imap_address: 'imap.gmail.com', imap_port: 993, imap_login: 'imap@gmail.com',
|
create(:channel_email, imap_enabled: true, account: account)
|
||||||
imap_password: 'password', account: account)
|
end
|
||||||
|
|
||||||
|
let(:imap_email_channel_suspended) do
|
||||||
|
create(:channel_email, imap_enabled: true, account: suspended_account)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:disabled_imap_channel) do
|
||||||
|
create(:channel_email, imap_enabled: false, account: account)
|
||||||
end
|
end
|
||||||
let(:email_inbox) { create(:inbox, channel: imap_email_channel, account: account) }
|
|
||||||
|
|
||||||
it 'enqueues the job' do
|
it 'enqueues the job' do
|
||||||
expect { described_class.perform_later }.to have_enqueued_job(described_class)
|
expect { described_class.perform_later }.to have_enqueued_job(described_class)
|
||||||
@@ -14,9 +22,26 @@ RSpec.describe Inboxes::FetchImapEmailInboxesJob do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when called' do
|
context 'when called' do
|
||||||
it 'fetch all the email channels' do
|
it 'fetches emails only for active accounts with imap enabled' do
|
||||||
|
# Should call perform_later only once for the active, imap-enabled inbox
|
||||||
expect(Inboxes::FetchImapEmailsJob).to receive(:perform_later).with(imap_email_channel).once
|
expect(Inboxes::FetchImapEmailsJob).to receive(:perform_later).with(imap_email_channel).once
|
||||||
|
|
||||||
|
# Should not call for suspended account or disabled IMAP channels
|
||||||
|
expect(Inboxes::FetchImapEmailsJob).not_to receive(:perform_later).with(imap_email_channel_suspended)
|
||||||
|
expect(Inboxes::FetchImapEmailsJob).not_to receive(:perform_later).with(disabled_imap_channel)
|
||||||
|
|
||||||
|
described_class.perform_now
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'skips suspended accounts' do
|
||||||
|
expect(Inboxes::FetchImapEmailsJob).not_to receive(:perform_later).with(imap_email_channel_suspended)
|
||||||
|
|
||||||
|
described_class.perform_now
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'skips disabled imap channels' do
|
||||||
|
expect(Inboxes::FetchImapEmailsJob).not_to receive(:perform_later).with(disabled_imap_channel)
|
||||||
|
|
||||||
described_class.perform_now
|
described_class.perform_now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user