20210106100013_issue_3346_xoauth2_token_not_fetched.rb 642 B

12345678910111213141516171819202122232425
  1. class Issue3346Xoauth2TokenNotFetched < ActiveRecord::Migration[5.2]
  2. def change
  3. # return if it's a new setup
  4. return if !Setting.exists?(name: 'system_init_done')
  5. Channel.where(area: ['Google::Account', 'Microsoft365::Account']).find_each do |channel|
  6. next if skip?(channel)
  7. begin
  8. channel.refresh_xoauth2!
  9. rescue => e
  10. Rails.logger.error e
  11. end
  12. end
  13. end
  14. private
  15. def skip?(channel)
  16. return true if channel.options.blank?
  17. return true if channel.options.dig(:inbound, :options, :auth_type) != 'XOAUTH2'
  18. channel.options[:inbound][:options][:password].present?
  19. end
  20. end