summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-08-30 16:49:22 +0100
committerPhil Hughes <me@iamphill.com>2017-08-30 16:49:22 +0100
commit4d2d744ae9a2d4c3bb0f00805c27704b79e00d72 (patch)
tree839b1c3ab4c09c80f7d643fe69dae8a83c4e4eb4 /lib/api/helpers.rb
parent25a3b7fab905d09f6f064108f457a4e20c8915ff (diff)
parentf7c8434c7100c3c87eb2a75cd5a128e520d8c110 (diff)
downloadgitlab-ce-enable-new-navigaton-by-default.tar.gz
Merge branch 'master' into enable-new-navigaton-by-defaultenable-new-navigaton-by-default
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index b56fd2388b3..3d377fdb9eb 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -11,6 +11,27 @@ module API
declared(params, options).to_h.symbolize_keys
end
+ def check_unmodified_since!(last_modified)
+ if_unmodified_since = Time.parse(headers['If-Unmodified-Since']) rescue nil
+
+ if if_unmodified_since && last_modified && last_modified > if_unmodified_since
+ render_api_error!('412 Precondition Failed', 412)
+ end
+ end
+
+ def destroy_conditionally!(resource, last_updated: nil)
+ last_updated ||= resource.updated_at
+
+ check_unmodified_since!(last_updated)
+
+ status 204
+ if block_given?
+ yield resource
+ else
+ resource.destroy
+ end
+ end
+
def current_user
return @current_user if defined?(@current_user)