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.
This commit is contained in:
parent
43d7596030
commit
7499f65014
10 changed files with 35 additions and 42 deletions
|
@ -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|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue