2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2021-05-25 12:30:12 +00:00
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Freshdesk
|
|
|
|
module ObjectAttribute
|
|
|
|
class Config < Sequencer::Unit::Base
|
|
|
|
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
|
|
|
|
|
|
|
|
skip_any_action
|
|
|
|
|
|
|
|
uses :resource, :sanitized_name, :model_class
|
|
|
|
provides :config
|
|
|
|
|
|
|
|
def process
|
|
|
|
state.provide(:config) do
|
|
|
|
{
|
|
|
|
object: model_class.to_s,
|
2022-04-25 10:55:32 +00:00
|
|
|
name: DEFAULT_FIELD_NAME_MAP[resource['name']] || sanitized_name,
|
2021-05-25 12:30:12 +00:00
|
|
|
display: resource['label'],
|
|
|
|
data_type: data_type,
|
|
|
|
data_option: data_option,
|
|
|
|
editable: true,
|
|
|
|
active: true,
|
|
|
|
screens: screens,
|
|
|
|
position: resource['position'],
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
DATA_TYPE_MAP = {
|
2021-07-12 07:51:07 +00:00
|
|
|
'custom_date' => 'date',
|
|
|
|
'custom_checkbox' => 'boolean',
|
|
|
|
'custom_dropdown' => 'select',
|
|
|
|
'custom_text' => 'input',
|
|
|
|
'custom_number' => 'integer',
|
|
|
|
'custom_paragraph' => 'input',
|
|
|
|
'custom_decimal' => 'input', # Don't use 'integer' as it would cut off the fractional part.
|
|
|
|
'custom_url' => 'input',
|
|
|
|
'custom_phone_number' => 'input',
|
2022-04-25 10:55:32 +00:00
|
|
|
'default_ticket_type' => 'select',
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
DEFAULT_FIELD_NAME_MAP = {
|
|
|
|
'ticket_type' => 'type',
|
2021-05-25 12:30:12 +00:00
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def data_type
|
|
|
|
@data_type ||= DATA_TYPE_MAP[resource['type']]
|
2021-07-12 07:51:07 +00:00
|
|
|
raise "The custom field type '#{resource['type']}' cannot be mapped to an internal field, aborting." if !@data_type
|
|
|
|
|
|
|
|
@data_type
|
2021-05-25 12:30:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def data_option
|
|
|
|
{
|
|
|
|
null: true,
|
|
|
|
note: '',
|
|
|
|
}.merge(data_type_options)
|
|
|
|
end
|
|
|
|
|
2021-07-12 07:51:07 +00:00
|
|
|
def data_type_options # rubocop:disable Metrics/CyclomaticComplexity
|
2021-05-25 12:30:12 +00:00
|
|
|
|
|
|
|
case data_type
|
|
|
|
when 'date'
|
|
|
|
{
|
|
|
|
future: true,
|
|
|
|
past: true,
|
|
|
|
diff: 0,
|
|
|
|
}
|
|
|
|
when 'boolean'
|
|
|
|
{
|
|
|
|
default: false,
|
|
|
|
options: {
|
|
|
|
true => 'yes',
|
|
|
|
false => 'no',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
when 'select'
|
|
|
|
{
|
|
|
|
default: '',
|
|
|
|
options: options,
|
|
|
|
}
|
|
|
|
when 'input'
|
2021-07-12 07:51:07 +00:00
|
|
|
case resource['type']
|
|
|
|
when 'custom_phone_number'
|
|
|
|
{
|
|
|
|
type: 'tel',
|
|
|
|
maxlength: 100,
|
|
|
|
}
|
|
|
|
when 'custom_url'
|
|
|
|
{
|
|
|
|
type: 'url',
|
|
|
|
maxlength: 250,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
maxlength: 255,
|
|
|
|
}
|
|
|
|
end
|
2021-05-25 12:30:12 +00:00
|
|
|
when 'integer'
|
|
|
|
{
|
|
|
|
min: 0,
|
|
|
|
max: 999_999_999,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def screens
|
|
|
|
{
|
|
|
|
view: {
|
|
|
|
'-all-' => {
|
|
|
|
shown: true,
|
|
|
|
null: true,
|
|
|
|
},
|
|
|
|
Customer: {
|
|
|
|
shown: false,
|
|
|
|
null: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
'-all-' => {
|
|
|
|
shown: true,
|
|
|
|
null: true,
|
|
|
|
},
|
|
|
|
Customer: {
|
|
|
|
shown: false,
|
|
|
|
null: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def options
|
|
|
|
resource['choices'].each_with_object({}) do |choice, result|
|
|
|
|
result[choice] = choice
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|