diff options
author | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-27 17:50:30 +0100 |
---|---|---|
committer | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-27 17:50:30 +0100 |
commit | 7499f65014257989510da50505fa7c0f5a4fae88 (patch) | |
tree | b8c9355b73ec48c12bfa9d6416fa91ba4c4444e6 /lib/api/helpers.rb | |
parent | 43d75960303be538fb79804ca6e2a90241aee0df (diff) | |
download | gitlab-ce-7499f65014257989510da50505fa7c0f5a4fae88.tar.gz |
API: extracted helper method to validate required parameters, code clean up
Added a helper method to check if required parameters are given in an API call. Can be used
to return a `400 Bad Request` return code if a required attribute is missing.
Code clean up and fixed tests.
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index becb3bce5b0..f12fb5fdbd0 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -41,6 +41,17 @@ module Gitlab abilities.allowed?(object, action, subject) end + # Checks the occurrences of required attributes, each attribute must be present in the params hash + # or a Bad Request error is invoked. + # + # Parameters: + # keys (required) - A hash consisting of keys that must be present + def required_attributes!(keys) + keys.each do |key| + bad_request!(key) unless params[key].present? + end + end + def attributes_for_keys(keys) attrs = {} keys.each do |key| |