diff options
Diffstat (limited to 'app/models/packages/nuget/metadatum.rb')
-rw-r--r-- | app/models/packages/nuget/metadatum.rb | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/app/models/packages/nuget/metadatum.rb b/app/models/packages/nuget/metadatum.rb index 1db8c0eddbf..fae7728cccb 100644 --- a/app/models/packages/nuget/metadatum.rb +++ b/app/models/packages/nuget/metadatum.rb @@ -1,24 +1,23 @@ # frozen_string_literal: true class Packages::Nuget::Metadatum < ApplicationRecord + MAX_AUTHORS_LENGTH = 255 + MAX_DESCRIPTION_LENGTH = 4000 + MAX_URL_LENGTH = 255 + belongs_to :package, -> { where(package_type: :nuget) }, inverse_of: :nuget_metadatum validates :package, presence: true - validates :license_url, public_url: { allow_blank: true } - validates :project_url, public_url: { allow_blank: true } - validates :icon_url, public_url: { allow_blank: true } + validates :license_url, public_url: { allow_blank: true }, length: { maximum: MAX_URL_LENGTH } + validates :project_url, public_url: { allow_blank: true }, length: { maximum: MAX_URL_LENGTH } + validates :icon_url, public_url: { allow_blank: true }, length: { maximum: MAX_URL_LENGTH } + validates :authors, presence: true, length: { maximum: MAX_AUTHORS_LENGTH } + validates :description, presence: true, length: { maximum: MAX_DESCRIPTION_LENGTH } - validate :ensure_at_least_one_field_supplied validate :ensure_nuget_package_type private - def ensure_at_least_one_field_supplied - return if license_url? || project_url? || icon_url? - - errors.add(:base, _('Nuget metadatum must have at least license_url, project_url or icon_url set')) - end - def ensure_nuget_package_type return if package&.nuget? |