Fixes #3167: Active Google channels cause Email channels to loose email addresses.
This commit is contained in:
parent
3d192af3d0
commit
b6ae957ac2
2 changed files with 22 additions and 1 deletions
|
@ -346,7 +346,15 @@ get instance of channel driver
|
||||||
options[:inbound][:options][:password] = result[:access_token]
|
options[:inbound][:options][:password] = result[:access_token]
|
||||||
options[:outbound][:options][:password] = result[:access_token]
|
options[:outbound][:options][:password] = result[:access_token]
|
||||||
|
|
||||||
save!
|
return if new_record?
|
||||||
|
|
||||||
|
# ATTENTION: We don't want to execute any other callbacks here
|
||||||
|
# because `after_initialize` leaks the current scope of the Channel class
|
||||||
|
# as described here: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-new
|
||||||
|
# which leads to unexpected effects like:
|
||||||
|
# Channel.where(area: 'Google::Account').limit(1).find_each { |c| puts Channel.all.to_sql }
|
||||||
|
# => "SELECT "channels".* FROM "channels" WHERE "channels"."area" = 'Google::Account'"
|
||||||
|
update_column(:options, options) # rubocop:disable Rails/SkipsModelValidations
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.error e
|
logger.error e
|
||||||
raise "Failed to refresh XOAUTH2 access_token of provider '#{options[:auth][:provider]}'! #{e.inspect}"
|
raise "Failed to refresh XOAUTH2 access_token of provider '#{options[:auth][:provider]}'! #{e.inspect}"
|
||||||
|
|
|
@ -62,4 +62,17 @@ RSpec.describe 'Gmail XOAUTH2' do # rubocop:disable RSpec/DescribeClass
|
||||||
expect(result[:result]).to eq('ok')
|
expect(result[:result]).to eq('ok')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when non-Google channels are present' do
|
||||||
|
|
||||||
|
let!(:email_address) { create(:email_address, channel: create(:channel, area: 'Some::Other')) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
channel
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't remove email address assignments" do
|
||||||
|
expect { Channel.where(area: 'Google::Account').find_each {} }.not_to change { email_address.reload.channel_id }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue