rosa-build/app/controllers/api/v1/build_lists_controller.rb

62 lines
2.0 KiB
Ruby
Raw Normal View History

# -*- encoding : utf-8 -*-
class Api::V1::BuildListsController < Api::V1::BaseController
2012-10-11 11:55:06 +01:00
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index] if APP_CONFIG['anonymous_access']
2012-10-11 11:55:06 +01:00
load_and_authorize_resource :project, :only => :index
2013-01-30 20:04:19 +00:00
load_and_authorize_resource :build_list, :only => [:show, :create, :cancel, :publish, :reject_publish, :create_container]
2012-10-11 11:55:06 +01:00
def index
filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
@build_lists = filter.find.scoped(:include => [:save_to_platform, :project, :user, :arch])
2012-10-10 13:02:59 +01:00
@build_lists = @build_lists.recent.paginate(paginate_params)
end
def create
bl_params = params[:build_list] || {}
save_to_repository = Repository.where(:id => bl_params[:save_to_repository_id]).first
2013-01-30 16:23:50 +00:00
if save_to_repository
bl_params[:save_to_platform_id] = save_to_repository.platform_id
bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa?
2013-01-30 16:23:50 +00:00
end
2013-01-30 16:23:50 +00:00
@build_list = BuildList.new(bl_params)
@build_list.user = current_user
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
2013-01-30 16:23:50 +00:00
create_subject @build_list
end
def cancel
2012-08-08 20:16:27 +01:00
render_json :cancel
end
def publish
2012-08-08 20:16:27 +01:00
render_json :publish
end
def reject_publish
2012-08-08 20:16:27 +01:00
render_json :reject_publish
end
2013-01-30 16:23:50 +00:00
def create_container
2013-01-30 20:42:37 +00:00
if @build_list.can_create_container? && @build_list.publish_container
2013-01-30 20:04:19 +00:00
render_json_response @build_list, t('layout.build_lists.create_container_success')
else
render_validation_error @build_list, t('layout.build_lists.create_container_fail')
end
2013-01-30 16:23:50 +00:00
end
2012-08-08 20:16:27 +01:00
private
def render_json(action_name)
2013-01-30 20:04:19 +00:00
if @build_list.try("can_#{action_name}?") && @build_list.send(action_name)
2013-01-30 16:23:50 +00:00
render_json_response @build_list, t("layout.build_lists.#{action_name}_success")
else
render_validation_error @build_list, t("layout.build_lists.#{action_name}_fail")
end
2012-11-28 14:52:11 +00:00
end
end