Class: Namespace::PackageSetting

Inherits:
ApplicationRecord show all
Defined in:
app/models/namespace/package_setting.rb

Constant Summary collapse

PackageSettingNotImplemented =
Class.new(StandardError)
PACKAGES_WITH_SETTINGS =
%w[maven generic].freeze

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.duplicates_allowed?(package) ⇒ Boolean

Returns:

  • (Boolean)

Raises:


20
21
22
23
24
25
26
27
28
# File 'app/models/namespace/package_setting.rb', line 20

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) || regex.match?(package.version)
end