2012-07-31 08:35:27 +01:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
class Api::V1::BuildListsController < Api::V1::BaseController
|
2012-10-11 11:55:06 +01:00
|
|
|
|
2012-09-26 18:15:11 +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
|
|
|
|
2012-07-31 08:35:27 +01:00
|
|
|
load_and_authorize_resource :project, :only => :index
|
2012-09-26 18:15:11 +01:00
|
|
|
load_and_authorize_resource :build_list, :only => [:show, :create, :cancel, :publish, :reject_publish]
|
2012-10-11 11:55:06 +01:00
|
|
|
|
2012-07-31 08:35:27 +01:00
|
|
|
def index
|
|
|
|
filter = BuildList::Filter.new(nil, 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)
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-10-10 17:19:00 +01:00
|
|
|
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
|
2012-09-03 14:49:11 +01:00
|
|
|
|
2012-10-10 17:19:00 +01:00
|
|
|
if project && 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?
|
2012-08-09 15:38:41 +01:00
|
|
|
|
2012-10-10 17:19:00 +01:00
|
|
|
@build_list = project.build_lists.build(bl_params)
|
2012-07-31 08:35:27 +01:00
|
|
|
|
2012-10-10 17:19:00 +01:00
|
|
|
@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
|
2012-09-03 14:49:11 +01:00
|
|
|
else
|
2012-10-10 17:19:00 +01:00
|
|
|
render :json => {:message => "Bad Request"}.to_json, :status => 400
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
2012-08-08 20:16:27 +01:00
|
|
|
render_json :cancel
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def publish
|
2012-08-08 20:16:27 +01:00
|
|
|
render_json :publish
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def reject_publish
|
2012-08-08 20:16:27 +01:00
|
|
|
render_json :reject_publish
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def render_json(action_name)
|
2012-11-28 14:52:11 +00:00
|
|
|
res, message = if !@build_list.send "can_#{action_name}?"
|
2012-11-28 15:29:34 +00:00
|
|
|
[false, "Incorrect action for current build list"]
|
2012-11-28 14:52:11 +00:00
|
|
|
elsif @build_list.send(action_name)
|
|
|
|
[true, t("layout.build_lists.#{action_name}_success")]
|
|
|
|
else
|
|
|
|
[false, t("layout.build_lists.#{action_name}_fail")]
|
|
|
|
end
|
2012-07-31 08:35:27 +01:00
|
|
|
|
2012-11-28 14:52:11 +00:00
|
|
|
render :json => {:"is_#{action_name}ed" => res, :url => api_v1_build_list_path(@build_list, :format => :json), :message => message}
|
|
|
|
end
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|