summaryrefslogtreecommitdiff
path: root/lib/api/validations
diff options
context:
space:
mode:
authorAlexandru Croitor <acroitor@gitlab.com>2019-04-24 16:08:14 +0300
committerAlexandru Croitor <acroitor@gitlab.com>2019-05-15 10:15:17 +0300
commitf117c032ac6c414e6c1dfeab98184363c1f61608 (patch)
treed3c5beb5363112dccbd2fa0cbcff573121eafda3 /lib/api/validations
parenta4fbf39eca4518598e893f6f1b81b8b69927c6f9 (diff)
downloadgitlab-ce-f117c032ac6c414e6c1dfeab98184363c1f61608.tar.gz
Add params validations and remove extra params support
Remove label_name and milestone_title params support Add mutually_exclusive validation for author_id and author_username Add mutually_exclusive validation for assignee_id and assignee_username Add validation to allow single value for asignee_username on CE Add separate issue_stats_params helper for statistics params and reuse in issues_params.
Diffstat (limited to 'lib/api/validations')
-rw-r--r--lib/api/validations/check_assignees_count.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/api/validations/check_assignees_count.rb b/lib/api/validations/check_assignees_count.rb
new file mode 100644
index 00000000000..e19c88e97b1
--- /dev/null
+++ b/lib/api/validations/check_assignees_count.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+module API
+ module Validations
+ class CheckAssigneesCount < Grape::Validations::Base
+ def self.coerce
+ lambda do |value|
+ case value
+ when String
+ [value]
+ when Array
+ value
+ when CheckAssigneesCount
+ value
+ else
+ []
+ end
+ end
+ end
+
+ def validate_param!(attr_name, params)
+ unless param_allowed?(attr_name, params)
+ raise Grape::Exceptions::Validation,
+ params: [@scope.full_name(attr_name)],
+ message: "allows one value, but found #{params[attr_name].size}: #{params[attr_name].join(", ")}"
+ end
+ end
+
+ private
+
+ def param_allowed?(attr_name, params)
+ params[attr_name].size <= 1
+ end
+ end
+ end
+end