diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 843cab408..24b3b34e9 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -47,6 +47,11 @@ class BuildList < ActiveRecord::Base validate lambda { errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_project')) unless save_to_repository.projects.exists?(project_id) } + validate lambda { + if status == BUILD_PUBLISH && !can_publish_into_repository? + errors.add(:save_to_repository, I18n.t('flash.build_list.not_all_build_lists_success')) + end + } before_validation lambda { self.include_repos = include_repos.uniq if include_repos.present? }, :on => :create before_validation :prepare_extra_repositories, :on => :create before_validation :prepare_extra_build_lists, :on => :create @@ -313,6 +318,27 @@ class BuildList < ActiveRecord::Base [SUCCESS, BUILD_PUBLISH, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status) end + def can_publish_into_repository? + return true if !save_to_repository.synchronizing_publications? || save_to_platform.personal? || project.architecture_dependent? + arch_ids = save_to_platform.platform_arch_settings.by_default.pluck(:arch_id) + BuildList.where( + :project_id => project_id, + :save_to_repository_id => save_to_repository_id, + :arch_id => arch_ids, + :commit_hash => commit_hash, + :status => [ + SUCCESS, + BUILD_PUBLISHED, + BUILD_PUBLISH, + FAILED_PUBLISH, + TESTS_FAILED, + BUILD_PUBLISHED_INTO_TESTING, + BUILD_PUBLISH_INTO_TESTING, + FAILED_PUBLISH_INTO_TESTING + ] + ).group(:arch_id).count == arch_ids.size + end + #TODO: Share this checking on product owner. def can_cancel? build_started? || build_pending? diff --git a/db/migrate/20140113205657_add_synchronize_publication_to_repository.rb b/db/migrate/20140113205657_add_synchronize_publication_to_repository.rb new file mode 100644 index 000000000..ddf57995f --- /dev/null +++ b/db/migrate/20140113205657_add_synchronize_publication_to_repository.rb @@ -0,0 +1,5 @@ +class AddSynchronizePublicationToRepository < ActiveRecord::Migration + def change + add_column :repositories, :synchronizing_publications, :boolean, :default => false, :null => false + end +end diff --git a/db/schema.rb b/db/schema.rb index f90c5de5a..aa7a3851b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131126154305) do +ActiveRecord::Schema.define(:version => 20140113205657) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -487,12 +487,13 @@ ActiveRecord::Schema.define(:version => 20131126154305) do add_index "relations", ["target_type", "target_id"], :name => "index_relations_on_target_type_and_target_id" create_table "repositories", :force => true do |t| - t.string "description", :null => false - t.integer "platform_id", :null => false + t.string "description", :null => false + t.integer "platform_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "name", :null => false - t.boolean "publish_without_qa", :default => true + t.string "name", :null => false + t.boolean "publish_without_qa", :default => true + t.boolean "synchronizing_publications", :default => false, :null => false end add_index "repositories", ["platform_id"], :name => "index_repositories_on_platform_id"