summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-10-26 10:42:41 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-10-26 10:42:41 +0000
commit8325a1fc9f0b2c9cea9073d4377f2b3b35771e8b (patch)
tree9ea5433076dd1576d867babbe33e7f648a087b58 /lib/api
parentc10c553e1db344f0cd65454373c63af0a5cb58f0 (diff)
parente0f0c29b0cfe3c0c97191eeb96eae1299f3983d1 (diff)
downloadgitlab-ce-8325a1fc9f0b2c9cea9073d4377f2b3b35771e8b.tar.gz
Merge branch '52384-api-filter-assignee-none-any' into 'master'
Resolve "Filter by `None`/`Any` for assignee_id in issues/mrs API" Closes #52384 See merge request gitlab-org/gitlab-ce!22598
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/helpers/custom_validators.rb13
-rw-r--r--lib/api/issues.rb3
-rw-r--r--lib/api/merge_requests.rb3
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb
index 23b1cd1ad45..1058f4e8a5e 100644
--- a/lib/api/helpers/custom_validators.rb
+++ b/lib/api/helpers/custom_validators.rb
@@ -10,8 +10,21 @@ module API
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:absence)
end
end
+
+ class IntegerNoneAny < Grape::Validations::Base
+ def validate_param!(attr_name, params)
+ value = params[attr_name]
+
+ return if value.is_a?(Integer) ||
+ [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 integer, '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)
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 25d78053c88..405fc30a2ed 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -40,7 +40,8 @@ module API
optional :updated_after, type: DateTime, desc: 'Return issues updated after the specified time'
optional :updated_before, type: DateTime, desc: 'Return issues updated before the specified time'
optional :author_id, type: Integer, desc: 'Return issues which are authored by the user with the given ID'
- optional :assignee_id, type: Integer, desc: 'Return issues which are assigned to the user with the given ID'
+ optional :assignee_id, types: [Integer, String], integer_none_any: true,
+ desc: 'Return issues which are assigned to the user with the given ID'
optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all],
desc: 'Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`'
optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji'
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 440d94ae186..a617efaaa4c 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -89,7 +89,8 @@ module API
optional :updated_before, type: DateTime, desc: 'Return merge requests updated before the specified time'
optional :view, type: String, values: %w[simple], desc: 'If simple, returns the `iid`, URL, title, description, and basic state of merge request'
optional :author_id, type: Integer, desc: 'Return merge requests which are authored by the user with the given ID'
- optional :assignee_id, type: Integer, desc: 'Return merge requests which are assigned to the user with the given ID'
+ optional :assignee_id, types: [Integer, String], integer_none_any: true,
+ desc: 'Return merge requests which are assigned to the user with the given ID'
optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all],
desc: 'Return merge requests for the given scope: `created_by_me`, `assigned_to_me` or `all`'
optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji'