Fixes #3769 - Usage of inactive object attributes in SLAs will crash admin SLA interface
This commit is contained in:
parent
90eca0f1eb
commit
4c72d5b9d9
3 changed files with 32 additions and 9 deletions
|
@ -678,7 +678,7 @@ to send no browser reload event, pass false
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
where attributes are used by triggers, overviews or schedulers
|
where attributes are used in conditions
|
||||||
|
|
||||||
result = ObjectManager::Attribute.attribute_to_references_hash
|
result = ObjectManager::Attribute.attribute_to_references_hash
|
||||||
|
|
||||||
|
@ -696,22 +696,36 @@ where attributes are used by triggers, overviews or schedulers
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.attribute_to_references_hash
|
def self.attribute_to_references_hash
|
||||||
objects = Trigger.select(:name, :condition) + Overview.select(:name, :condition) + Job.select(:name, :condition)
|
|
||||||
attribute_list = {}
|
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)
|
|
||||||
|
|
||||||
attribute_list[condition_key][item.class.name].push item.name
|
attribute_to_references_hash_objects
|
||||||
|
.map { |elem| elem.select(:name, :condition) }
|
||||||
|
.flatten
|
||||||
|
.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)
|
||||||
|
|
||||||
|
attribute_list[condition_key][item.class.name].push item.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
attribute_list
|
attribute_list
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
models that may reference attributes
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.attribute_to_references_hash_objects
|
||||||
|
Models.all.keys.select { |elem| elem.include? ChecksConditionValidation }
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
is certain attribute used by triggers, overviews or schedulers
|
is certain attribute used by triggers, overviews or schedulers
|
||||||
|
|
||||||
ObjectManager::Attribute.attribute_used_by_references?('Ticket', 'attribute_name')
|
ObjectManager::Attribute.attribute_used_by_references?('Ticket', 'attribute_name')
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
class Report::Profile < ApplicationModel
|
class Report::Profile < ApplicationModel
|
||||||
self.table_name = 'report_profiles'
|
self.table_name = 'report_profiles'
|
||||||
|
include ChecksConditionValidation
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
store :condition
|
store :condition
|
||||||
|
|
||||||
|
|
|
@ -148,4 +148,12 @@ RSpec.describe ObjectManager::Attribute, type: :model do
|
||||||
it { is_expected.to be_valid }
|
it { is_expected.to be_valid }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'Class methods:' do
|
||||||
|
describe '.attribute_to_references_hash_objects' do
|
||||||
|
it 'returns classes with conditions' do
|
||||||
|
expect(described_class.attribute_to_references_hash_objects).to match_array [Trigger, Overview, Job, Sla, Report::Profile ]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue