From 5f807ccfd0d01dbec2169e4062b8a343cb3ee1bd Mon Sep 17 00:00:00 2001 From: Alberto Bellotti Date: Wed, 17 May 2017 11:23:03 -0400 Subject: [PATCH] Merge pull request #15070 from jntullo/enhancement/csp_subcollection configuration_script_sources subcollection (cherry picked from commit 632c2d0c272e13fcd3f91d8334f4e402dcab6f32) https://bugzilla.redhat.com/show_bug.cgi?id=1459986 --- ...configuration_script_sources_controller.rb | 2 + .../configuration_script_payloads.rb | 9 ++++ config/api.yml | 7 +++ .../api/configuration_script_sources_spec.rb | 51 +++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 app/controllers/api/subcollections/configuration_script_payloads.rb diff --git a/app/controllers/api/configuration_script_sources_controller.rb b/app/controllers/api/configuration_script_sources_controller.rb index d9e8c2caec8..1a0e480a74b 100644 --- a/app/controllers/api/configuration_script_sources_controller.rb +++ b/app/controllers/api/configuration_script_sources_controller.rb @@ -1,5 +1,7 @@ module Api class ConfigurationScriptSourcesController < BaseController + include Subcollections::ConfigurationScriptPayloads + def edit_resource(type, id, data) config_script_src = resource_search(id, type, collection_class(:configuration_script_sources)) raise "Update not supported for #{config_script_src_ident(config_script_src)}" unless config_script_src.respond_to?(:update_in_provider_queue) diff --git a/app/controllers/api/subcollections/configuration_script_payloads.rb b/app/controllers/api/subcollections/configuration_script_payloads.rb new file mode 100644 index 00000000000..4fc2a524e04 --- /dev/null +++ b/app/controllers/api/subcollections/configuration_script_payloads.rb @@ -0,0 +1,9 @@ +module Api + module Subcollections + module ConfigurationScriptPayloads + def configuration_script_payloads_query_resource(object) + object.configuration_script_payloads + end + end + end +end diff --git a/config/api.yml b/config/api.yml index f1cddaaa402..4f404d05562 100644 --- a/config/api.yml +++ b/config/api.yml @@ -612,6 +612,7 @@ :description: Configuration Script Payloads :options: - :collection + - :subcollection :verbs: *g :klass: ConfigurationScriptPayload :subcollections: @@ -624,6 +625,10 @@ :get: - :name: read :identifier: embedded_configuration_script_payload_view + :subcollection_actions: + :get: + - :name: read + :identifier: embedded_configuration_script_payload_view :authentications_subcollection_actions: :get: - :name: read @@ -637,6 +642,8 @@ - :collection :verbs: *gpppd :klass: ConfigurationScriptSource + :subcollections: + - :configuration_script_payloads :collection_actions: :get: - :name: read diff --git a/spec/requests/api/configuration_script_sources_spec.rb b/spec/requests/api/configuration_script_sources_spec.rb index 6f1e2b53158..71ffa2a2181 100644 --- a/spec/requests/api/configuration_script_sources_spec.rb +++ b/spec/requests/api/configuration_script_sources_spec.rb @@ -381,4 +381,55 @@ expect(response).to have_http_status(:forbidden) end end + + describe 'GET /api/configuration_script_sources/:id/configuration_script_payloads' do + let(:payload) { FactoryGirl.create(:configuration_script_payload) } + let(:url) { "#{configuration_script_sources_url(config_script_src.id)}/configuration_script_payloads" } + + before do + config_script_src.configuration_script_payloads << payload + end + + it 'forbids configuration_script_payload retrievel without an appropriate role' do + api_basic_authorize + + run_get(url) + + expect(response).to have_http_status(:forbidden) + end + + it 'lists all configuration_script_payloads belonging to a configuration_script_source' do + api_basic_authorize subcollection_action_identifier(:configuration_script_sources, :configuration_script_payloads, :read, :get) + + run_get(url) + + expected = { + 'resources' => [{'href' => a_string_including("#{url}/#{payload.id}")}] + } + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include(expected) + end + + it 'can filter on region_number' do + api_basic_authorize subcollection_action_identifier(:configuration_script_sources, :configuration_script_payloads, :read, :get) + + run_get url, :filter => ["region_number=#{payload.region_number}"] + + expected = { + 'subcount' => 1, + 'resources' => [{'href' => a_string_including("#{url}/#{payload.id}")}] + } + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include(expected) + + run_get url, :filter => ["region_number=foo"] + + expected = { + 'subcount' => 0, + 'resources' => [] + } + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include(expected) + end + end end