2012-10-18 12:22:31 +01:00
|
|
|
class Api::V1::AdvisoriesController < Api::V1::BaseController
|
|
|
|
before_filter :authenticate_user!
|
2012-10-18 15:17:50 +01:00
|
|
|
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access']
|
2012-10-18 16:44:28 +01:00
|
|
|
load_resource :advisory, :find_by => :advisory_id
|
2012-10-19 08:32:12 +01:00
|
|
|
before_filter :find_and_authorize_build_list, :only => [:create, :update]
|
2012-10-18 16:44:28 +01:00
|
|
|
authorize_resource :build_list, :only => [:create, :update]
|
2012-10-18 12:22:31 +01:00
|
|
|
|
|
|
|
def index
|
2013-07-17 13:35:36 +01:00
|
|
|
@advisories = @advisories.scoped(:include => [:platforms, :projects]).
|
2012-10-18 12:22:31 +01:00
|
|
|
paginate(paginate_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2012-10-18 15:17:50 +01:00
|
|
|
@packages_info = @advisory.fetch_packages_info
|
2012-10-18 12:22:31 +01:00
|
|
|
end
|
|
|
|
|
2012-10-18 15:17:50 +01:00
|
|
|
def create
|
2012-10-19 15:03:09 +01:00
|
|
|
if @build_list.can_attach_to_advisory? &&
|
2012-10-19 08:32:12 +01:00
|
|
|
@build_list.associate_and_create_advisory(params[:advisory]) &&
|
|
|
|
@build_list.save
|
2012-10-18 15:17:50 +01:00
|
|
|
render_json_response @advisory, 'Advisory has been created successfully'
|
|
|
|
else
|
|
|
|
render_validation_error @advisory, error_message(@build_list, 'Advisory has not been created')
|
|
|
|
end
|
|
|
|
end
|
2012-10-18 12:22:31 +01:00
|
|
|
|
2012-10-18 15:17:50 +01:00
|
|
|
def update
|
2012-10-19 15:03:09 +01:00
|
|
|
if @advisory && @build_list.can_attach_to_advisory? &&
|
2012-10-19 08:32:12 +01:00
|
|
|
@advisory.attach_build_list(@build_list) && @build_list.save
|
2012-10-18 15:17:50 +01:00
|
|
|
render_json_response @advisory, "Build list '#{@build_list.id}' has been attached to advisory successfully"
|
|
|
|
else
|
|
|
|
render_validation_error @advisory, error_message(@build_list, 'Build list has not been attached to advisory')
|
2012-10-18 12:22:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-18 16:44:28 +01:00
|
|
|
protected
|
|
|
|
|
2012-10-19 08:32:12 +01:00
|
|
|
def find_and_authorize_build_list
|
2012-10-18 16:44:28 +01:00
|
|
|
@build_list = BuildList.find params[:build_list_id]
|
2013-03-07 10:05:53 +00:00
|
|
|
authorize! :local_admin_manage, @build_list.save_to_platform
|
2012-10-18 16:44:28 +01:00
|
|
|
end
|
|
|
|
|
2012-10-18 12:22:31 +01:00
|
|
|
end
|