diff options
author | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2022-08-30 15:09:23 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2022-08-30 15:09:23 +0000 |
commit | 33d3043f0f3b825f98c7ff2c794208a79bcafdb3 (patch) | |
tree | 2fc8f97f12f9e3049ed3daad5700ae438b7eac9b /app/models/snippet.rb | |
parent | 99e4792893862d913d0bc9168da7d85775445590 (diff) | |
parent | f1452cd5cf4c3e2dd6697bc25636b49c1aadecd1 (diff) | |
download | gitlab-ce-15-1-stable.tar.gz |
Merge remote-tracking branch 'dev/15-1-stable' into 15-1-stable15-1-stable
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 2001577c88b..d7eb1860831 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -21,6 +21,8 @@ class Snippet < ApplicationRecord MAX_FILE_COUNT = 10 + DESCRIPTION_LENGTH_MAX = 1.megabyte + cache_markdown_field :title, pipeline: :single_line cache_markdown_field :description cache_markdown_field :content @@ -56,19 +58,10 @@ class Snippet < ApplicationRecord validates :title, presence: true, length: { maximum: 255 } validates :file_name, length: { maximum: 255 } + validates :description, bytesize: { maximum: -> { DESCRIPTION_LENGTH_MAX } }, if: :description_changed? validates :content, presence: true - validates :content, - length: { - maximum: ->(_) { Gitlab::CurrentSettings.snippet_size_limit }, - message: -> (_, data) do - current_value = ActiveSupport::NumberHelper.number_to_human_size(data[:value].size) - max_size = ActiveSupport::NumberHelper.number_to_human_size(Gitlab::CurrentSettings.snippet_size_limit) - - _("is too long (%{current_value}). The maximum size is %{max_size}.") % { current_value: current_value, max_size: max_size } - end - }, - if: :content_changed? + validates :content, bytesize: { maximum: -> { Gitlab::CurrentSettings.snippet_size_limit } }, if: :content_changed? after_create :create_statistics |