diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-12 15:10:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-12 15:10:49 +0300 |
commit | bbfd13e575237aaa69a49caf1e23ebd878c2f824 (patch) | |
tree | ecf9f7db38629b98b804dfdfc23ab7234bdd642d /app/models/namespace | |
parent | 9c07ab8c6975de1046bd65b36f3d34f5408dac13 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/namespace')
-rw-r--r-- | app/models/namespace/package_setting.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/namespace/package_setting.rb b/app/models/namespace/package_setting.rb index 2c34bd9edcc..a2064e020b3 100644 --- a/app/models/namespace/package_setting.rb +++ b/app/models/namespace/package_setting.rb @@ -4,9 +4,25 @@ class Namespace::PackageSetting < ApplicationRecord self.primary_key = :namespace_id self.table_name = 'namespace_package_settings' + PackageSettingNotImplemented = Class.new(StandardError) + + PACKAGES_WITH_SETTINGS = %w[maven].freeze + belongs_to :namespace, inverse_of: :package_setting_relation validates :namespace, presence: true validates :maven_duplicates_allowed, inclusion: { in: [true, false] } validates :maven_duplicate_exception_regex, untrusted_regexp: true, length: { maximum: 255 } + + class << self + def duplicates_allowed?(package) + return true unless package + raise PackageSettingNotImplemented unless PACKAGES_WITH_SETTINGS.include?(package.package_type) + + duplicates_allowed = package.package_settings["#{package.package_type}_duplicates_allowed"] + regex = ::Gitlab::UntrustedRegexp.new("\\A#{package.package_settings["#{package.package_type}_duplicate_exception_regex"]}\\z") + + duplicates_allowed || regex.match?(package.name) + end + end end |