2012-05-04 23:53:45 +01:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-10 18:17:59 +01:00
|
|
|
class AdvisoriesController < ApplicationController
|
2012-05-04 23:53:45 +01:00
|
|
|
before_filter :authenticate_user!
|
2012-06-04 20:49:20 +01:00
|
|
|
skip_before_filter :authenticate_user! if APP_CONFIG['anonymous_access']
|
2012-06-18 23:49:17 +01:00
|
|
|
load_resource :find_by => :advisory_id
|
|
|
|
authorize_resource
|
2012-05-04 23:53:45 +01:00
|
|
|
|
2012-07-06 14:31:18 +01:00
|
|
|
before_filter :fetch_packages_info
|
|
|
|
|
2012-05-04 23:53:45 +01:00
|
|
|
def index
|
2012-06-20 18:51:08 +01:00
|
|
|
@advisories = @advisories.scoped(:include => :platforms)
|
|
|
|
@advisories = @advisories.search_by_id(params[:q]) if params[:q]
|
|
|
|
@advisories = @advisories.paginate(:page => params[:page])
|
2012-06-20 15:07:07 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.atom
|
|
|
|
end
|
2012-05-04 23:53:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2012-07-06 14:31:18 +01:00
|
|
|
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 ;)
|
2012-06-18 23:49:17 +01:00
|
|
|
@advisory.build_lists.find_in_batches(:include => [:save_to_platform, :packages, :project]) do |batch|
|
|
|
|
batch.each do |build_list|
|
2012-07-04 17:52:22 +01:00
|
|
|
tmp = build_list.packages.inject({:srpm => nil, :rpm => []}) do |h, p|
|
2012-07-04 19:01:06 +01:00
|
|
|
p.package_type == 'binary' ? h[:rpm] << p.fullname : h[:srpm] = p.fullname
|
2012-07-04 17:52:22 +01:00
|
|
|
h
|
|
|
|
end
|
|
|
|
h = { build_list.project => tmp }
|
|
|
|
@packages_info[build_list.save_to_platform].merge!(h) do |pr, old, new|
|
|
|
|
{:srpm => new[:srpm], :rpm => old[:rpm].concat(new[:rpm]).uniq}
|
|
|
|
end
|
2012-06-18 23:49:17 +01:00
|
|
|
end
|
|
|
|
end
|
2012-05-04 23:53:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|