From 2a1a15eb03cd7c22d69ad88233ac3f8002ccd4e5 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 30 Jan 2013 20:23:50 +0400 Subject: [PATCH] #859: update BuildList API --- .../api/v1/build_lists_controller.rb | 42 ++++++++----------- app/models/build_list.rb | 4 +- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index 91e8ce058..452324f28 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -15,26 +15,18 @@ class Api::V1::BuildListsController < Api::V1::BaseController def create 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 - if project && save_to_repository + 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? - - @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 + + @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 def cancel @@ -49,17 +41,19 @@ class Api::V1::BuildListsController < Api::V1::BaseController render_json :reject_publish end + def create_container + render_json :create_container + end + private def render_json(action_name) - res, message = if !@build_list.send "can_#{action_name}?" - [false, "Incorrect action for current build list"] - elsif @build_list.send(action_name) - [true, t("layout.build_lists.#{action_name}_success")] - else - [false, t("layout.build_lists.#{action_name}_fail")] - end - - render :json => {:"is_#{action_name}ed" => res, :url => api_v1_build_list_path(@build_list, :format => :json), :message => message} + if !@build_list.send "can_#{action_name}?" + render_validation_error @build_list, "Incorrect action for current build list") + elsif @build_list.send(action_name) + 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 end end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index a27f67751..72d1a88b4 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -223,7 +223,9 @@ class BuildList < ActiveRecord::Base :do => :remove_container 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 event :published_container do