fix: Skip email rate limiting for self-hosted instances (#13915)
Self-hosted installations were incorrectly hitting the daily email rate limit of 100, seeded from `installation_config`. Since self-hosted users control their own infrastructure, email rate limiting should only apply to Chatwoot Cloud. Closes #13913
This commit is contained in:
@@ -17,6 +17,7 @@ module AccountEmailRateLimitable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def within_email_rate_limit?
|
def within_email_rate_limit?
|
||||||
|
return true unless ChatwootApp.chatwoot_cloud?
|
||||||
return true if emails_sent_today < email_rate_limit
|
return true if emails_sent_today < email_rate_limit
|
||||||
|
|
||||||
Rails.logger.warn("Account #{id} reached daily email rate limit of #{email_rate_limit}. Sent: #{emails_sent_today}")
|
Rails.logger.warn("Account #{id} reached daily email rate limit of #{email_rate_limit}. Sent: #{emails_sent_today}")
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ RSpec.describe AccountEmailRateLimitable do
|
|||||||
|
|
||||||
describe '#within_email_rate_limit?' do
|
describe '#within_email_rate_limit?' do
|
||||||
before do
|
before do
|
||||||
|
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true)
|
||||||
account.update!(limits: { 'emails' => 2 })
|
account.update!(limits: { 'emails' => 2 })
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -34,6 +35,28 @@ RSpec.describe AccountEmailRateLimitable do
|
|||||||
2.times { account.increment_email_sent_count }
|
2.times { account.increment_email_sent_count }
|
||||||
expect(account).not_to be_within_email_rate_limit
|
expect(account).not_to be_within_email_rate_limit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when self-hosted' do
|
||||||
|
before do
|
||||||
|
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(false)
|
||||||
|
2.times { account.increment_email_sent_count }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'always returns true regardless of limit' do
|
||||||
|
expect(account).to be_within_email_rate_limit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when chatwoot cloud' do
|
||||||
|
before do
|
||||||
|
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true)
|
||||||
|
2.times { account.increment_email_sent_count }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when at limit' do
|
||||||
|
expect(account).not_to be_within_email_rate_limit
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#increment_email_sent_count' do
|
describe '#increment_email_sent_count' do
|
||||||
|
|||||||
Reference in New Issue
Block a user