Project

General

Profile

« Previous | Next » 

Revision be33e6e9

Added by Tomer Brisker over 8 years ago

Fixes #11650 - show global parameter value inherited from parent taxonomy

View differences:

app/models/taxonomies/location.rb
where(conditions)
}
# returns self and parent parameters as a hash
def parameters(include_source = false)
hash = {}
ids = ancestor_ids
ids << id unless new_record? or self.frozen?
# need to pull out the locations to ensure they are sorted first,
# otherwise we might be overwriting the hash in the wrong order.
locs = ids.size == 1 ? [self] : Location.sort_by_ancestry(Location.includes(:location_parameters).find(ids))
locs.each do |loc|
loc.location_parameters.each {|p| hash[p.name] = include_source ? {:value => p.value, :source => N_('location').to_sym, :source_name => loc.title} : p.value }
end
hash
end
def dup
new = super
new.organizations = organizations
app/models/taxonomies/organization.rb
where(conditions)
}
# returns self and parent parameters as a hash
def parameters(include_source = false)
hash = {}
ids = ancestor_ids
ids << id unless new_record? or self.frozen?
# need to pull out the organizations to ensure they are sorted first,
# otherwise we might be overwriting the hash in the wrong order.
orgs = ids.size == 1 ? [self] : Organization.sort_by_ancestry(Organization.includes(:organization_parameters).find(ids))
orgs.each do |org|
org.organization_parameters.each {|p| hash[p.name] = include_source ? {:value => p.value, :source => N_('organization').to_sym, :source_name => org.title} : p.value }
end
hash
end
def dup
new = super
new.locations = locations
app/models/taxonomy.rb
(users+User.only_admin).each { |u| u.expire_topbar_cache(sweeper) }
end
# returns self and parent parameters as a hash
def parameters(include_source = false)
hash = {}
ids = ancestor_ids
ids << id unless new_record? or self.frozen?
# need to pull out the locations to ensure they are sorted first,
# otherwise we might be overwriting the hash in the wrong order.
elements = ids.size == 1 ? [self] : self.class.sort_by_ancestry(self.class.includes("#{type.downcase}_parameters".to_sym).find(ids))
elements.each do |el|
el.send("#{type.downcase}_parameters".to_sym).each {|p| hash[p.name] = include_source ? {:value => p.value, :source => sti_name, :safe_value => p.safe_value, :source_name => el.title} : p.value }
end
hash
end
private
delegate :need_to_be_selected_ids, :selected_ids, :used_and_selected_ids, :mismatches, :missing_ids, :check_for_orphans,
test/unit/parameter_test.rb
host.clear_host_parameters_cache!
assert_equal "pig", host.host_params["animal"]
end
test "parameters should display correct safe value for nested taxonomies" do
loc1 = FactoryGirl.create(:location)
loc2 = FactoryGirl.create(:location, :parent => loc1)
host = FactoryGirl.create(:host, :location => loc2)
loc1.location_parameters << LocationParameter.create(:name => "animal", :value => "lion")
params = host.host_inherited_params(true)
assert_equal "lion", params["animal"][:safe_value]
assert_equal loc1.title, params["animal"][:source_name]
loc2.location_parameters << LocationParameter.create(:name => "animal", :value => "dog")
params = host.host_inherited_params(true)
assert_equal "dog", params["animal"][:safe_value]
assert_equal loc2.title, params["animal"][:source_name]
end
end

Also available in: Unified diff