exchange_controller.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Integration::ExchangeController < ApplicationController
  3. include Integration::ImportJobBase
  4. prepend_before_action { authentication_check(permission: 'admin.integration.exchange') }
  5. def autodiscover
  6. answer_with do
  7. client = Autodiscover::Client.new(
  8. email: params[:user],
  9. password: params[:password],
  10. )
  11. if params[:disable_ssl_verify]
  12. client.http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
  13. end
  14. {
  15. endpoint: client.try(:autodiscover).try(:ews_url),
  16. }
  17. end
  18. end
  19. def folders
  20. answer_with do
  21. Sequencer.process('Import::Exchange::AvailableFolders',
  22. parameters: {
  23. ews_config: ews_config
  24. })
  25. end
  26. end
  27. def mapping
  28. answer_with do
  29. raise 'Please select at least one folder.' if params[:folders].blank?
  30. examples = Sequencer.process('Import::Exchange::AttributesExamples',
  31. parameters: {
  32. ews_folder_ids: params[:folders],
  33. ews_config: ews_config
  34. })
  35. examples.tap do |result|
  36. raise 'No entries found in selected folder(s).' if result[:attributes].blank?
  37. end
  38. end
  39. end
  40. private
  41. # currently a workaround till LDAP is migrated to Sequencer
  42. def payload_dry_run
  43. {
  44. ews_attributes: params[:attributes].permit!.to_h,
  45. ews_folder_ids: params[:folders],
  46. ews_config: ews_config
  47. }
  48. end
  49. def payload_import
  50. nil
  51. end
  52. def ews_config
  53. {
  54. disable_ssl_verify: params[:disable_ssl_verify],
  55. endpoint: params[:endpoint],
  56. user: params[:user],
  57. password: params[:password],
  58. }
  59. end
  60. end