diff --git a/app/controllers/api/service_offerings_controller.rb b/app/controllers/api/service_offerings_controller.rb new file mode 100644 index 0000000000..e4463e8616 --- /dev/null +++ b/app/controllers/api/service_offerings_controller.rb @@ -0,0 +1,7 @@ +module Api + class ServiceOfferingsController < BaseController + def service_parameters_sets_query_resource(object) + object.service_parameters_sets + end + end +end diff --git a/app/controllers/api/service_parameters_sets_controller.rb b/app/controllers/api/service_parameters_sets_controller.rb new file mode 100644 index 0000000000..0d5c9a4d29 --- /dev/null +++ b/app/controllers/api/service_parameters_sets_controller.rb @@ -0,0 +1,4 @@ +module Api + class ServiceParametersSetsController < BaseController + end +end diff --git a/config/api.yml b/config/api.yml index 36f2112fea..a7a502b920 100644 --- a/config/api.yml +++ b/config/api.yml @@ -2769,6 +2769,23 @@ :delete: - :name: delete :identifier: dialog_delete + :service_offerings: + :description: Service Offerings + :identifier: service_offerings + :options: + - :collection + :verbs: *g + :klass: ServiceOffering + :subcollections: + - :service_parameters_sets + :collection_actions: + :get: + - :name: read + :identifier: service_offerings_view + :resource_actions: + :get: + - :name: read + :identifier: service_offerings_view :service_orders: :description: Service Orders :identifier: svc_catalog_provision @@ -2811,6 +2828,21 @@ :delete: - :name: delete :identifier: svc_catalog_provision + :service_parameters_sets: + :description: Service Parameters Sets + :identifier: service_parameters_sets + :options: + - :collection + :verbs: *g + :klass: ServiceParametersSet + :collection_actions: + :get: + - :name: read + :identifier: service_parameters_sets_view + :resource_actions: + :get: + - :name: read + :identifier: service_parameters_sets_view :service_requests: :description: Service Requests :identifier: miq_request diff --git a/spec/requests/service_offerings_spec.rb b/spec/requests/service_offerings_spec.rb new file mode 100644 index 0000000000..82a6c95994 --- /dev/null +++ b/spec/requests/service_offerings_spec.rb @@ -0,0 +1,56 @@ +describe "ServiceOfferings API" do + it "forbids access without an appropriate role" do + api_basic_authorize + + get(api_service_offerings_url) + + expect(response).to have_http_status(:forbidden) + end + + it "allows access with an appropriate role" do + api_basic_authorize action_identifier(:service_offerings, :read, :collection_actions, :get) + + instance = ServiceOffering.create! + + get(api_service_offerings_url) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body["resources"]).to include("href" => api_service_offering_url(nil, instance)) + end + + it "forbids access to an instance without an appropriate role" do + api_basic_authorize + + instance = ServiceOffering.create! + + get(api_service_offering_url(nil, instance)) + + expect(response).to have_http_status(:forbidden) + end + + it "allows access to an instance with an appropriate role" do + api_basic_authorize action_identifier(:service_offerings, :read, :resource_actions, :get) + + instance = ServiceOffering.create! + + get(api_service_offering_url(nil, instance)) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include( + "href" => api_service_offering_url(nil, instance), + "id" => instance.id.to_s + ) + end + + it "allows access to an instances service_parameters_sets with an appropriate role" do + api_basic_authorize action_identifier(:service_offerings, :read, :resource_actions, :get) + + instance = ServiceOffering.create! + sub_resource = instance.service_parameters_sets.create! + + get(api_service_offering_service_parameters_sets_url(nil, instance)) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body["resources"]).to eq([{"href" => api_service_offering_service_parameters_set_url(nil, instance, sub_resource)}]) + end +end diff --git a/spec/requests/service_parameters_sets_spec.rb b/spec/requests/service_parameters_sets_spec.rb new file mode 100644 index 0000000000..1dbed9ed28 --- /dev/null +++ b/spec/requests/service_parameters_sets_spec.rb @@ -0,0 +1,44 @@ +describe "ServiceParametersSets API" do + it "forbids access without an appropriate role" do + api_basic_authorize + + get(api_service_parameters_sets_url) + + expect(response).to have_http_status(:forbidden) + end + + it "allows access with an appropriate role" do + api_basic_authorize action_identifier(:service_parameters_sets, :read, :collection_actions, :get) + + instance = ServiceParametersSet.create! + + get(api_service_parameters_sets_url) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body["resources"]).to include("href" => api_service_parameters_set_url(nil, instance)) + end + + it "forbids access to an instance without an appropriate role" do + api_basic_authorize + + instance = ServiceParametersSet.create! + + get(api_service_parameters_set_url(nil, instance)) + + expect(response).to have_http_status(:forbidden) + end + + it "allows access to an instance with an appropriate role" do + api_basic_authorize action_identifier(:service_parameters_sets, :read, :resource_actions, :get) + + instance = ServiceParametersSet.create! + + get(api_service_parameters_set_url(nil, instance)) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include( + "href" => api_service_parameters_set_url(nil, instance), + "id" => instance.id.to_s + ) + end +end