Skip to content
代码片段 群组 项目
未验证 提交 e73413f9 编辑于 作者: Dzmitry Meshcharakou's avatar Dzmitry Meshcharakou 提交者: GitLab
浏览文件

Merge branch...

Merge branch '416382-gerardo-navarro-protected-packages-remove-unnecessary-attribute-package_name_pattern_ilike_query' into 'master' 

Protected packages: Drop col 'package_name_pattern_ilike_query' Part 1

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142299



Merged-by: default avatarDzmitry Meshcharakou <12459192-dmeshcharakou@users.noreply.gitlab.com>
Approved-by: default avatarSerena Fang <sfang@gitlab.com>
Approved-by: default avatarVitali Tatarintev <vtatarintev@gitlab.com>
Approved-by: default avatarTiger Watson <twatson@gitlab.com>
Approved-by: default avatarDzmitry Meshcharakou <12459192-dmeshcharakou@users.noreply.gitlab.com>
Reviewed-by: default avatarMayra Cabrera <mcabrera@gitlab.com>
Reviewed-by: default avatarDzmitry Meshcharakou <12459192-dmeshcharakou@users.noreply.gitlab.com>
Co-authored-by: default avatarGerardo <gerardo@b310.de>
No related branches found
No related tags found
无相关合并请求
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
module Packages module Packages
module Protection module Protection
class Rule < ApplicationRecord class Rule < ApplicationRecord
include IgnorableColumns
ignore_column :package_name_pattern_ilike_query, remove_with: '16.11', remove_after: '2024-03-22'
enum package_type: Packages::Package.package_types.slice(:npm) enum package_type: Packages::Package.package_types.slice(:npm)
enum push_protected_up_to_access_level: enum push_protected_up_to_access_level:
Gitlab::Access.sym_options_with_owner.slice(:developer, :maintainer, :owner), Gitlab::Access.sym_options_with_owner.slice(:developer, :maintainer, :owner),
...@@ -21,8 +24,6 @@ class Rule < ApplicationRecord ...@@ -21,8 +24,6 @@ class Rule < ApplicationRecord
validates :package_type, presence: true validates :package_type, presence: true
validates :push_protected_up_to_access_level, presence: true validates :push_protected_up_to_access_level, presence: true
before_save :set_package_name_pattern_ilike_query, if: :package_name_pattern_changed?
scope :for_package_name, ->(package_name) do scope :for_package_name, ->(package_name) do
return none if package_name.blank? return none if package_name.blank?
...@@ -39,17 +40,6 @@ def self.for_push_exists?(access_level:, package_name:, package_type:) ...@@ -39,17 +40,6 @@ def self.for_push_exists?(access_level:, package_name:, package_type:)
.for_package_name(package_name) .for_package_name(package_name)
.exists? .exists?
end end
private
# We want to allow wildcard pattern (`*`) for the field `package_name_pattern`
# , e.g. `@my-scope/my-package-*`, etc.
# Therefore, we need to preprocess the field value before we can use the field in the ILIKE clause.
# E.g. convert wildcard character (`*`) to LIKE match character (`%`), escape certain characters, etc.
def set_package_name_pattern_ilike_query
self.package_name_pattern_ilike_query = self.class.sanitize_sql_like(package_name_pattern)
.tr('*', '%')
end
end end
end end
end end
# frozen_string_literal: true
class RemoveNotNullConstraintFromPackageNamePatternIlikeQueryColumn < Gitlab::Database::Migration[2.2]
disable_ddl_transaction!
milestone '16.9'
def up
change_column_null :packages_protection_rules, :package_name_pattern_ilike_query, true
end
def down
change_column_null :packages_protection_rules, :package_name_pattern_ilike_query, false
end
end
5856d91dec985d1de03ae428be8504404f1e38e18bad933c5d311d2019ac725c
\ No newline at end of file
...@@ -21152,7 +21152,7 @@ CREATE TABLE packages_protection_rules ( ...@@ -21152,7 +21152,7 @@ CREATE TABLE packages_protection_rules (
push_protected_up_to_access_level smallint NOT NULL, push_protected_up_to_access_level smallint NOT NULL,
package_type smallint NOT NULL, package_type smallint NOT NULL,
package_name_pattern text NOT NULL, package_name_pattern text NOT NULL,
package_name_pattern_ilike_query text NOT NULL, package_name_pattern_ilike_query text,
CONSTRAINT check_d2d75d206d CHECK ((char_length(package_name_pattern) <= 255)), CONSTRAINT check_d2d75d206d CHECK ((char_length(package_name_pattern) <= 255)),
CONSTRAINT check_ff47b09794 CHECK ((char_length(package_name_pattern_ilike_query) <= 255)) CONSTRAINT check_ff47b09794 CHECK ((char_length(package_name_pattern_ilike_query) <= 255))
); );
...@@ -73,28 +73,6 @@ ...@@ -73,28 +73,6 @@
end end
end end
describe 'before_save' do
describe '#set_package_name_pattern_ilike_query' do
subject { create(:package_protection_rule, package_name_pattern: package_name_pattern) }
context 'with different package name patterns' do
where(:package_name_pattern, :expected_pattern_query) do
'@my-scope/my-package' | '@my-scope/my-package'
'@my-scope/*my-package-with-wildcard-start' | '@my-scope/%my-package-with-wildcard-start'
'@my-scope/my-package-with-wildcard-end*' | '@my-scope/my-package-with-wildcard-end%'
'@my-scope/my-package*with-wildcard-inbetween' | '@my-scope/my-package%with-wildcard-inbetween'
'@my-scope/**my-package-**-with-wildcard-multiple**' | '@my-scope/%%my-package-%%-with-wildcard-multiple%%'
'@my-scope/my-package-with_____underscore' | '@my-scope/my-package-with\_\_\_\_\_underscore'
'@my-scope/my-package-with-regex-characters.+' | '@my-scope/my-package-with-regex-characters.+'
end
with_them do
it { is_expected.to have_attributes(package_name_pattern_ilike_query: expected_pattern_query) }
end
end
end
end
describe '.for_package_name' do describe '.for_package_name' do
let_it_be(:package_protection_rule) do let_it_be(:package_protection_rule) do
create(:package_protection_rule, package_name_pattern: '@my-scope/my_package') create(:package_protection_rule, package_name_pattern: '@my-scope/my_package')
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册