diff options
author | Igor <idrozdov@gitlab.com> | 2019-03-07 07:06:54 +0000 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2019-03-07 07:06:54 +0000 |
commit | 572e3f2254fb9582d304cc4023b83b87dbf0e389 (patch) | |
tree | 1d4740d4f580c9b3cac3a37838073d2361951834 /lib/api/helpers/custom_validators.rb | |
parent | 860a4de34634548d26a0b67b480c3235a181c3d9 (diff) | |
download | gitlab-ce-572e3f2254fb9582d304cc4023b83b87dbf0e389.tar.gz |
Provide EE backports for filtering by approver feature
Adds custom validator for ArrayNoneAny param
Extracts some logic in js into separate files
Diffstat (limited to 'lib/api/helpers/custom_validators.rb')
-rw-r--r-- | lib/api/helpers/custom_validators.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb index 1058f4e8a5e..c86eae6f2da 100644 --- a/lib/api/helpers/custom_validators.rb +++ b/lib/api/helpers/custom_validators.rb @@ -22,9 +22,22 @@ module API message: "should be an integer, 'None' or 'Any'" end end + + class ArrayNoneAny < Grape::Validations::Base + def validate_param!(attr_name, params) + value = params[attr_name] + + return if value.is_a?(Array) || + [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase) + + raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], + message: "should be an array, 'None' or 'Any'" + end + end end end end Grape::Validations.register_validator(:absence, ::API::Helpers::CustomValidators::Absence) Grape::Validations.register_validator(:integer_none_any, ::API::Helpers::CustomValidators::IntegerNoneAny) +Grape::Validations.register_validator(:array_none_any, ::API::Helpers::CustomValidators::ArrayNoneAny) |