diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/models/packages | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/event.rb | 5 | ||||
-rw-r--r-- | app/models/packages/package.rb | 26 | ||||
-rw-r--r-- | app/models/packages/package_file.rb | 11 |
3 files changed, 29 insertions, 13 deletions
diff --git a/app/models/packages/event.rb b/app/models/packages/event.rb index 959c94931ec..13da82d16d3 100644 --- a/app/models/packages/event.rb +++ b/app/models/packages/event.rb @@ -25,7 +25,7 @@ class Packages::Event < ApplicationRecord enum originator_type: { user: 0, deploy_token: 1, guest: 2 } def self.allowed_event_name(event_scope, event_type, originator) - return unless event_allowed?(event_scope, event_type, originator) + return unless event_allowed?(event_type) # remove `package` from the event name to avoid issues with HLLRedisCounter class parsing "i_package_#{event_scope}_#{originator}_#{event_type.gsub(/_packages?/, "")}" @@ -33,8 +33,7 @@ class Packages::Event < ApplicationRecord # Remove some of the events, for now, so we don't hammer Redis too hard. # See: https://gitlab.com/gitlab-org/gitlab/-/issues/280770 - def self.event_allowed?(event_scope, event_type, originator) - return false if originator.to_sym == :guest + def self.event_allowed?(event_type) return true if UNIQUE_EVENTS_ALLOWED.include?(event_type.to_sym) false diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index 60aab0a7222..10c98f03804 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -28,7 +28,7 @@ class Packages::Package < ApplicationRecord validates :project, presence: true validates :name, presence: true - validates :name, format: { with: Gitlab::Regex.package_name_regex }, unless: -> { conan? || generic? } + 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? @@ -40,6 +40,8 @@ class Packages::Package < ApplicationRecord 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.nuget_package_name_regex }, if: :nuget? + validates :name, format: { with: Gitlab::Regex.debian_package_name_regex }, if: :debian_package? + validates :name, inclusion: { in: %w[incoming] }, if: :debian_incoming? validates :version, format: { with: Gitlab::Regex.nuget_version_regex }, if: :nuget? validates :version, format: { with: Gitlab::Regex.conan_recipe_component_regex }, if: :conan? validates :version, format: { with: Gitlab::Regex.maven_version_regex }, if: -> { version? && maven? } @@ -51,6 +53,11 @@ class Packages::Package < ApplicationRecord presence: true, format: { with: Gitlab::Regex.generic_package_version_regex }, if: :generic? + validates :version, + presence: true, + format: { with: Gitlab::Regex.debian_version_regex }, + 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 } @@ -184,6 +191,14 @@ class Packages::Package < ApplicationRecord tags.pluck(:name) end + def debian_incoming? + debian? && version.nil? + end + + def debian_package? + debian? && !version.nil? + end + private def composer_tag_version? @@ -228,4 +243,13 @@ class Packages::Package < ApplicationRecord errors.add(:base, _('Package already exists')) end end + + def forbidden_debian_changes + return unless persisted? + + # Debian incoming + if version_was.nil? || version.nil? + errors.add(:version, _('cannot be changed')) if version_changed? + end + end end diff --git a/app/models/packages/package_file.rb b/app/models/packages/package_file.rb index d68f75140ac..e8d1dd1e8c4 100644 --- a/app/models/packages/package_file.rb +++ b/app/models/packages/package_file.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class Packages::PackageFile < ApplicationRecord include UpdateProjectStatistics + include FileStoreMounter delegate :project, :project_id, to: :package delegate :conan_file_type, to: :conan_file_metadatum @@ -35,20 +36,12 @@ class Packages::PackageFile < ApplicationRecord .where(packages_conan_file_metadata: { conan_package_reference: conan_package_reference }) end - mount_uploader :file, Packages::PackageFileUploader - - after_save :update_file_metadata, if: :saved_change_to_file? + mount_file_store_uploader Packages::PackageFileUploader update_project_statistics project_statistics_name: :packages_size before_save :update_size_from_file - def update_file_metadata - # The file.object_store is set during `uploader.store!` - # which happens after object is inserted/updated - self.update_column(:file_store, file.object_store) - end - def download_path Gitlab::Routing.url_helpers.download_project_package_file_path(project, self) end |