summaryrefslogtreecommitdiff
path: root/app/models/packages
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/models/packages
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
downloadgitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/models/packages')
-rw-r--r--app/models/packages/composer/cache_file.rb23
-rw-r--r--app/models/packages/composer/metadatum.rb3
-rw-r--r--app/models/packages/debian/group_component.rb9
-rw-r--r--app/models/packages/debian/group_component_file.rb9
-rw-r--r--app/models/packages/debian/project_component.rb9
-rw-r--r--app/models/packages/debian/project_component_file.rb9
-rw-r--r--app/models/packages/debian/project_distribution.rb3
-rw-r--r--app/models/packages/debian/publication.rb24
-rw-r--r--app/models/packages/package.rb28
-rw-r--r--app/models/packages/package_file.rb4
-rw-r--r--app/models/packages/rubygems/metadatum.rb24
11 files changed, 139 insertions, 6 deletions
diff --git a/app/models/packages/composer/cache_file.rb b/app/models/packages/composer/cache_file.rb
new file mode 100644
index 00000000000..ecd7596b989
--- /dev/null
+++ b/app/models/packages/composer/cache_file.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Packages
+ module Composer
+ class CacheFile < ApplicationRecord
+ include FileStoreMounter
+
+ self.table_name = 'packages_composer_cache_files'
+
+ mount_file_store_uploader Packages::Composer::CacheUploader
+
+ belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id'
+ belongs_to :namespace
+
+ validates :namespace, presence: true
+
+ scope :with_namespace, ->(namespace) { where(namespace: namespace) }
+ scope :with_sha, ->(sha) { where(file_sha256: sha) }
+ scope :expired, -> { where("delete_at <= ?", Time.current) }
+ scope :without_namespace, -> { where(namespace_id: nil) }
+ end
+ end
+end
diff --git a/app/models/packages/composer/metadatum.rb b/app/models/packages/composer/metadatum.rb
index 3026f5ea878..363858a3ed1 100644
--- a/app/models/packages/composer/metadatum.rb
+++ b/app/models/packages/composer/metadatum.rb
@@ -9,6 +9,9 @@ module Packages
belongs_to :package, -> { where(package_type: :composer) }, inverse_of: :composer_metadatum
validates :package, :target_sha, :composer_json, presence: true
+
+ scope :for_package, ->(name, project_id) { joins(:package).where(packages_packages: { name: name, project_id: project_id, package_type: Packages::Package.package_types[:composer] }) }
+ scope :locked_for_update, -> { lock('FOR UPDATE') }
end
end
end
diff --git a/app/models/packages/debian/group_component.rb b/app/models/packages/debian/group_component.rb
new file mode 100644
index 00000000000..81e02c363b0
--- /dev/null
+++ b/app/models/packages/debian/group_component.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class Packages::Debian::GroupComponent < ApplicationRecord
+ def self.container_type
+ :group
+ end
+
+ include Packages::Debian::Component
+end
diff --git a/app/models/packages/debian/group_component_file.rb b/app/models/packages/debian/group_component_file.rb
new file mode 100644
index 00000000000..333aab044a4
--- /dev/null
+++ b/app/models/packages/debian/group_component_file.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class Packages::Debian::GroupComponentFile < ApplicationRecord
+ def self.container_type
+ :group
+ end
+
+ include Packages::Debian::ComponentFile
+end
diff --git a/app/models/packages/debian/project_component.rb b/app/models/packages/debian/project_component.rb
new file mode 100644
index 00000000000..98cd7fd589b
--- /dev/null
+++ b/app/models/packages/debian/project_component.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class Packages::Debian::ProjectComponent < ApplicationRecord
+ def self.container_type
+ :project
+ end
+
+ include Packages::Debian::Component
+end
diff --git a/app/models/packages/debian/project_component_file.rb b/app/models/packages/debian/project_component_file.rb
new file mode 100644
index 00000000000..60ac29f91c2
--- /dev/null
+++ b/app/models/packages/debian/project_component_file.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class Packages::Debian::ProjectComponentFile < ApplicationRecord
+ def self.container_type
+ :project
+ end
+
+ include Packages::Debian::ComponentFile
+end
diff --git a/app/models/packages/debian/project_distribution.rb b/app/models/packages/debian/project_distribution.rb
index a73c12d172d..22f1008b3b5 100644
--- a/app/models/packages/debian/project_distribution.rb
+++ b/app/models/packages/debian/project_distribution.rb
@@ -5,5 +5,8 @@ class Packages::Debian::ProjectDistribution < ApplicationRecord
:project
end
+ has_many :publications, class_name: 'Packages::Debian::Publication', inverse_of: :distribution, foreign_key: :distribution_id
+ has_many :packages, class_name: 'Packages::Package', through: :publications
+
include Packages::Debian::Distribution
end
diff --git a/app/models/packages/debian/publication.rb b/app/models/packages/debian/publication.rb
new file mode 100644
index 00000000000..93f5aa11d81
--- /dev/null
+++ b/app/models/packages/debian/publication.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class Packages::Debian::Publication < ApplicationRecord
+ belongs_to :package,
+ -> { where(package_type: :debian).where.not(version: nil) },
+ inverse_of: :debian_publication,
+ class_name: 'Packages::Package'
+ belongs_to :distribution,
+ inverse_of: :publications,
+ class_name: 'Packages::Debian::ProjectDistribution',
+ foreign_key: :distribution_id
+
+ validates :package, presence: true
+ validate :valid_debian_package_type
+
+ validates :distribution, presence: true
+
+ private
+
+ def valid_debian_package_type
+ return errors.add(:package, _('type must be Debian')) unless package&.debian?
+ return errors.add(:package, _('must be a Debian package')) unless package.debian_package?
+ end
+end
diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb
index 2067a800ad5..391540634be 100644
--- a/app/models/packages/package.rb
+++ b/app/models/packages/package.rb
@@ -17,13 +17,18 @@ class Packages::Package < ApplicationRecord
has_one :maven_metadatum, inverse_of: :package, class_name: 'Packages::Maven::Metadatum'
has_one :nuget_metadatum, inverse_of: :package, class_name: 'Packages::Nuget::Metadatum'
has_one :composer_metadatum, inverse_of: :package, class_name: 'Packages::Composer::Metadatum'
+ has_one :rubygems_metadatum, inverse_of: :package, class_name: 'Packages::Rubygems::Metadatum'
has_many :build_infos, inverse_of: :package
has_many :pipelines, through: :build_infos
+ has_one :debian_publication, inverse_of: :package, class_name: 'Packages::Debian::Publication'
+ has_one :debian_distribution, through: :debian_publication, source: :distribution, inverse_of: :packages, class_name: 'Packages::Debian::ProjectDistribution'
accepts_nested_attributes_for :conan_metadatum
+ accepts_nested_attributes_for :debian_publication
accepts_nested_attributes_for :maven_metadatum
delegate :recipe, :recipe_path, to: :conan_metadatum, prefix: :conan
+ delegate :codename, :suite, to: :debian_distribution, prefix: :debian_distribution
validates :project, presence: true
validates :name, presence: true
@@ -31,7 +36,8 @@ 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?
+ uniqueness: { scope: %i[project_id version package_type] }, unless: -> { conan? || debian_package? }
+ validate :unique_debian_package_name, if: :debian_package?
validate :valid_conan_package_recipe, if: :conan?
validate :valid_npm_package_name, if: :npm?
@@ -59,7 +65,11 @@ class Packages::Package < ApplicationRecord
if: :debian_package?
validate :forbidden_debian_changes, if: :debian?
- enum package_type: { maven: 1, npm: 2, conan: 3, nuget: 4, pypi: 5, composer: 6, generic: 7, golang: 8, debian: 9 }
+ enum package_type: { maven: 1, npm: 2, conan: 3, nuget: 4, pypi: 5,
+ composer: 6, generic: 7, golang: 8, debian: 9,
+ rubygems: 10 }
+
+ enum status: { default: 0, hidden: 1, processing: 2 }
scope :with_name, ->(name) { where(name: name) }
scope :with_name_like, ->(name) { where(arel_table[:name].matches(name)) }
@@ -68,6 +78,8 @@ class Packages::Package < ApplicationRecord
scope :with_version, ->(version) { where(version: version) }
scope :without_version_like, -> (version) { where.not(arel_table[:version].matches(version)) }
scope :with_package_type, ->(package_type) { where(package_type: package_type) }
+ scope :with_status, ->(status) { where(status: status) }
+ scope :displayable, -> { with_status(:default) }
scope :including_build_info, -> { includes(pipelines: :user) }
scope :including_project_route, -> { includes(project: { namespace: :route }) }
scope :including_tags, -> { includes(:tags) }
@@ -251,6 +263,18 @@ class Packages::Package < ApplicationRecord
end
end
+ def unique_debian_package_name
+ return unless debian_publication&.distribution
+
+ package_exists = debian_publication.distribution.packages
+ .with_name(name)
+ .with_version(version)
+ .id_not_in(id)
+ .exists?
+
+ errors.add(:base, _('Debian package already exists in Distribution')) if package_exists
+ end
+
def forbidden_debian_changes
return unless persisted?
diff --git a/app/models/packages/package_file.rb b/app/models/packages/package_file.rb
index 389edaea392..9059f61b5de 100644
--- a/app/models/packages/package_file.rb
+++ b/app/models/packages/package_file.rb
@@ -55,10 +55,6 @@ class Packages::PackageFile < ApplicationRecord
Gitlab::Routing.url_helpers.download_project_package_file_path(project, self)
end
- def local?
- file_store == ::Packages::PackageFileUploader::Store::LOCAL
- end
-
private
def update_size_from_file
diff --git a/app/models/packages/rubygems/metadatum.rb b/app/models/packages/rubygems/metadatum.rb
new file mode 100644
index 00000000000..42db1f3defc
--- /dev/null
+++ b/app/models/packages/rubygems/metadatum.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Packages
+ module Rubygems
+ class Metadatum < ApplicationRecord
+ self.table_name = 'packages_rubygems_metadata'
+ self.primary_key = :package_id
+
+ belongs_to :package, -> { where(package_type: :rubygems) }, inverse_of: :rubygems_metadatum
+
+ validates :package, presence: true
+
+ validate :rubygems_package_type
+
+ private
+
+ def rubygems_package_type
+ unless package&.rubygems?
+ errors.add(:base, _('Package type must be RubyGems'))
+ end
+ end
+ end
+ end
+end