summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-15 08:58:20 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-15 08:58:20 +0000
commit59c9ff627603da03f6a7c330d57a2c765b3c24a3 (patch)
treedd8f3a2fbc9564818a77d2d8798fcc464d220e8e /app
parent30b4659f2c485885324fd8d67fcd92a2939310a3 (diff)
downloadgitlab-ce-59c9ff627603da03f6a7c330d57a2c765b3c24a3.tar.gz
Add latest changes from gitlab-org/gitlab@14-7-stable-ee
Diffstat (limited to 'app')
-rw-r--r--app/models/packages/package.rb22
-rw-r--r--app/models/project.rb1
-rw-r--r--app/services/packages/create_package_service.rb1
-rw-r--r--app/services/packages/debian/find_or_create_package_service.rb1
-rw-r--r--app/services/packages/helm/process_file_service.rb1
-rw-r--r--app/services/packages/npm/create_package_service.rb1
-rw-r--r--app/services/packages/nuget/update_package_from_metadata_service.rb1
-rw-r--r--app/services/packages/rubygems/process_gem_service.rb1
-rw-r--r--app/services/packages/terraform_module/create_package_service.rb2
9 files changed, 26 insertions, 5 deletions
diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb
index 1b2c3e25283..4a97ae97ea0 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?
diff --git a/app/models/project.rb b/app/models/project.rb
index f2b3db684ae..7f823b5ed6b 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -2614,6 +2614,7 @@ class Project < ApplicationRecord
Packages::Package.with_name(package_name)
.with_version(package_version)
.with_package_type(package_type)
+ .not_pending_destruction
.for_projects(
root_ancestor.all_projects
.id_not_in(id)
diff --git a/app/services/packages/create_package_service.rb b/app/services/packages/create_package_service.rb
index 7e1b6ecbe51..7565b017a64 100644
--- a/app/services/packages/create_package_service.rb
+++ b/app/services/packages/create_package_service.rb
@@ -11,6 +11,7 @@ module Packages
project
.packages
.with_package_type(package_type)
+ .not_pending_destruction
.find_or_create_by!(name: name, version: version) do |package|
package.status = params[:status] if params[:status]
package.creator = package_creator
diff --git a/app/services/packages/debian/find_or_create_package_service.rb b/app/services/packages/debian/find_or_create_package_service.rb
index 46e06c9f584..3b2be7b6874 100644
--- a/app/services/packages/debian/find_or_create_package_service.rb
+++ b/app/services/packages/debian/find_or_create_package_service.rb
@@ -11,6 +11,7 @@ module Packages
.with_name(params[:name])
.with_version(params[:version])
.with_debian_codename(params[:distribution_name])
+ .not_pending_destruction
.first
package ||= create_package!(
diff --git a/app/services/packages/helm/process_file_service.rb b/app/services/packages/helm/process_file_service.rb
index 31b357c1616..f53c63d2b01 100644
--- a/app/services/packages/helm/process_file_service.rb
+++ b/app/services/packages/helm/process_file_service.rb
@@ -68,6 +68,7 @@ module Packages
package = project_packages.with_package_type(:helm)
.with_name(metadata['name'])
.with_version(metadata['version'])
+ .not_pending_destruction
.last
package || temp_package
end
diff --git a/app/services/packages/npm/create_package_service.rb b/app/services/packages/npm/create_package_service.rb
index 76a7f3bdc72..b0a5f37cfa3 100644
--- a/app/services/packages/npm/create_package_service.rb
+++ b/app/services/packages/npm/create_package_service.rb
@@ -33,6 +33,7 @@ module Packages
.npm
.with_name(name)
.with_version(version)
+ .not_pending_destruction
.exists?
end
diff --git a/app/services/packages/nuget/update_package_from_metadata_service.rb b/app/services/packages/nuget/update_package_from_metadata_service.rb
index d1e47ad00a1..5456ad4cad7 100644
--- a/app/services/packages/nuget/update_package_from_metadata_service.rb
+++ b/app/services/packages/nuget/update_package_from_metadata_service.rb
@@ -98,6 +98,7 @@ module Packages
.nuget
.with_name(package_name)
.with_version(package_version)
+ .not_pending_destruction
.first
end
end
diff --git a/app/services/packages/rubygems/process_gem_service.rb b/app/services/packages/rubygems/process_gem_service.rb
index 109c87a0444..c771af28f73 100644
--- a/app/services/packages/rubygems/process_gem_service.rb
+++ b/app/services/packages/rubygems/process_gem_service.rb
@@ -91,6 +91,7 @@ module Packages
.rubygems
.with_name(gemspec.name)
.with_version(gemspec.version.to_s)
+ .not_pending_destruction
.last
package || temp_package
end
diff --git a/app/services/packages/terraform_module/create_package_service.rb b/app/services/packages/terraform_module/create_package_service.rb
index d1bc79089a3..3afecc6c1ca 100644
--- a/app/services/packages/terraform_module/create_package_service.rb
+++ b/app/services/packages/terraform_module/create_package_service.rb
@@ -29,6 +29,7 @@ module Packages
.for_projects(project.root_namespace.all_projects.id_not_in(project.id))
.with_package_type(:terraform_module)
.with_name(name)
+ .not_pending_destruction
.exists?
end
@@ -37,6 +38,7 @@ module Packages
.with_package_type(:terraform_module)
.with_name(name)
.with_version(params[:module_version])
+ .not_pending_destruction
.exists?
end