2018-01-08 15:29:34 +00:00
|
|
|
module Import
|
|
|
|
class Zendesk
|
|
|
|
module ObjectAttribute
|
|
|
|
class Base
|
|
|
|
|
|
|
|
def initialize(object, name, attribute)
|
|
|
|
|
|
|
|
initialize_data_option(attribute)
|
|
|
|
init_callback(attribute)
|
|
|
|
|
|
|
|
add(object, name, attribute)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def init_callback(_attribute); end
|
|
|
|
|
|
|
|
def add(object, name, attribute)
|
|
|
|
ObjectManager::Attribute.add( attribute_config(object, name, attribute) )
|
|
|
|
ObjectManager::Attribute.migration_execute(false)
|
|
|
|
rescue => e
|
|
|
|
# rubocop:disable Style/SpecialGlobalVars
|
|
|
|
raise $!, "Problem with ObjectManager Attribute '#{name}': #{$!}", $!.backtrace
|
2018-04-12 14:57:37 +00:00
|
|
|
# rubocop:enable Style/SpecialGlobalVars
|
2018-01-08 15:29:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def attribute_config(object, name, attribute)
|
|
|
|
{
|
2018-12-14 01:59:19 +00:00
|
|
|
object: object.to_s,
|
2018-01-08 15:29:34 +00:00
|
|
|
name: name,
|
|
|
|
display: attribute.title,
|
|
|
|
data_type: data_type(attribute),
|
|
|
|
data_option: @data_option,
|
|
|
|
editable: !attribute.removable,
|
|
|
|
active: attribute.active,
|
|
|
|
screens: screens(attribute),
|
|
|
|
position: attribute.position,
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def screens(attribute)
|
|
|
|
config = {
|
|
|
|
view: {
|
|
|
|
'-all-' => {
|
|
|
|
shown: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return config if !attribute.visible_in_portal && attribute.required_in_portal
|
|
|
|
|
|
|
|
{
|
|
|
|
edit: {
|
|
|
|
Customer: {
|
|
|
|
shown: attribute.visible_in_portal,
|
2018-12-19 17:31:51 +00:00
|
|
|
null: !attribute.required_in_portal,
|
2018-01-08 15:29:34 +00:00
|
|
|
},
|
|
|
|
}.merge(config)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize_data_option(attribute)
|
|
|
|
@data_option = {
|
|
|
|
null: !attribute.required,
|
|
|
|
note: attribute.description,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def data_type(attribute)
|
|
|
|
attribute.type
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|