diff --git a/app/helpers/platforms_helper.rb b/app/helpers/platforms_helper.rb index bcf24a791..aec00b490 100644 --- a/app/helpers/platforms_helper.rb +++ b/app/helpers/platforms_helper.rb @@ -12,6 +12,12 @@ module PlatformsHelper end end + def platform_project_list_type_options + %w(blacklist whitelist).map do |v| + [ I18n.t("activerecord.attributes.platform.project_list_types.#{v}"), Platform.const_get("PROJECT_LIST_TYPE_#{v.upcase}")] + end + end + def repository_name_postfix(platform) return "" unless platform return platform.released ? '/update' : '/release' diff --git a/app/models/build_list.rb b/app/models/build_list.rb index f870e9f93..c69bae0d0 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -336,6 +336,16 @@ 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_platform? + return true unless save_to_platform.project_list_active + if save_to_platform.project_list_type == Platform::PROJECT_LIST_TYPE_BLACKLIST + return false if save_to_platform.project_list.split("\n").include?(project.name) + else + return false unless save_to_platform.project_list.split("\n").include?(project.name) + end + return true + 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) @@ -381,6 +391,7 @@ class BuildList < ActiveRecord::Base def can_publish? super && + can_publish_into_platform? && valid_branch_for_publish? && extra_build_lists_published? && save_to_repository.projects.exists?(id: project_id) diff --git a/app/models/platform.rb b/app/models/platform.rb index 4346ee193..8b30a6be8 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -25,6 +25,11 @@ class Platform < ActiveRecord::Base TYPE_MAIN = 'main' ] + PROJECT_LIST_TYPES = [ + PROJECT_LIST_TYPE_BLACKLIST = 0, + PROJECT_LIST_TYPE_WHITELIST = 1 + ] + belongs_to :parent, class_name: 'Platform', foreign_key: 'parent_platform_id' belongs_to :owner, polymorphic: true @@ -74,6 +79,10 @@ class Platform < ActiveRecord::Base presence: true, inclusion: { in: APP_CONFIG['distr_types'] } + validates :project_list_type, + presence: true, + inclusion: { in: PROJECT_LIST_TYPES } + validate -> { if released_was && !released errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed')) @@ -89,6 +98,7 @@ class Platform < ActiveRecord::Base before_create :create_directory before_destroy :detele_directory + before_save :fix_project_list after_update :freeze_platform_and_update_repos after_update :update_owner_relation @@ -281,6 +291,11 @@ class Platform < ActiveRecord::Base protected + def fix_project_list + existing = projects.where(name: self.project_list.split("\r\n")).pluck(:name) + self.project_list = existing.join("\n") + end + def create_directory system("mkdir -p -m 0777 #{build_path([name, 'repository'])}") end diff --git a/app/policies/platform_policy.rb b/app/policies/platform_policy.rb index efef3ee2e..0e1892458 100644 --- a/app/policies/platform_policy.rb +++ b/app/policies/platform_policy.rb @@ -78,6 +78,9 @@ class PlatformPolicy < ApplicationPolicy released term visibility + project_list + project_list_type + project_list_active ) + [ platform_arch_settings_attributes: %i(id arch_id platform_id default time_living) ] diff --git a/app/views/platforms/platforms/_form.html.slim b/app/views/platforms/platforms/_form.html.slim index 8826f8acb..7e7a89937 100644 --- a/app/views/platforms/platforms/_form.html.slim +++ b/app/views/platforms/platforms/_form.html.slim @@ -24,6 +24,13 @@ = f.input :default_branch +h3 + = t('layout.platforms.publish_lists') + += f.input :project_list_active, as: :boolean += f.input :project_list_type, collection: platform_project_list_type_options, include_blank: false += f.input :project_list, as: :text, input_html: {rows: 10} + - if %w(edit update).include? controller.action_name - unless @platform.personal? diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index af4e7467d..0369487d9 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -51,6 +51,7 @@ en: change_visibility_from_open: Change status to "Private" confirm_change_visibility: Are you sure you want to change visibility of this platform? metadata: Metadata for Software Center + publish_lists: Publishing black/white project lists flash: platform: @@ -94,6 +95,9 @@ en: visibility_types: open: Public hidden: Private + project_list_types: + blacklist: Blacklist + whitelist: Whitelist simple_form: labels: diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index 7a788877a..ac38a4145 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -52,7 +52,7 @@ ru: change_visibility_from_open: Сменить статус на "Приватный" confirm_change_visibility: Вы уверены, что хотите сменить статус этой платформы? metadata: Метаданные для Software Center - + publish_lists: Чёрные/белые списки публикации проектов flash: platform: released_status_can_not_be_changed: Released статус платформы не может быть изменен, если платформа уже выпущена diff --git a/db/migrate/20190210143409_add_black_lists_to_platforms.rb b/db/migrate/20190210143409_add_black_lists_to_platforms.rb new file mode 100644 index 000000000..eea6998b9 --- /dev/null +++ b/db/migrate/20190210143409_add_black_lists_to_platforms.rb @@ -0,0 +1,7 @@ +class AddBlackListsToPlatforms < ActiveRecord::Migration + def change + add_column :platforms, :project_list, :string, default: '' + add_column :platforms, :project_list_type, :integer, default: 0 + add_column :platforms, :project_list_active, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8611beee8..2bbcedd53 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190210140249) do +ActiveRecord::Schema.define(version: 20190210143409) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -218,6 +218,9 @@ ActiveRecord::Schema.define(version: 20190210140249) do t.string "last_regenerated_log_sha1" t.string "automatic_metadata_regeneration" t.string "default_branch", :null=>false + t.string "project_list", :default=>"" + t.integer "project_list_type", :default=>0 + t.boolean "project_list_active", :default=>false end create_table "product_build_lists", force: :cascade do |t|