2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2017-08-14 11:56:23 +00:00
|
|
|
|
|
|
|
class Integration::ExchangeController < ApplicationController
|
|
|
|
include Integration::ImportJobBase
|
|
|
|
|
2020-03-19 09:39:51 +00:00
|
|
|
prepend_before_action { authentication_check && authorize! }
|
2017-08-14 11:56:23 +00:00
|
|
|
|
|
|
|
def autodiscover
|
|
|
|
answer_with do
|
2021-07-05 13:38:40 +00:00
|
|
|
require 'autodiscover' # Only load this gem when it is really used.
|
2017-08-14 11:56:23 +00:00
|
|
|
client = Autodiscover::Client.new(
|
|
|
|
email: params[:user],
|
|
|
|
password: params[:password],
|
|
|
|
)
|
2017-10-04 14:18:13 +00:00
|
|
|
|
|
|
|
if params[:disable_ssl_verify]
|
|
|
|
client.http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
|
|
end
|
|
|
|
|
2018-07-11 03:01:36 +00:00
|
|
|
begin
|
|
|
|
{ endpoint: client.autodiscover&.ews_url }
|
|
|
|
rescue Errno::EADDRNOTAVAIL
|
|
|
|
{}
|
|
|
|
end
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def folders
|
|
|
|
answer_with do
|
|
|
|
Sequencer.process('Import::Exchange::AvailableFolders',
|
2018-07-10 05:32:24 +00:00
|
|
|
parameters: { ews_config: ews_config })
|
|
|
|
.tap do |res|
|
2021-11-15 15:58:19 +00:00
|
|
|
raise __('No folders found for given user credentials.') if res[:folders].blank?
|
2018-07-10 05:32:24 +00:00
|
|
|
end
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def mapping
|
|
|
|
answer_with do
|
2021-11-15 15:58:19 +00:00
|
|
|
raise __('Please select at least one folder.') if params[:folders].blank?
|
2017-09-05 15:35:53 +00:00
|
|
|
|
2018-07-10 05:32:24 +00:00
|
|
|
Sequencer.process('Import::Exchange::AttributesExamples',
|
|
|
|
parameters: { ews_folder_ids: params[:folders],
|
|
|
|
ews_config: ews_config })
|
|
|
|
.tap do |res|
|
2021-11-15 15:58:19 +00:00
|
|
|
raise __('No entries found in selected folder(s).') if res[:attributes].blank?
|
2018-07-10 05:32:24 +00:00
|
|
|
end
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def payload_dry_run
|
|
|
|
{
|
2017-10-24 15:00:48 +00:00
|
|
|
ews_attributes: params[:attributes].permit!.to_h,
|
2017-08-14 11:56:23 +00:00
|
|
|
ews_folder_ids: params[:folders],
|
2017-11-03 10:40:11 +00:00
|
|
|
ews_config: ews_config
|
2017-08-14 11:56:23 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-11-03 10:40:11 +00:00
|
|
|
def ews_config
|
|
|
|
{
|
|
|
|
disable_ssl_verify: params[:disable_ssl_verify],
|
|
|
|
endpoint: params[:endpoint],
|
|
|
|
user: params[:user],
|
|
|
|
password: params[:password],
|
|
|
|
}
|
|
|
|
end
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|