diff --git a/app/controllers/api/base_controller/renderer.rb b/app/controllers/api/base_controller/renderer.rb index 7f3f958b99..c01bba49a9 100644 --- a/app/controllers/api/base_controller/renderer.rb +++ b/app/controllers/api/base_controller/renderer.rb @@ -441,13 +441,21 @@ def gen_action_spec_for_resources(cspec, is_subcollection, href, resource) next unless render_actions_for_method(cspec[:verbs], method) typed_action_definitions = action_definitions || fetch_typed_subcollection_actions(method, is_subcollection) typed_action_definitions.each.collect do |action| - if !action[:disabled] && api_user_role_allows?(action[:identifier]) && action_validated?(resource, action) - {"name" => action[:name], "method" => method, "href" => href} - end + next unless !action[:disabled] && api_user_role_allows?(action[:identifier]) && action_validated?(resource, action) + build_resource_actions(action, method, href, cspec[:verbs]) end end.flatten.compact end + def build_resource_actions(action, method, href, verbs) + actions = [{"name" => action[:name], "method" => method, "href" => href}] + if action[:name] == "edit" + actions << { 'name' => 'edit', 'method' => :patch, 'href' => href } if verbs.include?(:patch) + actions << { 'name' => 'edit', 'method' => :put, 'href' => href } if verbs.include?(:put) + end + actions + end + def render_actions_for_method(methods, method) method != :get && methods.include?(method) end diff --git a/spec/requests/authentications_spec.rb b/spec/requests/authentications_spec.rb index d1655411bc..fb11dd2fe5 100644 --- a/spec/requests/authentications_spec.rb +++ b/spec/requests/authentications_spec.rb @@ -31,12 +31,19 @@ describe 'GET /api/authentications/:id' do it 'will show an authentication configuration script base' do - api_basic_authorize action_identifier(:authentications, :read, :resource_actions, :get) + api_basic_authorize action_identifier(:authentications, :read, :resource_actions, :get), + action_identifier(:authentications, :edit) + href = api_authentication_url(nil, auth) - get(api_authentication_url(nil, auth)) + get(href) expected = { - 'href' => api_authentication_url(nil, auth) + 'href' => href, + 'actions' => [ + { 'name' => 'edit', 'method' => 'post', 'href' => href }, + { 'name' => 'edit', 'method' => 'patch', 'href' => href }, + { 'name' => 'edit', 'method' => 'put', 'href' => href } + ] } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) diff --git a/spec/requests/custom_actions_spec.rb b/spec/requests/custom_actions_spec.rb index fe962b9293..c11283e2ce 100644 --- a/spec/requests/custom_actions_spec.rb +++ b/spec/requests/custom_actions_spec.rb @@ -75,7 +75,7 @@ def expect_result_to_have_custom_actions_hash get api_service_url(nil, svc1) expect_result_to_have_keys(%w(id href actions)) - expect(response.parsed_body["actions"].collect { |a| a["name"] }).to match_array(%w(edit add_resource remove_resource remove_all_resources add_provider_vms)) + expect(response.parsed_body["actions"].select { |a| a["method"] == "post" }.pluck("name")).to match_array(%w(edit add_resource remove_resource remove_all_resources add_provider_vms)) end end @@ -91,7 +91,7 @@ def expect_result_to_have_custom_actions_hash get api_service_url(nil, svc1) expect_result_to_have_keys(%w(id href actions)) - expect(response.parsed_body["actions"].collect { |a| a["name"] }).to match_array(%w(edit button1 button2 button3 add_resource remove_resource remove_all_resources add_provider_vms)) + expect(response.parsed_body["actions"].select { |a| a["method"] == "post" }.pluck("name")).to match_array(%w(edit button1 button2 button3 add_resource remove_resource remove_all_resources add_provider_vms)) end it "supports the custom_actions attribute" do @@ -128,7 +128,7 @@ def expect_result_to_have_custom_actions_hash expect_result_to_have_keys(%w(id href actions)) action_specs = response.parsed_body["actions"] - expect(action_specs.size).to eq(1) + expect(action_specs.size).to eq(3) expect(action_specs.first["name"]).to eq("edit") end