[issue #590] Moved repository check to controller.

This commit is contained in:
George Vinogradov 2012-08-06 14:21:33 +04:00
parent 623ce0cefb
commit 36de270fad
3 changed files with 19 additions and 17 deletions

View File

@ -47,23 +47,27 @@ class Projects::BuildListsController < Projects::BaseController
params[:build_list][:save_to_platform_id] = @platform.id
params[:build_list][:auto_publish] = false if @platform.released
Arch.where(:id => params[:arches]).each do |arch|
Platform.main.where(:id => params[:build_for_platforms]).each do |build_for_platform|
@build_list = @project.build_lists.build(params[:build_list])
@build_list.commit_hash = @project.repo.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last ||
@build_list.project_version).first.id if @build_list.project_version
@build_list.build_for_platform = build_for_platform; @build_list.arch = arch; @build_list.user = current_user
@build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i}
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
flash_options = {:project_version => @build_list.project_version, :arch => arch.name, :build_for_platform => build_for_platform.name}
if @build_list.save
notices << t("flash.build_list.saved", flash_options)
else
errors << t("flash.build_list.save_error", flash_options)
if current_user.can?(:write, save_to_repository)
Arch.where(:id => params[:arches]).each do |arch|
Platform.main.where(:id => params[:build_for_platforms]).each do |build_for_platform|
@build_list = @project.build_lists.build(params[:build_list])
@build_list.commit_hash = @project.repo.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last ||
@build_list.project_version).first.id if @build_list.project_version
@build_list.build_for_platform = build_for_platform; @build_list.arch = arch; @build_list.user = current_user
@build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i}
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
flash_options = {:project_version => @build_list.project_version, :arch => arch.name, :build_for_platform => build_for_platform.name}
if @build_list.save
notices << t("flash.build_list.saved", flash_options)
else
errors << t("flash.build_list.save_error", flash_options)
end
end
end
errors << t("flash.build_list.no_arch_or_platform_selected") if errors.blank? and notices.blank?
else
errors << t('flash.build_list.cannot_write')
end
errors << t("flash.build_list.no_arch_or_platform_selected") if errors.blank? and notices.blank?
if errors.present?
@build_list ||= BuildList.new
flash[:error] = errors.join('<br>').html_safe

View File

@ -27,9 +27,6 @@ class BuildList < ActiveRecord::Base
validate lambda {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) unless save_to_repository_id.in? save_to_platform.repositories.map(&:id)
}
validate lambda {
errors.add(:save_to_repository, I18n.t('flash.build_list.cannot_write')) unless current_user.can?(:write, save_to_repository)
}
LIVE_TIME = 3.week

View File

@ -14,6 +14,7 @@ class AddSaveToRepositoryToBuildLists < ActiveRecord::Migration
bl.save_to_repository_id = rep
bl.save!
puts bl.inspect
rescue Exception => e
puts e.inspect
false