Skip to content

Commit

Permalink
Merge pull request #495 from jvlcek/bz_1599259_CORS
Browse files Browse the repository at this point in the history
Add subcollection options support for CORS prefilghted requests

(cherry picked from commit 3502e51)

https://bugzilla.redhat.com/show_bug.cgi?id=1599259
  • Loading branch information
abellotti authored and simaishi committed Oct 18, 2018
1 parent 50eef54 commit 9b4e420
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ def destroy
end

def options
render_options(@req.collection)
if params.key?(:subcollection)
render :json => ""
else
render_options(@req.collection)
end
end

def settings
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
end

Array(collection.subcollections).each do |subcollection_name|
# OPTIONS action for each subcollection
match "/:c_id/#{subcollection_name}", :controller => collection_name, :action => :options, :via => :options, :as => nil, :subcollection => true

if subcollection_name == :settings
match(
"/:c_id/settings",
Expand Down
6 changes: 6 additions & 0 deletions spec/requests/tenant_quotas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
expect(response).to have_http_status(:no_content)
end

it "supports OPTIONS requests on a subcollection without authorization" do
options api_tenant_quotas_url(nil, tenant)
expect(response).to have_http_status(:ok)
expect(response.body).to be_empty
end

it "can delete multiple quotas from a tenant with POST" do
api_basic_authorize action_identifier(:quotas, :delete, :subcollection_actions, :post)

Expand Down

0 comments on commit 9b4e420

Please sign in to comment.