#859: update BuildList API

This commit is contained in:
Vokhmin Alexey V 2013-01-30 20:23:50 +04:00
parent 8677831e61
commit 2a1a15eb03
2 changed files with 21 additions and 25 deletions

View File

@ -15,26 +15,18 @@ class Api::V1::BuildListsController < Api::V1::BaseController
def create def create
bl_params = params[:build_list] || {} bl_params = params[:build_list] || {}
project = Project.where(:id => bl_params[:project_id]).first
save_to_repository = Repository.where(:id => bl_params[:save_to_repository_id]).first save_to_repository = Repository.where(:id => bl_params[:save_to_repository_id]).first
if project && save_to_repository if save_to_repository
bl_params[:save_to_platform_id] = save_to_repository.platform_id bl_params[:save_to_platform_id] = save_to_repository.platform_id
bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa? bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa?
@build_list = project.build_lists.build(bl_params)
@build_list.user = current_user
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
if @build_list.save
render :action => 'show'
else
render :json => {:message => "Validation Failed", :errors => @build_list.errors.messages}.to_json, :status => 422
end
else
render :json => {:message => "Bad Request"}.to_json, :status => 400
end end
@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
create_subject @build_list
end end
def cancel def cancel
@ -49,17 +41,19 @@ class Api::V1::BuildListsController < Api::V1::BaseController
render_json :reject_publish render_json :reject_publish
end end
def create_container
render_json :create_container
end
private private
def render_json(action_name) def render_json(action_name)
res, message = if !@build_list.send "can_#{action_name}?" if !@build_list.send "can_#{action_name}?"
[false, "Incorrect action for current build list"] render_validation_error @build_list, "Incorrect action for current build list")
elsif @build_list.send(action_name) elsif @build_list.send(action_name)
[true, t("layout.build_lists.#{action_name}_success")] render_json_response @build_list, t("layout.build_lists.#{action_name}_success")
else else
[false, t("layout.build_lists.#{action_name}_fail")] render_validation_error @build_list, t("layout.build_lists.#{action_name}_fail")
end end
render :json => {:"is_#{action_name}ed" => res, :url => api_v1_build_list_path(@build_list, :format => :json), :message => message}
end end
end end

View File

@ -223,7 +223,9 @@ class BuildList < ActiveRecord::Base
:do => :remove_container :do => :remove_container
event :publish_container do event :publish_container do
transition [:waiting_for_publish, :container_failed_publish] => :container_publish transition [:waiting_for_publish, :container_failed_publish] => :container_publish, :if => lambda { |build_list|
build_list.success?
}
end end
event :published_container do event :published_container do