[issue #428] Fetching packages moved to particular method.

This commit is contained in:
George Vinogradov 2012-07-06 17:31:18 +04:00
parent 3c8b77027e
commit 49927728cd
1 changed files with 17 additions and 9 deletions

View File

@ -5,6 +5,8 @@ class AdvisoriesController < ApplicationController
load_resource :find_by => :advisory_id
authorize_resource
before_filter :fetch_packages_info
def index
@advisories = @advisories.scoped(:include => :platforms)
@advisories = @advisories.search_by_id(params[:q]) if params[:q]
@ -16,7 +18,21 @@ class AdvisoriesController < ApplicationController
end
def show
@packages_info = Hash.new { |h, k| h[k] = {} }
end
def search
@advisory = Advisory.by_update_type(params[:bl_type]).search_by_id(params[:query]).first
raise ActionController::RoutingError.new('Not Found') if @advisory.nil?
respond_to do |format|
format.json { render @advisory }
end
end
protected
# this method fetches and structurize packages attached to current advisory.
def fetch_packages_info
@packages_info = Hash.new { |h, k| h[k] = {} } # maaagic, it's maaagic ;)
@advisory.build_lists.find_in_batches(:include => [:save_to_platform, :packages, :project]) do |batch|
batch.each do |build_list|
tmp = build_list.packages.inject({:srpm => nil, :rpm => []}) do |h, p|
@ -31,12 +47,4 @@ class AdvisoriesController < ApplicationController
end
end
def search
@advisory = Advisory.by_update_type(params[:bl_type]).search_by_id(params[:query]).first
raise ActionController::RoutingError.new('Not Found') if @advisory.nil?
respond_to do |format|
format.json { render @advisory }
end
end
end