Add publish white/black project lists to platforms

This commit is contained in:
Wedge 2019-02-10 19:07:42 +03:00
parent 7b3d7d27a9
commit 82f35228c8
9 changed files with 58 additions and 2 deletions

View File

@ -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'

View File

@ -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)

View File

@ -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

View File

@ -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)
]

View File

@ -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?

View File

@ -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:

View File

@ -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 статус платформы не может быть изменен, если платформа уже выпущена

View File

@ -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

View File

@ -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|