From 978a8a4cb20745c620294fc5bd1b0823defff0b0 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Mon, 19 Feb 2024 15:43:35 +0530 Subject: [PATCH 1/2] fix: `support_email` and `inbound_email_domain` returning empty string (#8963) chore: Fix for inbound email domain being nil --- app/models/account.rb | 5 ++-- spec/models/account_spec.rb | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index a24aec775..419ccc471 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -111,11 +111,12 @@ class Account < ApplicationRecord end def inbound_email_domain - domain || GlobalConfig.get('MAILER_INBOUND_EMAIL_DOMAIN')['MAILER_INBOUND_EMAIL_DOMAIN'] || ENV.fetch('MAILER_INBOUND_EMAIL_DOMAIN', false) + domain.presence || GlobalConfig.get('MAILER_INBOUND_EMAIL_DOMAIN')['MAILER_INBOUND_EMAIL_DOMAIN'] || ENV.fetch('MAILER_INBOUND_EMAIL_DOMAIN', + false) end def support_email - super || ENV.fetch('MAILER_SENDER_EMAIL') { GlobalConfig.get('MAILER_SUPPORT_EMAIL')['MAILER_SUPPORT_EMAIL'] } + super.presence || ENV.fetch('MAILER_SENDER_EMAIL') { GlobalConfig.get('MAILER_SUPPORT_EMAIL')['MAILER_SUPPORT_EMAIL'] } end def usage_limits diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 8f9ba7d2c..aa0556492 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -47,6 +47,56 @@ RSpec.describe Account do end end + describe 'inbound_email_domain' do + let(:account) { create(:account) } + + it 'returns the domain from inbox if inbox value is present' do + account.update(domain: 'test.com') + with_modified_env MAILER_INBOUND_EMAIL_DOMAIN: 'test2.com' do + expect(account.inbound_email_domain).to eq('test.com') + end + end + + it 'returns the domain from ENV if inbox value is nil' do + account.update(domain: nil) + with_modified_env MAILER_INBOUND_EMAIL_DOMAIN: 'test.com' do + expect(account.inbound_email_domain).to eq('test.com') + end + end + + it 'returns the domain from ENV if inbox value is empty string' do + account.update(domain: '') + with_modified_env MAILER_INBOUND_EMAIL_DOMAIN: 'test.com' do + expect(account.inbound_email_domain).to eq('test.com') + end + end + end + + describe 'support_email' do + let(:account) { create(:account) } + + it 'returns the support email from inbox if inbox value is present' do + account.update(support_email: 'support@chatwoot.com') + with_modified_env MAILER_SENDER_EMAIL: 'hello@chatwoot.com' do + expect(account.support_email).to eq('support@chatwoot.com') + end + end + + it 'returns the support email from ENV if inbox value is nil' do + account.update(support_email: nil) + with_modified_env MAILER_SENDER_EMAIL: 'hello@chatwoot.com' do + expect(account.support_email).to eq('hello@chatwoot.com') + end + end + + it 'returns the support email from ENV if inbox value is empty string' do + account.update(support_email: '') + with_modified_env MAILER_SENDER_EMAIL: 'hello@chatwoot.com' do + expect(account.support_email).to eq('hello@chatwoot.com') + end + end + end + context 'when after_destroy is called' do it 'conv_dpid_seq and camp_dpid_seq_ are deleted' do account = create(:account) From 71ee10c88932276badede8917117a5e610c39124 Mon Sep 17 00:00:00 2001 From: Sojan Date: Mon, 19 Feb 2024 15:58:21 +0530 Subject: [PATCH 2/2] Bump version to 3.6.0 --- config/app.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/app.yml b/config/app.yml index 3ba8851b8..99f2706e9 100644 --- a/config/app.yml +++ b/config/app.yml @@ -1,5 +1,5 @@ shared: &shared - version: '3.5.2' + version: '3.6.0' development: <<: *shared diff --git a/package.json b/package.json index 3213922e8..f7a2f86f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chatwoot/chatwoot", - "version": "3.5.2", + "version": "3.6.0", "license": "MIT", "scripts": { "eslint": "eslint app/**/*.{js,vue}",