Redo project assign for build_list_packages. Redo and fix double render error during build_list publish. Refs #444, #481

This commit is contained in:
Pavel Chipiga 2012-05-18 00:19:57 +03:00
parent 4a457b2298
commit b41a9e3b49
2 changed files with 14 additions and 13 deletions

View File

@ -75,7 +75,7 @@ class Projects::BuildListsController < Projects::BaseController
def update
if params[:publish].present? and can?(:publish, @build_list)
publish
elsif params[:reject_publish].present? and can?(:reject_publish)
elsif params[:reject_publish].present? and can?(:reject_publish, @build_list)
reject_publish
else
# King Arthur, we are under attack!
@ -112,7 +112,7 @@ class Projects::BuildListsController < Projects::BaseController
@build_list.container_path = params[:container_path]
@build_list.save
@build_list.set_packages(ActiveSupport::JSON.decode(params[:pkg_info])) if params[:status].to_i == BuildServer::SUCCESS and params[:pkg_info].present?
@build_list.set_packages(ActiveSupport::JSON.decode(params[:pkg_info]), params[:package_name]) if params[:status].to_i == BuildServer::SUCCESS and params[:pkg_info].present?
render :nothing => true, :status => 200
end
@ -172,12 +172,12 @@ class Projects::BuildListsController < Projects::BaseController
def publish
@build_list.update_type = params[:build_list][:update_type] if params[:build_list][:update_type].present?
if params[:create_advisory].present?
a = @build_list.build_advisory
a.update_type = @build_list.update_type
a.project = @build_list.project
a.platforms << @build_list.save_to_platform unless a.platforms.include? @build_list.save_to_platform
redirect_to :back, :notice => t('layout.build_lists.publish_fail') unless a.update_attributes(params[:build_list][:advisory])
if params[:create_advisory].present? and !@build_list.build_advisory(params[:build_list][:advisory]) do |a|
a.update_type = @build_list.update_type
a.project = @build_list.project
a.platforms << @build_list.save_to_platform unless a.platforms.include? @build_list.save_to_platform
end.save
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return
end
if @build_list.save and @build_list.publish
redirect_to :back, :notice => t('layout.build_lists.publish_success')

View File

@ -114,10 +114,11 @@ class BuildList < ActiveRecord::Base
end
end
def set_packages(pkg_hash)
build_package(pkg_hash['srpm'], 'source') {|p| p.save!}
def set_packages(pkg_hash, project_name)
prj = Project.joins(:repositories => :platform).where('platforms.id = ?', save_to_platform.id).find_by_name!(project_name)
build_package(pkg_hash['srpm'], 'source', prj) {|p| p.save!}
pkg_hash['rpm'].each do |rpm_hash|
build_package(rpm_hash, 'binary') {|p| p.save!}
build_package(rpm_hash, 'binary', prj) {|p| p.save!}
end
end
@ -188,9 +189,9 @@ class BuildList < ActiveRecord::Base
save
end
def build_package(pkg_hash, package_type)
def build_package(pkg_hash, package_type, prj)
packages.create(pkg_hash) do |p|
p.project = project # Project.joins(:repositories => :platform).where('platforms.id = ?', save_to_platform.id).find_by_name!(pkg_hash['name'])
p.project = prj
p.platform = save_to_platform
p.package_type = package_type
yield p