diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-11 06:12:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-11 06:12:21 +0300 |
commit | 9fbfd2ebf45c0d22b844306c51b673106e1fdf17 (patch) | |
tree | 681d21abcfadb2843eab19e42a2f3ed198dd0729 /app/models/packages | |
parent | 18ad304adc191b31f11a311fc4b89e3ea8f0f328 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/package.rb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index ca0ffc19019..c76473c9438 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -63,12 +63,17 @@ class Packages::Package < ApplicationRecord validates :name, format: { with: Gitlab::Regex.package_name_regex }, unless: -> { conan? || generic? || debian? } validates :name, - uniqueness: { scope: %i[project_id version package_type] }, unless: -> { conan? || debian_package? } - validate :unique_debian_package_name, if: :debian_package? + uniqueness: { + scope: %i[project_id version package_type], + conditions: -> { not_pending_destruction} + }, + unless: -> { pending_destruction? || conan? || debian_package? } + validate :unique_debian_package_name, if: :debian_package? validate :valid_conan_package_recipe, if: :conan? validate :valid_composer_global_name, if: :composer? validate :npm_package_already_taken, if: :npm? + validates :name, format: { with: Gitlab::Regex.conan_recipe_component_regex }, if: :conan? validates :name, format: { with: Gitlab::Regex.generic_package_name_regex }, if: :generic? validates :name, format: { with: Gitlab::Regex.helm_package_regex }, if: :helm? @@ -320,6 +325,7 @@ class Packages::Package < ApplicationRecord recipe_exists = project.packages .conan .includes(:conan_metadatum) + .not_pending_destruction .with_name(name) .with_version(version) .with_conan_channel(conan_metadatum.package_channel) @@ -334,9 +340,14 @@ class Packages::Package < ApplicationRecord # .default_scoped is required here due to a bug in rails that leaks # the scope and adds `self` to the query incorrectly # See https://github.com/rails/rails/pull/35186 - if Packages::Package.default_scoped.composer.with_name(name).where.not(project_id: project_id).exists? - errors.add(:name, 'is already taken by another project') - end + package_exists = Packages::Package.default_scoped + .composer + .not_pending_destruction + .with_name(name) + .where.not(project_id: project_id) + .exists? + + errors.add(:name, 'is already taken by another project') if package_exists end def npm_package_already_taken @@ -361,6 +372,7 @@ class Packages::Package < ApplicationRecord package_exists = debian_publication.distribution.packages .with_name(name) .with_version(version) + .not_pending_destruction .id_not_in(id) .exists? |