Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r--app/models/snippet.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 51ab94e6f4a..b802ea2fd59 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -46,6 +46,18 @@ class Snippet < ApplicationRecord
length: { maximum: 255 }
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 :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values }
# Scopes