2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
class ObjectManager::Attribute < ApplicationModel
|
2017-05-02 15:21:13 +00:00
|
|
|
include ChecksClientNotification
|
2017-05-14 18:41:25 +00:00
|
|
|
include CanSeed
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
DATA_TYPES = %w[
|
|
|
|
input
|
|
|
|
user_autocompletion
|
|
|
|
checkbox
|
|
|
|
select
|
|
|
|
tree_select
|
|
|
|
datetime
|
|
|
|
date
|
|
|
|
tag
|
|
|
|
richtext
|
|
|
|
textarea
|
|
|
|
integer
|
|
|
|
autocompletion_ajax
|
|
|
|
boolean
|
|
|
|
user_permission
|
|
|
|
active
|
|
|
|
].freeze
|
|
|
|
|
2021-08-18 04:48:16 +00:00
|
|
|
VALIDATE_INTEGER_MIN = -2_147_483_647
|
|
|
|
VALIDATE_INTEGER_MAX = 2_147_483_647
|
|
|
|
VALIDATE_INTEGER_REGEXP = %r{^-?\d+$}.freeze
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
self.table_name = 'object_manager_attributes'
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2019-07-04 11:16:55 +00:00
|
|
|
belongs_to :object_lookup, optional: true
|
2018-04-12 14:57:37 +00:00
|
|
|
|
|
|
|
validates :name, presence: true
|
2020-02-18 19:51:31 +00:00
|
|
|
validates :data_type, inclusion: { in: DATA_TYPES, msg: '%{value} is not a valid data type' } # rubocop:disable Style/FormatStringToken
|
2020-11-24 09:32:07 +00:00
|
|
|
validate :inactive_must_be_unused_by_references, unless: :active?
|
2018-08-24 01:39:17 +00:00
|
|
|
validate :data_option_must_have_appropriate_values
|
|
|
|
validate :data_type_must_not_change, on: :update
|
2018-04-12 14:57:37 +00:00
|
|
|
|
|
|
|
store :screens
|
|
|
|
store :data_option
|
|
|
|
store :data_option_new
|
2016-05-19 09:21:50 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
before_validation :set_base_options
|
2018-06-29 06:14:18 +00:00
|
|
|
|
2021-08-17 16:37:16 +00:00
|
|
|
scope :active, -> { where(active: true) }
|
|
|
|
scope :editable, -> { where(editable: true) }
|
|
|
|
scope :for_object, lambda { |name_or_klass|
|
|
|
|
id = ObjectLookup.lookup(name: name_or_klass.to_s)
|
|
|
|
where(object_lookup_id: id)
|
|
|
|
}
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
list of all attributes
|
|
|
|
|
|
|
|
result = ObjectManager::Attribute.list_full
|
|
|
|
|
|
|
|
result = [
|
|
|
|
{
|
|
|
|
name: 'some name',
|
|
|
|
display: '...',
|
|
|
|
}.
|
|
|
|
],
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.list_full
|
2016-05-28 22:04:26 +00:00
|
|
|
result = ObjectManager::Attribute.all.order('position ASC, name ASC')
|
2018-06-20 12:13:35 +00:00
|
|
|
references = ObjectManager::Attribute.attribute_to_references_hash
|
2016-05-19 09:21:50 +00:00
|
|
|
attributes = []
|
2017-10-01 12:25:52 +00:00
|
|
|
result.each do |item|
|
2016-05-19 09:21:50 +00:00
|
|
|
attribute = item.attributes
|
|
|
|
attribute[:object] = ObjectLookup.by_id(item.object_lookup_id)
|
|
|
|
attribute.delete('object_lookup_id')
|
2018-06-20 12:13:35 +00:00
|
|
|
|
|
|
|
# an attribute is deletable if it is both editable and not referenced by other Objects (Triggers, Overviews, Schedulers)
|
|
|
|
deletable = true
|
|
|
|
not_deletable_reason = ''
|
|
|
|
if ObjectManager::Attribute.attribute_used_by_references?(attribute[:object], attribute['name'], references)
|
|
|
|
deletable = false
|
|
|
|
not_deletable_reason = ObjectManager::Attribute.attribute_used_by_references_humaniced(attribute[:object], attribute['name'], references)
|
|
|
|
end
|
|
|
|
attribute[:deletable] = attribute['editable'] && deletable == true
|
|
|
|
if not_deletable_reason.present?
|
|
|
|
attribute[:not_deletable_reason] = "This attribute is referenced by #{not_deletable_reason} and thus cannot be deleted!"
|
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
attributes.push attribute
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
add a new attribute entry for an object
|
|
|
|
|
|
|
|
ObjectManager::Attribute.add(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'group_id',
|
|
|
|
display: 'Group',
|
|
|
|
data_type: 'select',
|
|
|
|
data_option: {
|
|
|
|
relation: 'Group',
|
2017-06-16 20:43:09 +00:00
|
|
|
relation_condition: { access: 'full' },
|
2016-05-19 09:21:50 +00:00
|
|
|
multiple: false,
|
|
|
|
null: true,
|
|
|
|
translate: false,
|
|
|
|
},
|
|
|
|
active: true,
|
|
|
|
screens: {
|
|
|
|
create: {
|
|
|
|
'-all-' => {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
edit: {
|
2017-04-03 21:38:55 +00:00
|
|
|
'ticket.agent' => {
|
2016-05-19 09:21:50 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
position: 20,
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_at: '2014-06-04 10:00:00',
|
|
|
|
updated_at: '2014-06-04 10:00:00',
|
|
|
|
|
2019-09-12 11:34:37 +00:00
|
|
|
force: true
|
2016-05-19 09:21:50 +00:00
|
|
|
editable: false,
|
|
|
|
to_migrate: false,
|
|
|
|
to_create: false,
|
|
|
|
to_delete: false,
|
2016-05-29 17:48:28 +00:00
|
|
|
to_config: false,
|
2016-05-19 09:21:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
preserved name are
|
|
|
|
|
|
|
|
/(_id|_ids)$/
|
|
|
|
|
2016-05-25 09:10:33 +00:00
|
|
|
possible types
|
|
|
|
|
|
|
|
# input
|
|
|
|
|
|
|
|
data_type: 'input',
|
|
|
|
data_option: {
|
|
|
|
default: '',
|
|
|
|
type: 'text', # text|email|url|tel
|
|
|
|
maxlength: 200,
|
|
|
|
null: true,
|
|
|
|
note: 'some additional comment', # optional
|
2019-08-12 07:53:24 +00:00
|
|
|
link_template: '', # optional
|
2016-05-25 09:10:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
# select
|
|
|
|
|
|
|
|
data_type: 'select',
|
|
|
|
data_option: {
|
|
|
|
default: 'aa',
|
|
|
|
options: {
|
|
|
|
'aa' => 'aa (comment)',
|
|
|
|
'bb' => 'bb (comment)',
|
|
|
|
},
|
2016-05-29 17:48:28 +00:00
|
|
|
maxlength: 200,
|
2016-05-26 08:14:51 +00:00
|
|
|
nulloption: true,
|
2016-05-25 09:10:33 +00:00
|
|
|
null: false,
|
|
|
|
multiple: false, # currently only "false" supported
|
|
|
|
translate: true, # optional
|
|
|
|
note: 'some additional comment', # optional
|
2019-08-12 07:53:24 +00:00
|
|
|
link_template: '', # optional
|
2016-05-25 09:10:33 +00:00
|
|
|
},
|
|
|
|
|
2017-06-20 15:08:59 +00:00
|
|
|
# tree_select
|
|
|
|
|
|
|
|
data_type: 'tree_select',
|
|
|
|
data_option: {
|
|
|
|
default: 'aa',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
'value' => 'aa',
|
|
|
|
'name' => 'aa (comment)',
|
|
|
|
'children' => [
|
|
|
|
{
|
|
|
|
'value' => 'aaa',
|
|
|
|
'name' => 'aaa (comment)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'value' => 'aab',
|
|
|
|
'name' => 'aab (comment)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'value' => 'aac',
|
|
|
|
'name' => 'aac (comment)',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'value' => 'bb',
|
|
|
|
'name' => 'bb (comment)',
|
|
|
|
'children' => [
|
|
|
|
{
|
|
|
|
'value' => 'bba',
|
|
|
|
'name' => 'aaa (comment)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'value' => 'bbb',
|
|
|
|
'name' => 'bbb (comment)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'value' => 'bbc',
|
|
|
|
'name' => 'bbc (comment)',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
],
|
|
|
|
maxlength: 200,
|
|
|
|
nulloption: true,
|
|
|
|
null: false,
|
|
|
|
multiple: false, # currently only "false" supported
|
|
|
|
translate: true, # optional
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
2016-05-25 09:10:33 +00:00
|
|
|
# checkbox
|
|
|
|
|
|
|
|
data_type: 'checkbox',
|
|
|
|
data_option: {
|
|
|
|
default: 'aa',
|
|
|
|
options: {
|
|
|
|
'aa' => 'aa (comment)',
|
|
|
|
'bb' => 'bb (comment)',
|
|
|
|
},
|
|
|
|
null: false,
|
|
|
|
translate: true, # optional
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
|
|
|
# integer
|
|
|
|
|
|
|
|
data_type: 'integer',
|
|
|
|
data_option: {
|
|
|
|
default: 5,
|
|
|
|
min: 15,
|
|
|
|
max: 999,
|
|
|
|
null: false,
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
|
|
|
# boolean
|
|
|
|
|
|
|
|
data_type: 'boolean',
|
|
|
|
data_option: {
|
|
|
|
default: true,
|
|
|
|
options: {
|
|
|
|
true => 'aa',
|
|
|
|
false => 'bb',
|
|
|
|
},
|
|
|
|
null: false,
|
|
|
|
translate: true, # optional
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
|
|
|
# datetime
|
|
|
|
|
|
|
|
data_type: 'datetime',
|
|
|
|
data_option: {
|
|
|
|
future: true, # true|false
|
|
|
|
past: true, # true|false
|
|
|
|
diff: 12, # in hours
|
|
|
|
null: false,
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
|
|
|
# date
|
|
|
|
|
|
|
|
data_type: 'date',
|
|
|
|
data_option: {
|
|
|
|
future: true, # true|false
|
|
|
|
past: true, # true|false
|
|
|
|
diff: 15, # in days
|
|
|
|
null: false,
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
|
|
|
# textarea
|
|
|
|
|
|
|
|
data_type: 'textarea',
|
|
|
|
data_option: {
|
|
|
|
default: '',
|
|
|
|
rows: 15,
|
|
|
|
null: false,
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
|
|
|
# richtext
|
|
|
|
|
|
|
|
data_type: 'richtext',
|
|
|
|
data_option: {
|
|
|
|
default: '',
|
|
|
|
null: false,
|
|
|
|
note: 'some additional comment', # optional
|
|
|
|
},
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
=end
|
|
|
|
|
|
|
|
def self.add(data)
|
|
|
|
|
|
|
|
force = data[:force]
|
|
|
|
data.delete(:force)
|
|
|
|
|
|
|
|
# lookups
|
|
|
|
if data[:object]
|
|
|
|
data[:object_lookup_id] = ObjectLookup.by_name(data[:object])
|
|
|
|
end
|
|
|
|
data.delete(:object)
|
|
|
|
|
|
|
|
data[:name].downcase!
|
|
|
|
|
|
|
|
# check new entry - is needed
|
|
|
|
record = ObjectManager::Attribute.find_by(
|
|
|
|
object_lookup_id: data[:object_lookup_id],
|
2018-12-19 17:31:51 +00:00
|
|
|
name: data[:name],
|
2016-05-19 09:21:50 +00:00
|
|
|
)
|
|
|
|
if record
|
|
|
|
|
|
|
|
# do not allow to overwrite certain attributes
|
|
|
|
if !force
|
|
|
|
data.delete(:editable)
|
|
|
|
data.delete(:to_create)
|
|
|
|
data.delete(:to_migrate)
|
|
|
|
data.delete(:to_delete)
|
2016-05-29 17:48:28 +00:00
|
|
|
data.delete(:to_config)
|
|
|
|
end
|
|
|
|
|
|
|
|
# if data_option has changed, store it for next migration
|
|
|
|
if !force
|
2017-11-23 08:09:44 +00:00
|
|
|
%i[name display data_type position active].each do |key|
|
2017-04-30 13:14:17 +00:00
|
|
|
next if record[key] == data[key]
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-01-25 08:33:30 +00:00
|
|
|
record[:data_option_new] = data[:data_option] if data[:data_option] # bring the data options over as well, when there are changes to the fields above
|
2017-04-30 13:14:17 +00:00
|
|
|
data[:to_config] = true
|
|
|
|
break
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2018-01-25 08:33:30 +00:00
|
|
|
|
2016-05-29 17:48:28 +00:00
|
|
|
if record[:data_option] != data[:data_option]
|
|
|
|
|
|
|
|
# do we need a database migration?
|
2019-09-12 11:34:37 +00:00
|
|
|
if record[:data_option][:maxlength] && data[:data_option][:maxlength] && record[:data_option][:maxlength].to_s != data[:data_option][:maxlength].to_s
|
2016-05-29 17:48:28 +00:00
|
|
|
data[:to_migrate] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
record[:data_option_new] = data[:data_option]
|
|
|
|
data.delete(:data_option)
|
|
|
|
data[:to_config] = true
|
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
2016-05-29 17:48:28 +00:00
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
# update attributes
|
2017-10-01 12:25:52 +00:00
|
|
|
data.each do |key, value|
|
2016-05-19 09:21:50 +00:00
|
|
|
record[key.to_sym] = value
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
|
|
|
|
# check editable & name
|
|
|
|
if !force
|
|
|
|
record.check_editable
|
|
|
|
record.check_name
|
|
|
|
end
|
|
|
|
record.save!
|
|
|
|
return record
|
|
|
|
end
|
|
|
|
|
|
|
|
# do not allow to overwrite certain attributes
|
|
|
|
if !force
|
|
|
|
data[:editable] = true
|
|
|
|
data[:to_create] = true
|
|
|
|
data[:to_migrate] = true
|
|
|
|
data[:to_delete] = false
|
|
|
|
end
|
|
|
|
|
|
|
|
record = ObjectManager::Attribute.new(data)
|
|
|
|
|
|
|
|
# check editable & name
|
|
|
|
if !force
|
|
|
|
record.check_editable
|
|
|
|
record.check_name
|
|
|
|
end
|
|
|
|
record.save!
|
|
|
|
record
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
remove attribute entry for an object
|
|
|
|
|
|
|
|
ObjectManager::Attribute.remove(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'group_id',
|
|
|
|
)
|
|
|
|
|
|
|
|
use "force: true" to delete also not editable fields
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.remove(data)
|
|
|
|
|
|
|
|
# lookups
|
|
|
|
if data[:object]
|
|
|
|
data[:object_lookup_id] = ObjectLookup.by_name(data[:object])
|
2018-06-20 12:13:35 +00:00
|
|
|
elsif data[:object_lookup_id]
|
|
|
|
data[:object] = ObjectLookup.by_id(data[:object_lookup_id])
|
|
|
|
else
|
2020-03-12 08:23:19 +00:00
|
|
|
raise 'need object or object_lookup_id param!'
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
|
2016-05-20 01:49:30 +00:00
|
|
|
data[:name].downcase!
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
# check newest entry - is needed
|
|
|
|
record = ObjectManager::Attribute.find_by(
|
|
|
|
object_lookup_id: data[:object_lookup_id],
|
2018-12-19 17:31:51 +00:00
|
|
|
name: data[:name],
|
2016-05-19 09:21:50 +00:00
|
|
|
)
|
|
|
|
if !record
|
2020-03-12 08:23:19 +00:00
|
|
|
raise "No such field #{data[:object]}.#{data[:name]}"
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if !data[:force] && !record.editable
|
2020-03-12 08:23:19 +00:00
|
|
|
raise "#{data[:object]}.#{data[:name]} can't be removed!"
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
|
2018-06-20 12:13:35 +00:00
|
|
|
# check to make sure that no triggers, overviews, or schedulers references this attribute
|
|
|
|
if ObjectManager::Attribute.attribute_used_by_references?(data[:object], data[:name])
|
|
|
|
text = ObjectManager::Attribute.attribute_used_by_references_humaniced(data[:object], data[:name])
|
2020-03-12 08:23:19 +00:00
|
|
|
raise "#{data[:object]}.#{data[:name]} is referenced by #{text} and thus cannot be deleted!"
|
2018-06-20 12:13:35 +00:00
|
|
|
end
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
# if record is to create, just destroy it
|
|
|
|
if record.to_create
|
|
|
|
record.destroy
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
record.to_delete = true
|
|
|
|
record.save
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get the attribute model based on object and name
|
|
|
|
|
|
|
|
attribute = ObjectManager::Attribute.get(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'group_id',
|
|
|
|
)
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.get(data)
|
|
|
|
|
|
|
|
# lookups
|
|
|
|
if data[:object]
|
|
|
|
data[:object_lookup_id] = ObjectLookup.by_name(data[:object])
|
|
|
|
end
|
|
|
|
|
|
|
|
data[:name].downcase!
|
|
|
|
|
|
|
|
ObjectManager::Attribute.find_by(
|
|
|
|
object_lookup_id: data[:object_lookup_id],
|
2018-12-19 17:31:51 +00:00
|
|
|
name: data[:name],
|
2016-05-19 09:21:50 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
discard migration changes
|
|
|
|
|
|
|
|
ObjectManager::Attribute.discard_changes
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
true|false
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.discard_changes
|
2020-12-10 09:13:57 +00:00
|
|
|
ObjectManager::Attribute.where(to_create: true).each(&:destroy)
|
2017-10-01 12:25:52 +00:00
|
|
|
ObjectManager::Attribute.where('to_delete = ? OR to_config = ?', true, true).each do |attribute|
|
2016-05-29 17:48:28 +00:00
|
|
|
attribute.to_migrate = false
|
2016-05-19 09:21:50 +00:00
|
|
|
attribute.to_delete = false
|
2016-05-29 17:48:28 +00:00
|
|
|
attribute.to_config = false
|
|
|
|
attribute.data_option_new = {}
|
2016-05-19 09:21:50 +00:00
|
|
|
attribute.save
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
check if we have pending migrations of attributes
|
|
|
|
|
|
|
|
ObjectManager::Attribute.pending_migration?
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
true|false
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.pending_migration?
|
2017-11-23 08:09:44 +00:00
|
|
|
return false if migrations.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get list of pending attributes migrations
|
|
|
|
|
|
|
|
ObjectManager::Attribute.migrations
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
[record1, record2, ...]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.migrations
|
2016-05-29 17:48:28 +00:00
|
|
|
ObjectManager::Attribute.where('to_create = ? OR to_migrate = ? OR to_delete = ? OR to_config = ?', true, true, true, true)
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
start migration of pending attribute migrations
|
|
|
|
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
[record1, record2, ...]
|
|
|
|
|
2016-05-27 14:25:25 +00:00
|
|
|
to send no browser reload event, pass false
|
|
|
|
|
|
|
|
ObjectManager::Attribute.migration_execute(false)
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
=end
|
|
|
|
|
2016-05-27 14:25:25 +00:00
|
|
|
def self.migration_execute(send_event = true)
|
2016-05-19 09:21:50 +00:00
|
|
|
|
|
|
|
# check if field already exists
|
2016-05-29 17:48:28 +00:00
|
|
|
execute_db_count = 0
|
|
|
|
execute_config_count = 0
|
2017-10-01 12:25:52 +00:00
|
|
|
migrations.each do |attribute|
|
2019-01-06 18:41:29 +00:00
|
|
|
model = attribute.object_lookup.name.constantize
|
2016-05-19 09:21:50 +00:00
|
|
|
|
|
|
|
# remove field
|
|
|
|
if attribute.to_delete
|
|
|
|
if model.column_names.include?(attribute.name)
|
|
|
|
ActiveRecord::Migration.remove_column model.table_name, attribute.name
|
2016-05-26 08:14:51 +00:00
|
|
|
reset_database_info(model)
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
2016-05-29 17:48:28 +00:00
|
|
|
execute_db_count += 1
|
2016-05-19 09:21:50 +00:00
|
|
|
attribute.destroy
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2016-05-29 17:48:28 +00:00
|
|
|
# config changes
|
|
|
|
if attribute.to_config
|
|
|
|
execute_config_count += 1
|
2018-08-23 07:44:32 +00:00
|
|
|
if attribute.data_type == 'select' && attribute.data_option[:options]
|
2018-07-26 09:16:34 +00:00
|
|
|
historical_options = attribute.data_option[:historical_options] || {}
|
|
|
|
historical_options.update(attribute.data_option[:options])
|
|
|
|
historical_options.update(attribute.data_option_new[:options])
|
|
|
|
attribute.data_option_new[:historical_options] = historical_options
|
|
|
|
end
|
2016-05-29 17:48:28 +00:00
|
|
|
attribute.data_option = attribute.data_option_new
|
|
|
|
attribute.data_option_new = {}
|
|
|
|
attribute.to_config = false
|
|
|
|
attribute.save!
|
|
|
|
next if !attribute.to_create && !attribute.to_migrate && !attribute.to_delete
|
|
|
|
end
|
|
|
|
|
2018-08-23 07:44:32 +00:00
|
|
|
if attribute.data_type == 'select' && attribute.data_option[:options]
|
2019-09-12 11:34:37 +00:00
|
|
|
attribute.data_option[:historical_options] = attribute.data_option[:options]
|
2018-07-26 09:16:34 +00:00
|
|
|
end
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
data_type = nil
|
2020-07-13 12:46:08 +00:00
|
|
|
case attribute.data_type
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^input|select|tree_select|richtext|textarea|checkbox$}
|
2016-05-19 09:21:50 +00:00
|
|
|
data_type = :string
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^integer|user_autocompletion$}
|
2016-05-19 13:01:02 +00:00
|
|
|
data_type = :integer
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^boolean|active$}
|
2016-05-19 09:21:50 +00:00
|
|
|
data_type = :boolean
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^datetime$}
|
2016-05-19 09:21:50 +00:00
|
|
|
data_type = :datetime
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^date$}
|
2016-05-19 09:21:50 +00:00
|
|
|
data_type = :date
|
|
|
|
end
|
|
|
|
|
|
|
|
# change field
|
|
|
|
if model.column_names.include?(attribute.name)
|
2020-07-13 12:46:08 +00:00
|
|
|
case attribute.data_type
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^input|select|tree_select|richtext|textarea|checkbox$}
|
2016-05-19 09:21:50 +00:00
|
|
|
ActiveRecord::Migration.change_column(
|
|
|
|
model.table_name,
|
|
|
|
attribute.name,
|
|
|
|
data_type,
|
2019-09-12 11:34:37 +00:00
|
|
|
limit: attribute.data_option[:maxlength],
|
|
|
|
null: true
|
2016-05-19 09:21:50 +00:00
|
|
|
)
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^integer|user_autocompletion|datetime|date$}, %r{^boolean|active$}
|
2016-05-19 13:01:02 +00:00
|
|
|
ActiveRecord::Migration.change_column(
|
|
|
|
model.table_name,
|
|
|
|
attribute.name,
|
|
|
|
data_type,
|
|
|
|
default: attribute.data_option[:default],
|
2018-12-19 17:31:51 +00:00
|
|
|
null: true
|
2016-05-19 13:01:02 +00:00
|
|
|
)
|
2016-05-19 09:21:50 +00:00
|
|
|
else
|
|
|
|
raise "Unknown attribute.data_type '#{attribute.data_type}', can't update attribute"
|
|
|
|
end
|
|
|
|
|
|
|
|
# restart processes
|
2017-04-30 13:14:17 +00:00
|
|
|
attribute.to_create = false
|
2016-05-19 09:21:50 +00:00
|
|
|
attribute.to_migrate = false
|
2017-04-30 13:14:17 +00:00
|
|
|
attribute.to_delete = false
|
2016-05-19 09:21:50 +00:00
|
|
|
attribute.save!
|
2016-05-26 08:14:51 +00:00
|
|
|
reset_database_info(model)
|
2016-05-29 17:48:28 +00:00
|
|
|
execute_db_count += 1
|
2016-05-19 09:21:50 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
# create field
|
2020-07-13 12:46:08 +00:00
|
|
|
case attribute.data_type
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^input|select|tree_select|richtext|textarea|checkbox$}
|
2016-05-19 09:21:50 +00:00
|
|
|
ActiveRecord::Migration.add_column(
|
|
|
|
model.table_name,
|
|
|
|
attribute.name,
|
|
|
|
data_type,
|
2019-09-12 11:34:37 +00:00
|
|
|
limit: attribute.data_option[:maxlength],
|
|
|
|
null: true
|
2016-05-19 09:21:50 +00:00
|
|
|
)
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^integer|user_autocompletion$}, %r{^boolean|active$}, %r{^datetime|date$}
|
2016-05-19 09:21:50 +00:00
|
|
|
ActiveRecord::Migration.add_column(
|
|
|
|
model.table_name,
|
|
|
|
attribute.name,
|
|
|
|
data_type,
|
|
|
|
default: attribute.data_option[:default],
|
2018-12-19 17:31:51 +00:00
|
|
|
null: true
|
2016-05-19 09:21:50 +00:00
|
|
|
)
|
|
|
|
else
|
|
|
|
raise "Unknown attribute.data_type '#{attribute.data_type}', can't create attribute"
|
|
|
|
end
|
|
|
|
|
|
|
|
# restart processes
|
|
|
|
attribute.to_create = false
|
|
|
|
attribute.to_migrate = false
|
|
|
|
attribute.to_delete = false
|
|
|
|
attribute.save!
|
|
|
|
|
2016-05-26 08:14:51 +00:00
|
|
|
reset_database_info(model)
|
2016-05-29 17:48:28 +00:00
|
|
|
execute_db_count += 1
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
|
2016-05-26 21:40:10 +00:00
|
|
|
# sent maintenance message to clients
|
2016-05-29 17:48:28 +00:00
|
|
|
if send_event
|
2016-07-26 22:02:28 +00:00
|
|
|
if execute_db_count.nonzero?
|
2016-05-29 17:48:28 +00:00
|
|
|
if ENV['APP_RESTART_CMD']
|
|
|
|
AppVersion.set(true, 'restart_auto')
|
|
|
|
sleep 4
|
2018-12-13 14:40:22 +00:00
|
|
|
AppVersionRestartJob.perform_later(ENV['APP_RESTART_CMD'])
|
2016-05-29 17:48:28 +00:00
|
|
|
else
|
|
|
|
AppVersion.set(true, 'restart_manual')
|
|
|
|
end
|
2016-07-26 22:02:28 +00:00
|
|
|
elsif execute_config_count.nonzero?
|
2016-05-29 17:48:28 +00:00
|
|
|
AppVersion.set(true, 'config_changed')
|
2016-05-26 21:40:10 +00:00
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2018-06-20 12:13:35 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
where attributes are used by triggers, overviews or schedulers
|
|
|
|
|
|
|
|
result = ObjectManager::Attribute.attribute_to_references_hash
|
|
|
|
|
|
|
|
result = {
|
|
|
|
ticket.category: {
|
|
|
|
Trigger: ['abc', 'xyz'],
|
|
|
|
Overview: ['abc1', 'abc2'],
|
|
|
|
},
|
|
|
|
ticket.field_b: {
|
|
|
|
Trigger: ['abc'],
|
|
|
|
Overview: ['abc1', 'abc2'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.attribute_to_references_hash
|
|
|
|
objects = Trigger.select(:name, :condition) + Overview.select(:name, :condition) + Job.select(:name, :condition)
|
|
|
|
attribute_list = {}
|
|
|
|
objects.each do |item|
|
|
|
|
item.condition.each do |condition_key, _condition_attributes|
|
|
|
|
attribute_list[condition_key] ||= {}
|
|
|
|
attribute_list[condition_key][item.class.name] ||= []
|
|
|
|
next if attribute_list[condition_key][item.class.name].include?(item.name)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-20 12:13:35 +00:00
|
|
|
attribute_list[condition_key][item.class.name].push item.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
attribute_list
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
is certain attribute used by triggers, overviews or schedulers
|
|
|
|
|
|
|
|
ObjectManager::Attribute.attribute_used_by_references?('Ticket', 'attribute_name')
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.attribute_used_by_references?(object_name, attribute_name, references = attribute_to_references_hash)
|
|
|
|
references.each do |reference_key, _relations|
|
|
|
|
local_object, local_attribute = reference_key.split('.')
|
|
|
|
next if local_object != object_name.downcase
|
|
|
|
next if local_attribute != attribute_name
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-20 12:13:35 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
is certain attribute used by triggers, overviews or schedulers
|
|
|
|
|
|
|
|
result = ObjectManager::Attribute.attribute_used_by_references('Ticket', 'attribute_name')
|
|
|
|
|
|
|
|
result = {
|
|
|
|
Trigger: ['abc', 'xyz'],
|
|
|
|
Overview: ['abc1', 'abc2'],
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.attribute_used_by_references(object_name, attribute_name, references = attribute_to_references_hash)
|
|
|
|
result = {}
|
|
|
|
references.each do |reference_key, relations|
|
|
|
|
local_object, local_attribute = reference_key.split('.')
|
|
|
|
next if local_object != object_name.downcase
|
|
|
|
next if local_attribute != attribute_name
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-20 12:13:35 +00:00
|
|
|
relations.each do |relation, relation_names|
|
|
|
|
result[relation] ||= []
|
|
|
|
result[relation].push relation_names.sort
|
|
|
|
end
|
|
|
|
break
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
is certain attribute used by triggers, overviews or schedulers
|
|
|
|
|
|
|
|
text = ObjectManager::Attribute.attribute_used_by_references_humaniced('Ticket', 'attribute_name', references)
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.attribute_used_by_references_humaniced(object_name, attribute_name, references = nil)
|
|
|
|
result = if references.present?
|
|
|
|
ObjectManager::Attribute.attribute_used_by_references(object_name, attribute_name, references)
|
|
|
|
else
|
|
|
|
ObjectManager::Attribute.attribute_used_by_references(object_name, attribute_name)
|
|
|
|
end
|
|
|
|
not_deletable_reason = ''
|
|
|
|
result.each do |relation, relation_names|
|
|
|
|
if not_deletable_reason.present?
|
|
|
|
not_deletable_reason += '; '
|
|
|
|
end
|
|
|
|
not_deletable_reason += "#{relation}: #{relation_names.sort.join(',')}"
|
|
|
|
end
|
|
|
|
not_deletable_reason
|
|
|
|
end
|
|
|
|
|
2016-05-26 08:14:51 +00:00
|
|
|
def self.reset_database_info(model)
|
|
|
|
model.connection.schema_cache.clear!
|
|
|
|
model.reset_column_information
|
2017-08-18 14:01:49 +00:00
|
|
|
# rebuild columns cache to reduce the risk of
|
|
|
|
# race conditions in re-setting it with outdated data
|
|
|
|
model.columns
|
2016-05-26 08:14:51 +00:00
|
|
|
end
|
|
|
|
|
2016-05-19 09:21:50 +00:00
|
|
|
def check_name
|
2016-05-23 22:48:32 +00:00
|
|
|
return if !name
|
2017-11-23 08:09:44 +00:00
|
|
|
|
2021-05-12 11:37:44 +00:00
|
|
|
if name.match?(%r{.+?_(id|ids)$}i)
|
2020-02-13 11:55:19 +00:00
|
|
|
errors.add(:name, "can't get used because *_id and *_ids are not allowed")
|
|
|
|
end
|
2021-05-12 11:37:44 +00:00
|
|
|
if name.match?(%r{\s})
|
2020-02-13 11:55:19 +00:00
|
|
|
errors.add(:name, 'spaces are not allowed')
|
|
|
|
end
|
2021-05-12 11:37:44 +00:00
|
|
|
if !name.match?(%r{^[a-z0-9_]+$})
|
2020-02-13 11:55:19 +00:00
|
|
|
errors.add(:name, 'Only letters from a-z because numbers from 0-9 and _ are allowed')
|
|
|
|
end
|
2021-05-12 11:37:44 +00:00
|
|
|
if !name.match?(%r{[a-z]})
|
2020-02-13 11:55:19 +00:00
|
|
|
errors.add(:name, 'At least one letters is needed')
|
|
|
|
end
|
2016-12-14 00:08:29 +00:00
|
|
|
|
|
|
|
# do not allow model method names as attributes
|
2019-09-02 16:20:32 +00:00
|
|
|
reserved_words = %w[destroy true false integer select drop create alter index table varchar blob date datetime timestamp url icon initials avatar permission validate subscribe unsubscribe translate search _type _doc _id id]
|
2021-05-12 11:37:44 +00:00
|
|
|
if name.match?(%r{^(#{reserved_words.join('|')})$})
|
2020-02-13 11:55:19 +00:00
|
|
|
errors.add(:name, "#{name} is a reserved word! (1)")
|
|
|
|
end
|
2017-11-23 08:09:44 +00:00
|
|
|
|
2018-09-14 14:32:02 +00:00
|
|
|
# fixes issue #2236 - Naming an attribute "attribute" causes ActiveRecord failure
|
|
|
|
begin
|
|
|
|
ObjectLookup.by_id(object_lookup_id).constantize.instance_method_already_implemented? name
|
2020-06-22 09:57:45 +00:00
|
|
|
rescue ActiveRecord::DangerousAttributeError
|
2020-02-13 11:55:19 +00:00
|
|
|
errors.add(:name, "#{name} is a reserved word! (2)")
|
2018-09-14 14:32:02 +00:00
|
|
|
end
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
record = object_lookup.name.constantize.new
|
2020-02-13 11:55:19 +00:00
|
|
|
if record.respond_to?(name.to_sym) && record.attributes.key?(name) && new_record?
|
|
|
|
errors.add(:name, "#{name} already exists!")
|
|
|
|
end
|
|
|
|
|
|
|
|
if errors.present?
|
|
|
|
raise ActiveRecord::RecordInvalid, self
|
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2020-02-13 11:55:19 +00:00
|
|
|
true
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_editable
|
|
|
|
return if editable
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2020-02-13 11:55:19 +00:00
|
|
|
errors.add(:name, 'Attribute not editable!')
|
|
|
|
raise ActiveRecord::RecordInvalid, self
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
|
2018-06-29 06:14:18 +00:00
|
|
|
private
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
# when setting default values for boolean fields,
|
|
|
|
# favor #nil? tests over ||= (which will overwrite `false`)
|
|
|
|
def set_base_options
|
|
|
|
local_data_option[:null] = true if local_data_option[:null].nil?
|
2016-05-29 17:48:28 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
case data_type
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^((tree_)?select|checkbox)$}
|
2018-08-24 01:39:17 +00:00
|
|
|
local_data_option[:nulloption] = true if local_data_option[:nulloption].nil?
|
|
|
|
local_data_option[:maxlength] ||= 255
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
2018-08-24 01:39:17 +00:00
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
def data_option_must_have_appropriate_values
|
|
|
|
data_option_validations
|
|
|
|
.select { |validation| validation[:failed] }
|
|
|
|
.each { |validation| errors.add(local_data_attr, validation[:message]) }
|
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
|
2020-11-24 09:32:07 +00:00
|
|
|
def inactive_must_be_unused_by_references
|
|
|
|
return if !ObjectManager::Attribute.attribute_used_by_references?(object_lookup.name, name)
|
|
|
|
|
|
|
|
human_reference = ObjectManager::Attribute.attribute_used_by_references_humaniced(object_lookup.name, name)
|
|
|
|
text = "#{object_lookup.name}.#{name} is referenced by #{human_reference} and thus cannot be set to inactive!"
|
|
|
|
|
|
|
|
# Adding as `base` to prevent `Active` prefix which does not look good on error message shown at the top of the form.
|
|
|
|
errors.add(:base, text)
|
|
|
|
end
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
def data_type_must_not_change
|
|
|
|
allowable_changes = %w[tree_select select input checkbox]
|
2016-05-19 09:21:50 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
return if !data_type_changed?
|
|
|
|
return if (data_type_change - allowable_changes).empty?
|
2016-05-19 09:21:50 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
errors.add(:data_type, "can't be altered after creation " \
|
|
|
|
'(delete the attribute and create another with the desired value)')
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
def local_data_option
|
|
|
|
@local_data_option ||= send(local_data_attr)
|
|
|
|
end
|
2018-06-29 06:14:18 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
def local_data_attr
|
|
|
|
@local_data_attr ||= to_config ? :data_option_new : :data_option
|
|
|
|
end
|
2018-06-29 06:14:18 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
def local_data_option=(val)
|
|
|
|
send("#{local_data_attr}=", val)
|
|
|
|
end
|
2018-06-29 06:14:18 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
def data_option_validations
|
|
|
|
case data_type
|
|
|
|
when 'input'
|
|
|
|
[{ failed: %w[text password tel fax email url].exclude?(local_data_option[:type]),
|
|
|
|
message: 'must have one of text/password/tel/fax/email/url for :type' },
|
2021-05-12 11:37:44 +00:00
|
|
|
{ failed: !local_data_option[:maxlength].to_s.match?(%r{^\d+$}),
|
2018-08-24 01:39:17 +00:00
|
|
|
message: 'must have integer for :maxlength' }]
|
|
|
|
when 'richtext'
|
2021-05-12 11:37:44 +00:00
|
|
|
[{ failed: !local_data_option[:maxlength].to_s.match?(%r{^\d+$}),
|
2018-08-24 01:39:17 +00:00
|
|
|
message: 'must have integer for :maxlength' }]
|
|
|
|
when 'integer'
|
2021-08-18 04:48:16 +00:00
|
|
|
min = local_data_option[:min]
|
|
|
|
max = local_data_option[:max]
|
|
|
|
|
|
|
|
[{ failed: !VALIDATE_INTEGER_REGEXP.match?(min.to_s),
|
2018-08-24 01:39:17 +00:00
|
|
|
message: 'must have integer for :min' },
|
2021-08-18 04:48:16 +00:00
|
|
|
{ failed: !VALIDATE_INTEGER_REGEXP.match?(max.to_s),
|
|
|
|
message: 'must have integer for :max' },
|
|
|
|
{ failed: !(min.is_a?(Integer) && min >= VALIDATE_INTEGER_MIN),
|
|
|
|
message: 'min must be higher than -2147483648' },
|
|
|
|
{ failed: !(min.is_a?(Integer) && min <= VALIDATE_INTEGER_MAX),
|
|
|
|
message: 'min must be lower than 2147483648' },
|
|
|
|
{ failed: !(max.is_a?(Integer) && max >= VALIDATE_INTEGER_MIN),
|
|
|
|
message: 'max must be higher than -2147483648' },
|
|
|
|
{ failed: !(max.is_a?(Integer) && max <= VALIDATE_INTEGER_MAX),
|
|
|
|
message: 'max must be lower than 2147483648' },
|
|
|
|
{ failed: !(max.is_a?(Integer) && min.is_a?(Integer) && min <= max),
|
|
|
|
message: 'min must be lower than max' }]
|
2021-05-12 11:37:44 +00:00
|
|
|
when %r{^((tree_)?select|checkbox)$}
|
2018-08-24 01:39:17 +00:00
|
|
|
[{ failed: !local_data_option.key?(:default),
|
|
|
|
message: 'must have value for :default' },
|
|
|
|
{ failed: local_data_option[:options].nil? && local_data_option[:relation].nil?,
|
|
|
|
message: 'must have non-nil value for either :options or :relation' }]
|
|
|
|
when 'boolean'
|
|
|
|
[{ failed: !local_data_option.key?(:default),
|
|
|
|
message: 'must have boolean/undefined value for :default' },
|
|
|
|
{ failed: local_data_option[:options].nil?,
|
|
|
|
message: 'must have non-nil value for :options' }]
|
|
|
|
when 'datetime'
|
|
|
|
[{ failed: local_data_option[:future].nil?,
|
|
|
|
message: 'must have boolean value for :future' },
|
|
|
|
{ failed: local_data_option[:past].nil?,
|
|
|
|
message: 'must have boolean value for :past' },
|
|
|
|
{ failed: local_data_option[:diff].nil?,
|
|
|
|
message: 'must have integer value for :diff (in hours)' }]
|
|
|
|
when 'date'
|
2019-03-14 10:06:49 +00:00
|
|
|
[{ failed: local_data_option[:diff].nil?,
|
2018-08-24 01:39:17 +00:00
|
|
|
message: 'must have integer value for :diff (in days)' }]
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
2018-06-29 06:14:18 +00:00
|
|
|
end
|
2016-05-19 09:21:50 +00:00
|
|
|
end
|