module Katello module ProductsHelper def gpg_keys_edit keys = {} GpgKey.readable(current_organization).each do |key| keys[key.id] = key.name end keys[""] = "" keys["selected"] = @product.gpg_key_id || "" return keys.to_json end def gpg_keys GpgKey.readable(current_organization) end # Objectify the record provided. This will generate a hash containing # the record id, list of products and list of repos. It assumes that the # record has a 'repositories' relationship. def objectify(record, content_types = nil) repos = Hash.new { |h, k| h[k] = [] } record.repositories.each do |repo| next if content_types && !content_types.include?(repo.content_type) repos[repo.product.id.to_s] << repo.id.to_s end { :id => record.id, :products => record.product_ids, # :id :repos => repos } end # Retrieve a hash of products that are accessible to the user. # This will be determined from the readable & editable products provided in the options. # @param [Hash] options the options to construct the product hash with # @option options [String] :readable_products List of readable products # @option options [String] :editable_products List of editable products # @option options [String] :content_types (Optional) Filter repos by listed types def get_products(options) options[:content_types] ||= [Repository::TYPES] if @product_hash.nil? @product_hash = {} options[:readable_products].sort_by(&:name).each do |prod| repos = prod.repos(current_organization.library).where(:content_type => options[:content_types]) .sort { |a, b| a.name <=> b.name } repos = repos.map { |repo| {:name => repo.name, :id => repo.id} } if repos.any? @product_hash[prod.id] = {:name => prod.name, :repos => repos, :id => prod.id, :editable => options[:editable_products].include?(prod)} end end end @product_hash end end end