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

243 lines
8.8 KiB
Ruby
Raw Normal View History

class Projects::BuildListsController < Projects::BaseController
2013-08-27 16:43:30 +01:00
include FileStoreHelper
include BuildListsHelper
2013-08-21 12:00:22 +01:00
2013-08-05 13:52:15 +01:00
NESTED_ACTIONS = [:index, :new, :create]
2015-03-04 23:19:19 +00:00
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:show, :index, :log] if APP_CONFIG['anonymous_access']
2015-03-04 23:19:19 +00:00
before_action :find_build_list, only: [:show, :publish, :cancel, :update, :log, :create_container, :dependent_projects]
2014-03-20 22:56:59 +00:00
load_and_authorize_resource :project, only: [:new, :create]
load_resource :project, only: :index, parent: false
2014-01-21 04:51:49 +00:00
load_and_authorize_resource :build_list, through: :project, only: NESTED_ACTIONS, shallow: true
load_and_authorize_resource except: NESTED_ACTIONS
2015-03-04 23:19:19 +00:00
before_action :create_from_build_list, only: :new
def index
authorize :build_list
authorize @project, :show? if @project
params[:filter].each{|k,v| params[:filter].delete(k) if v.blank? } if params[:filter]
2013-08-02 19:13:41 +01:00
respond_to do |format|
format.html
format.json do
@filter = BuildList::Filter.new(@project, current_user, current_ability, params[:filter] || {})
2014-05-26 18:42:27 +01:00
params[:page] = params[:page].to_i == 0 ? nil : params[:page]
params[:per_page] = if BuildList::Filter::PER_PAGE.include? params[:per_page].to_i
params[:per_page].to_i
else
BuildList::Filter::PER_PAGE.first
end
@bls_count = @filter.find.count
@bls = @filter.find.recent.paginate(page: params[:page], per_page: params[:per_page])
2014-01-21 04:51:49 +00:00
@build_lists = BuildList.where(id: @bls.pluck(:id)).recent
2014-05-26 18:42:27 +01:00
.includes(:save_to_platform,
:save_to_repository,
:build_for_platform,
:user,
:source_packages,
project: :project_statistics)
@build_server_status = AbfWorkerStatusPresenter.new.projects_status
2013-08-02 19:13:41 +01:00
end
end
end
def new
2013-08-05 19:34:42 +01:00
if params[:show] == 'inline' && params[:build_list_id].present?
render json: new_build_list_data(@build_list, @project, params), layout: false
2013-08-05 19:34:42 +01:00
else
render :new
end
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-13 17:08:41 +01:00
build_for_platforms = Repository.select(:platform_id).
2014-01-21 04:51:49 +00:00
where(id: params[:build_list][:include_repos]).group(:platform_id).map(&:platform_id)
2012-09-13 17:08:41 +01:00
2013-08-29 18:46:11 +01:00
build_lists = []
2014-01-21 04:51:49 +00:00
Arch.where(id: params[:arches]).each do |arch|
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
2014-05-26 18:42:27 +01:00
flash_options = { project_version: @build_list.project_version, arch: arch.name, build_for_platform: build_for_platform.name }
if authorize!(:create, @build_list) && @build_list.save
2013-08-29 18:46:11 +01:00
build_lists << @build_list
2014-05-26 18:42:27 +01:00
notices << t('flash.build_list.saved', flash_options)
else
2014-05-26 18:42:27 +01:00
errors << t('flash.build_list.save_error', flash_options)
end
end
end
2014-05-26 18:42:27 +01:00
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
2014-01-21 04:51:49 +00:00
render action: :new
else
2014-01-21 04:51:49 +00:00
BuildList.where(id: build_lists.map(&:id)).update_all(group_id: build_lists[0].id) if build_lists.size > 1
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
2014-01-21 04:51:49 +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])
2014-01-21 04:51:49 +00:00
redirect_to :back, notice: t('layout.build_lists.publish_fail') and return
end
else
# attach existing advisory
2014-01-21 04:51:49 +00:00
a = Advisory.where(advisory_id: params[:attach_advisory]).first
2012-10-19 08:32:12 +01:00
unless (a && a.attach_build_list(@build_list))
2014-01-21 04:51:49 +00:00
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
2014-05-21 23:58:13 +01:00
do_and_back(:publish, 'publish_')
2012-05-04 18:12:51 +01:00
end
def dependent_projects
2015-03-12 22:43:13 +00:00
raise Pundit::NotAuthorizedError if @build_list.save_to_platform.personal?
if request.post?
prs = params[:build_list]
if prs.present? && prs[:projects].present? && prs[:arches].present?
project_ids = prs[:projects].select{ |k, v| v == '1' }.keys
arch_ids = prs[:arches]. select{ |k, v| v == '1' }.keys
Resque.enqueue(
BuildLists::DependentPackagesJob,
@build_list.id,
current_user.id,
project_ids,
arch_ids,
{
auto_publish_status: prs[:auto_publish_status],
auto_create_container: prs[:auto_create_container],
include_testing_subrepository: prs[:include_testing_subrepository],
use_cached_chroot: prs[:use_cached_chroot],
use_extra_tests: prs[:use_extra_tests]
}
)
flash[:notice] = t('flash.build_list.dependent_projects_job_added_to_queue')
redirect_to build_list_path(@build_list)
end
end
end
2013-11-01 17:11:59 +00:00
def publish_into_testing
@build_list.publisher = current_user
2014-05-21 23:58:13 +01:00
do_and_back(:publish_into_testing, 'publish_')
end
def rerun_tests
do_and_back(:rerun_tests, 'rerun_tests_')
2012-05-04 18:12:51 +01:00
end
def reject_publish
@build_list.publisher = current_user
2014-05-21 23:58:13 +01:00
do_and_back(:reject_publish, 'reject_publish_')
2012-05-04 18:12:51 +01:00
end
def create_container
2014-05-21 23:58:13 +01:00
do_and_back(:publish_container, 'create_container_')
end
def cancel
2014-05-21 23:58:13 +01:00
do_and_back(:cancel, nil, 'will_be_canceled', 'cancel_fail')
end
def log
2014-01-21 04:51:49 +00:00
render json: {
log: @build_list.log(params[:load_lines]),
building: @build_list.build_started?
}
end
2013-08-01 18:18:46 +01:00
def list
@build_lists = @project.build_lists
2014-01-21 04:51:49 +00:00
@build_lists = @build_lists.where(user_id: current_user) if params[:owner_filter] == 'true'
@build_lists = @build_lists.where(status: [BuildList::BUILD_ERROR, BuildList::FAILED_PUBLISH, BuildList::REJECTED_PUBLISH]) if params[:status_filter] == 'true'
@total_build_lists = @build_lists.count
@build_lists = @build_lists.recent.paginate(page: current_page)
2013-08-01 18:18:46 +01:00
2014-01-21 04:51:49 +00:00
render partial: 'build_lists_ajax', layout: false
2013-08-01 18:18:46 +01:00
end
def update_type
respond_to do |format|
format.html { render nothing: true }
format.json do
@build_list.update_type = params[:update_type]
if @build_list.save
render json: 'success', status: :ok
else
render json: { message: @build_list.errors.full_messages.join('. ') },
status: :unprocessable_entity
end
end
end
end
2013-08-01 18:18:46 +01:00
protected
2014-05-21 23:58:13 +01:00
def do_and_back(action, prefix, success = 'success', fail = 'fail')
result = @build_list.send("can_#{action}?") && @build_list.send(action)
2014-05-21 23:58:13 +01:00
message = result ? success : fail
flash[result ? :notice : :error] = t("layout.build_lists.#{prefix}#{message}")
redirect_to :back
end
def find_build_list
@build_list = BuildList.find(params[:id])
end
2013-07-31 15:57:02 +01:00
2013-08-03 04:58:45 +01:00
def create_from_build_list
return if params[:build_list_id].blank?
2014-04-07 22:54:12 +01:00
build_list = @project.build_lists.find(params[:build_list_id])
2013-08-03 04:58:45 +01:00
2013-07-31 15:57:02 +01:00
params[:build_list] ||= {}
keys = [
:save_to_repository_id, :auto_publish_status, :include_repos,
:extra_params, :project_version, :update_type, :auto_create_container,
:extra_repositories, :extra_build_lists, :build_for_platform_id,
:use_cached_chroot, :use_extra_tests, :save_buildroot,
:include_testing_subrepository, :external_nodes
]
2013-08-08 13:49:33 +01:00
keys.each { |key| params[:build_list][key] = build_list.send(key) }
params[:arches] = [build_list.arch_id]
2013-08-01 18:18:46 +01:00
[:owner_filter, :status_filter].each { |t| params[t] = 'true' if %w(true undefined).exclude? params[t] }
2012-05-04 18:12:51 +01:00
end
2011-04-22 13:08:58 +01:00
end