rosa-build/app/controllers/projects/build_lists_controller.rb

151 lines
5.6 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class Projects::BuildListsController < Projects::BaseController
NESTED_ACTIONS = [:search, :index, :new, :create]
2013-01-24 09:33:22 +00:00
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index, :search, :log] if APP_CONFIG['anonymous_access']
2013-01-25 17:24:46 +00:00
before_filter :find_build_list, :only => [:show, :publish, :cancel, :update, :log, :create_container]
load_and_authorize_resource :project, :only => NESTED_ACTIONS
load_and_authorize_resource :build_list, :through => :project, :only => NESTED_ACTIONS, :shallow => true
2013-01-24 09:33:22 +00:00
load_and_authorize_resource :except => NESTED_ACTIONS
def search
new_params = {:filter => {}}
params[:filter].each do |k,v|
new_params[:filter][k] = v unless v.empty?
end
new_params[:per_page] = params[:per_page] if params[:per_page].present?
redirect_to @project ? project_build_lists_path(@project, new_params) : build_lists_path(new_params)
end
def index
@action_url = @project ? search_project_build_lists_path(@project) : search_build_lists_path
@filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
2012-11-14 17:56:00 +00:00
page = params[:page].to_i == 0 ? nil : params[:page]
2013-02-21 12:46:28 +00:00
@per_page = BuildList::Filter::PER_PAGE.include?(params[:per_page].to_i) ? params[:per_page].to_i : 25
@bls = @filter.find.recent.paginate :page => page, :per_page => @per_page
@build_lists = BuildList.where(:id => @bls.pluck("#{BuildList.table_name}.id")).recent
@build_lists = @build_lists.includes [:save_to_platform, :save_to_repository, :arch, :user, :project => [:owner]]
2013-01-24 10:42:03 +00:00
@build_server_status = AbfWorker::StatusInspector.projects_status
end
def new
end
def create
notices, errors = [], []
2012-09-13 17:08:41 +01:00
@repository = Repository.find params[:build_list][:save_to_repository_id]
@platform = @repository.platform
2012-09-13 17:08:41 +01:00
params[:build_list][:save_to_platform_id] = @platform.id
2012-09-06 16:39:26 +01:00
params[:build_list][:auto_publish] = false unless @repository.publish_without_qa?
2012-09-13 17:08:41 +01:00
build_for_platforms = Repository.select(:platform_id).
2012-09-13 17:18:09 +01:00
where(:id => params[:build_list][:include_repos]).group(:platform_id).map(&:platform_id)
2012-09-13 17:08:41 +01:00
Arch.where(:id => params[:arches]).each do |arch|
2012-09-13 17:08:41 +01:00
Platform.main.where(:id => build_for_platforms).each do |build_for_platform|
@build_list = @project.build_lists.build(params[:build_list])
@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?
if errors.present?
@build_list ||= BuildList.new
flash[:error] = errors.join('<br>').html_safe
render :action => :new
else
flash[:notice] = notices.join('<br>').html_safe
redirect_to project_build_lists_path(@project)
end
end
def show
@item_groups = @build_list.items.group_by_level
end
2012-05-04 18:12:51 +01:00
def publish
@build_list.update_type = params[:build_list][:update_type] if params[:build_list][:update_type].present?
if params[:attach_advisory].present? and params[:attach_advisory] != 'no' and !@build_list.advisory
unless @build_list.update_type.in? BuildList::RELEASE_UPDATE_TYPES
2013-01-24 09:33:22 +00:00
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return
end
if params[:attach_advisory] == 'new'
# create new advisory
2012-10-19 08:32:12 +01:00
unless @build_list.associate_and_create_advisory(params[:build_list][:advisory])
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return
end
else
# attach existing advisory
2012-10-19 08:32:12 +01:00
a = Advisory.where(:advisory_id => params[:attach_advisory]).first
unless (a && a.attach_build_list(@build_list))
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return
end
end
2012-05-04 18:12:51 +01:00
end
2013-03-28 11:58:26 +00:00
@build_list.publisher = current_user
if @build_list.publish
redirect_to :back, :notice => t('layout.build_lists.publish_success')
2012-05-04 18:12:51 +01:00
else
redirect_to :back, :notice => t('layout.build_lists.publish_fail')
end
end
def reject_publish
@build_list.publisher = current_user
2012-05-04 18:12:51 +01:00
if @build_list.reject_publish
redirect_to :back, :notice => t('layout.build_lists.reject_publish_success')
else
redirect_to :back, :notice => t('layout.build_lists.reject_publish_fail')
end
end
def create_container
if @build_list.publish_container
redirect_to :back, :notice => t('layout.build_lists.create_container_success')
else
redirect_to :back, :notice => t('layout.build_lists.create_container_fail')
end
end
def cancel
if @build_list.cancel
redirect_to :back, :notice => t('layout.build_lists.will_be_canceled')
else
redirect_to :back, :notice => t('layout.build_lists.cancel_fail')
end
end
def log
render :json => {
:log => @build_list.log(params[:load_lines]),
:building => @build_list.build_started?
}
end
protected
def find_build_list
@build_list = BuildList.find(params[:id])
end
2011-04-22 13:08:58 +01:00
end