From 38b6375ca36a57de796cf8ba4d56998d208794a1 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 22 Feb 2013 13:09:37 +0400 Subject: [PATCH] #757: send error when some containers for main platform have not been published --- app/controllers/api/v1/build_lists_controller.rb | 6 +++++- app/controllers/projects/build_lists_controller.rb | 8 ++++++-- app/models/build_list.rb | 10 +++++----- config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index 79d3c04b4..91ef7e03b 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -33,7 +33,11 @@ class Api::V1::BuildListsController < Api::V1::BaseController end def publish - render_json :publish + if @build_list.can_publish_to_repository? + render_json :publish + else + render_validation_error @build_list, t('layout.build_lists.publish_with_extra_fail') + end end def reject_publish diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index ed5b0d4bc..ec08884b8 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -173,8 +173,12 @@ class Projects::BuildListsController < Projects::BaseController end - if @build_list.save and @build_list.now_publish - redirect_to :back, :notice => t('layout.build_lists.publish_success') + if @build_list.save && @build_list.can_publish? + if @build_list.can_publish_to_repository? && @build_list.now_publish + redirect_to :back, :notice => t('layout.build_lists.publish_success') + else + redirect_to :back, :notice => t('layout.build_lists.publish_with_extra_fail') + end else redirect_to :back, :notice => t('layout.build_lists.publish_fail') end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 836da910f..ec9c86a53 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -287,6 +287,11 @@ class BuildList < ActiveRecord::Base [SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED].include? status end + def can_publish_to_repository? + return true unless save_to_platform.main? + BuildList.where(:id => extra_containers).where('status != ?', BUILD_PUBLISHED).count == 0 + end + def can_reject_publish? can_publish? && !save_to_repository.publish_without_qa && !build_published? end @@ -502,9 +507,4 @@ class BuildList < ActiveRecord::Base self.extra_containers = bls.pluck('build_lists.id') end - def can_publish_to_repository? - return true unless save_to_platform.main? - BuildList.where(:id => extra_containers).where('status != ?', BUILD_PUBLISHED).count == 0 - end - end \ No newline at end of file diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 02d309300..ed1ea5087 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -80,6 +80,7 @@ en: create_container_fail: 'Errors during container creating!' publish_success: 'Build is queued for publishing' publish_fail: 'Errors during build publishing!' + publish_with_extra_fail: 'All extra containers should be published before publishing this build list!' cancel_success: 'Build canceled' cancel_fail: 'Errors during build cancelation!' reject_publish_success: 'Publishing rejected' diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 4dd649c97..784f49aa1 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -81,6 +81,7 @@ ru: cancel_fail: 'При отмене сборки произошла ошибка!' publish_success: 'Сборка поставлена в очередь на публикацию.' publish_fail: 'При публикации сборки произошла ошибка!' + publish_with_extra_fail: 'Все дополнительные контейнеры должны быть опубликованы до публикации этой сборки!' reject_publish_success: 'Публикация отклонена' reject_publish_fail: 'Не удалось отклонить публикацию сборки' container_published: 'Контейнер размещен в репозитории'