2026-01-02 13:41:09 +00:00
|
|
|
# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
|
2025-01-09 14:47:18 +00:00
|
|
|
|
|
|
|
|
class ChannelsAdmin::MicrosoftGraphController < ChannelsAdmin::BaseController
|
2025-02-18 12:38:47 +00:00
|
|
|
include CanXoauth2EmailChannel
|
|
|
|
|
|
2025-01-09 14:47:18 +00:00
|
|
|
def area
|
|
|
|
|
'MicrosoftGraph::Account'.freeze
|
|
|
|
|
end
|
|
|
|
|
|
2025-02-18 12:38:47 +00:00
|
|
|
def external_credential_name
|
|
|
|
|
'microsoft_graph'.freeze
|
2025-01-09 14:47:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def folders
|
|
|
|
|
channel = Channel.find_by(id: params[:id], area:)
|
2026-04-22 15:23:21 +00:00
|
|
|
raise Exceptions::UnprocessableContent, __('Could not find the channel.') if channel.nil?
|
2025-01-09 14:47:18 +00:00
|
|
|
|
|
|
|
|
channel_mailbox = channel.options.dig('inbound', 'options', 'shared_mailbox') || channel.options.dig('inbound', 'options', 'user')
|
2026-04-22 15:23:21 +00:00
|
|
|
raise Exceptions::UnprocessableContent, __('Could not identify the channel mailbox.') if channel_mailbox.nil?
|
2025-01-09 14:47:18 +00:00
|
|
|
|
|
|
|
|
channel.refresh_xoauth2!(force: true)
|
|
|
|
|
|
|
|
|
|
graph = ::MicrosoftGraph.new access_token: channel.options.dig('auth', 'access_token'), mailbox: channel_mailbox
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
folders = graph.get_message_folders_tree
|
|
|
|
|
rescue ::MicrosoftGraph::ApiError => e
|
|
|
|
|
error = {
|
|
|
|
|
message: e.message,
|
|
|
|
|
code: e.error_code,
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
render json: { folders:, error: }
|
|
|
|
|
end
|
|
|
|
|
end
|