summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 20:21:02 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 20:21:02 +0300
commit71da2e0b56a89fc87f2da3685bdebb333690593a (patch)
treebe6418658f118746ab158be162622fe8cb5f0b0e /lib/api/helpers.rb
parent011a905a821e2ff0cd2d9885ef93764018eb8346 (diff)
parent44501820152083d231459223fe09b9d9641b7c1e (diff)
downloadgitlab-ce-71da2e0b56a89fc87f2da3685bdebb333690593a.tar.gz
Merge remote-tracking branch 'origin/master' into docker-registry
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 5bbf721321d..40c967453fb 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -183,6 +183,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'