20210106100013_issue_3346_xoauth2_token_not_fetched.rb 719 B

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