2017-08-14 11:56:23 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class Integration::ExchangeController < ApplicationController
|
|
|
|
include Integration::ImportJobBase
|
|
|
|
|
|
|
|
prepend_before_action { authentication_check(permission: 'admin.integration.exchange') }
|
|
|
|
|
|
|
|
def autodiscover
|
|
|
|
answer_with do
|
|
|
|
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
|
|
|
|
|
2017-08-14 11:56:23 +00:00
|
|
|
{
|
2017-09-12 09:47:32 +00:00
|
|
|
endpoint: client.try(:autodiscover).try(:ews_url),
|
2017-08-14 11:56:23 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def folders
|
|
|
|
answer_with do
|
|
|
|
Sequencer.process('Import::Exchange::AvailableFolders',
|
|
|
|
parameters: {
|
|
|
|
ews_config: {
|
|
|
|
endpoint: params[:endpoint],
|
|
|
|
user: params[:user],
|
|
|
|
password: params[:password],
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def mapping
|
|
|
|
answer_with do
|
2017-09-05 15:35:53 +00:00
|
|
|
raise 'Please select at least one folder.' if params[:folders].blank?
|
|
|
|
|
|
|
|
examples = Sequencer.process('Import::Exchange::AttributesExamples',
|
|
|
|
parameters: {
|
|
|
|
ews_folder_ids: params[:folders],
|
|
|
|
ews_config: {
|
|
|
|
endpoint: params[:endpoint],
|
|
|
|
user: params[:user],
|
|
|
|
password: params[:password],
|
|
|
|
}
|
|
|
|
})
|
|
|
|
examples.tap do |result|
|
|
|
|
raise 'No entries found in selected folder(s).' if result[:attributes].blank?
|
|
|
|
end
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# currently a workaround till LDAP is migrated to Sequencer
|
|
|
|
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],
|
|
|
|
ews_config: {
|
|
|
|
endpoint: params[:endpoint],
|
|
|
|
user: params[:user],
|
|
|
|
password: params[:password],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def payload_import
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|