|
@@ -26,6 +26,7 @@ class ObjectManager::Attribute < ApplicationModel
|
|
|
|
|
|
validates :name, presence: true
|
|
|
validates :data_type, inclusion: { in: DATA_TYPES, msg: '%{value} is not a valid data type' } # rubocop:disable Style/FormatStringToken
|
|
|
+ validate :inactive_must_be_unused_by_references, unless: :active?
|
|
|
validate :data_option_must_have_appropriate_values
|
|
|
validate :data_type_must_not_change, on: :update
|
|
|
|
|
@@ -844,6 +845,16 @@ is certain attribute used by triggers, overviews or schedulers
|
|
|
.each { |validation| errors.add(local_data_attr, validation[:message]) }
|
|
|
end
|
|
|
|
|
|
+ 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
|
|
|
+
|
|
|
def data_type_must_not_change
|
|
|
allowable_changes = %w[tree_select select input checkbox]
|
|
|
|