summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-05-11 09:52:58 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-05-11 09:52:58 +0530
commit2e9742997ddbfaeff350eb5334b7f641a779550c (patch)
tree4dacf94eb6b6f67fc5c8b89b117f0babe1c2b8a4 /lib/api/helpers.rb
parent2768e99ac386598480a7ac5490deee644125dfa1 (diff)
parentf7d2297c86eb84c2e2fbfa6b3e007da3c7adb5ae (diff)
downloadgitlab-ce-2e9742997ddbfaeff350eb5334b7f641a779550c.tar.gz
Merge remote-tracking branch 'origin/master' into 2979-personal-access-tokens
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index fb30ef3e252..de9a1b0eb94 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -195,6 +195,22 @@ module API
Gitlab::Access.options_with_owner.values.include? level.to_i
end
+ # Checks the occurrences of datetime attributes, each attribute if present in the params hash must be in ISO 8601
+ # format (YYYY-MM-DDTHH:MM:SSZ) or a Bad Request error is invoked.
+ #
+ # Parameters:
+ # keys (required) - An array consisting of elements that must be parseable as dates from the params hash
+ def datetime_attributes!(*keys)
+ keys.each do |key|
+ begin
+ params[key] = Time.xmlschema(params[key]) if params[key].present?
+ rescue ArgumentError
+ message = "\"" + key.to_s + "\" must be a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ"
+ render_api_error!(message, 400)
+ end
+ end
+ end
+
def issuable_order_by
if params["order_by"] == 'updated_at'
'updated_at'