2012-07-31 08:35:27 +01:00
|
|
|
class Api::V1::BuildListsController < Api::V1::BaseController
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :authenticate_user!
|
2015-03-19 23:31:41 +00:00
|
|
|
before_action :load_build_list, only: %i(
|
|
|
|
cancel
|
|
|
|
create_container
|
|
|
|
publish
|
|
|
|
publish_into_testing
|
|
|
|
reject_publish
|
|
|
|
rerun_tests
|
|
|
|
show
|
|
|
|
)
|
2016-03-24 15:59:12 +00:00
|
|
|
skip_before_action :check_auth, only: %i(show index) if APP_CONFIG['anonymous_access']
|
2015-03-19 23:31:41 +00:00
|
|
|
skip_before_action :authenticate_user!, only: %i(show index) if APP_CONFIG['anonymous_access']
|
2012-10-11 11:55:06 +01:00
|
|
|
|
2014-08-28 21:22:11 +01:00
|
|
|
def show
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize @build_list
|
2014-08-28 21:46:42 +01:00
|
|
|
respond_to :json
|
2014-08-28 21:22:11 +01:00
|
|
|
end
|
|
|
|
|
2012-07-31 08:35:27 +01:00
|
|
|
def index
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize :build_list
|
2014-12-09 13:32:55 +00:00
|
|
|
@project = Project.find(params[:project_id]) if params[:project_id].present?
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize @project, :show? if @project
|
2015-03-25 00:17:17 +00:00
|
|
|
filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
|
2014-12-09 15:33:27 +00:00
|
|
|
@build_lists = filter.find.includes(:build_for_platform,
|
|
|
|
:save_to_repository,
|
|
|
|
:save_to_platform,
|
|
|
|
:project,
|
|
|
|
:user,
|
|
|
|
:arch)
|
|
|
|
|
2012-10-10 13:02:59 +01:00
|
|
|
@build_lists = @build_lists.recent.paginate(paginate_params)
|
2014-08-28 21:46:42 +01:00
|
|
|
respond_to :json
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-04-27 23:14:49 +01:00
|
|
|
save_to_repository = Repository.find_by(id: build_list_params[:save_to_repository_id])
|
2012-09-03 14:49:11 +01:00
|
|
|
|
2015-04-27 23:14:49 +01:00
|
|
|
@build_list = current_user.build_lists.new(build_list_params)
|
|
|
|
@build_list.save_to_platform = save_to_repository.platform if save_to_repository
|
|
|
|
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
|
2012-10-10 17:19:00 +01:00
|
|
|
|
2013-01-30 16:23:50 +00:00
|
|
|
create_subject @build_list
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @build_list
|
2012-08-08 20:16:27 +01:00
|
|
|
render_json :cancel
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def publish
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @build_list
|
2013-03-28 11:58:26 +00:00
|
|
|
@build_list.publisher = current_user
|
2012-08-08 20:16:27 +01:00
|
|
|
render_json :publish
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def reject_publish
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @build_list
|
2013-05-30 11:41:09 +01:00
|
|
|
@build_list.publisher = current_user
|
2012-08-08 20:16:27 +01:00
|
|
|
render_json :reject_publish
|
|
|
|
end
|
|
|
|
|
2013-01-30 16:23:50 +00:00
|
|
|
def create_container
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @build_list
|
2013-01-30 20:51:05 +00:00
|
|
|
render_json :create_container, :publish_container
|
2013-01-30 16:23:50 +00:00
|
|
|
end
|
|
|
|
|
2014-05-22 19:08:43 +01:00
|
|
|
def rerun_tests
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @build_list
|
2014-05-22 19:08:43 +01:00
|
|
|
render_json :rerun_tests
|
|
|
|
end
|
|
|
|
|
2013-11-18 17:48:38 +00:00
|
|
|
def publish_into_testing
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @build_list
|
2013-11-18 17:48:38 +00:00
|
|
|
@build_list.publisher = current_user
|
|
|
|
render_json :publish_into_testing
|
|
|
|
end
|
|
|
|
|
2012-08-08 20:16:27 +01:00
|
|
|
private
|
|
|
|
|
2015-04-27 23:14:49 +01:00
|
|
|
def build_list_params
|
2015-04-28 23:28:36 +01:00
|
|
|
subject_params(BuildList)
|
2015-04-27 23:14:49 +01:00
|
|
|
end
|
|
|
|
|
2015-03-19 23:31:41 +00:00
|
|
|
# Private: before_action hook which loads BuidList.
|
|
|
|
def load_build_list
|
|
|
|
@build_list = BuildList.find params[:id]
|
|
|
|
end
|
|
|
|
|
2013-01-30 20:51:05 +00:00
|
|
|
def render_json(action_name, action_method = nil)
|
|
|
|
if @build_list.try("can_#{action_name}?") && @build_list.send(action_method || 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
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|