diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/validators | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/json_schemas/application_setting_kroki_formats.json | 10 | ||||
-rw-r--r-- | app/validators/json_schemas/git_trailers.json | 9 | ||||
-rw-r--r-- | app/validators/nested_attributes_duplicates_validator.rb (renamed from app/validators/variable_duplicates_validator.rb) | 22 |
3 files changed, 33 insertions, 8 deletions
diff --git a/app/validators/json_schemas/application_setting_kroki_formats.json b/app/validators/json_schemas/application_setting_kroki_formats.json new file mode 100644 index 00000000000..460dc74069f --- /dev/null +++ b/app/validators/json_schemas/application_setting_kroki_formats.json @@ -0,0 +1,10 @@ +{ + "description": "Kroki formats", + "type": "object", + "properties": { + "bpmn": { "type": "boolean" }, + "excalidraw": { "type": "boolean" }, + "blockdiag": { "type": "boolean" } + }, + "additionalProperties": false +} diff --git a/app/validators/json_schemas/git_trailers.json b/app/validators/json_schemas/git_trailers.json new file mode 100644 index 00000000000..18ac97226a7 --- /dev/null +++ b/app/validators/json_schemas/git_trailers.json @@ -0,0 +1,9 @@ +{ + "description": "Git trailer key/value pairs", + "type": "object", + "patternProperties": { + ".*": { + "type": "string" + } + } +} diff --git a/app/validators/variable_duplicates_validator.rb b/app/validators/nested_attributes_duplicates_validator.rb index d36a56e81b9..b60350a6311 100644 --- a/app/validators/variable_duplicates_validator.rb +++ b/app/validators/nested_attributes_duplicates_validator.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -# VariableDuplicatesValidator +# NestedAttributesDuplicates # # This validator is designed for especially the following condition # - Use `accepts_nested_attributes_for :xxx` in a parent model # - Use `validates :xxx, uniqueness: { scope: :xxx_id }` in a child model -class VariableDuplicatesValidator < ActiveModel::EachValidator +class NestedAttributesDuplicatesValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - return if record.errors.include?(:"#{attribute}.key") + return if child_attributes.any? { |child_attribute| record.errors.include?(:"#{attribute}.#{child_attribute}") } if options[:scope] scoped = value.group_by do |variable| @@ -23,12 +23,18 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator # rubocop: disable CodeReuse/ActiveRecord def validate_duplicates(record, attribute, values) - duplicates = values.reject(&:marked_for_destruction?).group_by(&:key).select { |_, v| v.many? }.map(&:first) - if duplicates.any? - error_message = +"have duplicate values (#{duplicates.join(", ")})" - error_message << " for #{values.first.send(options[:scope])} scope" if options[:scope] # rubocop:disable GitlabSecurity/PublicSend - record.errors.add(attribute, error_message) + child_attributes.each do |child_attribute| + duplicates = values.reject(&:marked_for_destruction?).group_by(&:"#{child_attribute}").select { |_, v| v.many? }.map(&:first) + if duplicates.any? + error_message = +"have duplicate values (#{duplicates.join(", ")})" + error_message << " for #{values.first.send(options[:scope])} scope" if options[:scope] # rubocop:disable GitlabSecurity/PublicSend + record.errors.add(attribute, error_message) + end end end # rubocop: enable CodeReuse/ActiveRecord + + def child_attributes + options[:child_attributes] || %i[key] + end end |