From 07d0313e0f16f6aa0c2006c5d04095b74cc5d744 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Mon, 26 Aug 2019 23:56:37 +0200 Subject: [PATCH] Use SupportsFeatureMixin to validate_order --- app/controllers/api/mixins/service_templates.rb | 12 +++--------- spec/requests/service_templates_spec.rb | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/mixins/service_templates.rb b/app/controllers/api/mixins/service_templates.rb index 62717e6c9f..d105586960 100644 --- a/app/controllers/api/mixins/service_templates.rb +++ b/app/controllers/api/mixins/service_templates.rb @@ -3,10 +3,7 @@ module Mixins module ServiceTemplates def order_service_template(id, data, scheduled_time = nil) service_template = resource_search(id, :service_templates, ServiceTemplate) - errors = validate_order(service_template, true) - if errors.present? - raise BadRequestError, "#{service_template_ident(service_template)} cannot be ordered - #{errors.join(", ")}" - end + raise BadRequestError, "#{service_template_ident(service_template)} cannot be ordered - #{service_template.unsupported_reason(:order)}" unless service_template.supports_order? request_result = service_template.order(User.current_user, (data || {}), order_request_options, scheduled_time) errors = request_result[:errors] @@ -18,11 +15,8 @@ def order_service_template(id, data, scheduled_time = nil) private - def validate_order(service_template, with_errors = false) - errors = [] - errors << 'Service ordering via API is not allowed' unless api_request_allowed? - errors += service_template.validate_order(true) - with_errors ? errors : errors.blank? + def validate_order(service_template) + service_template.supports_order? end alias orderable? validate_order diff --git a/spec/requests/service_templates_spec.rb b/spec/requests/service_templates_spec.rb index 7d4a73e47b..ea4d1fdc31 100644 --- a/spec/requests/service_templates_spec.rb +++ b/spec/requests/service_templates_spec.rb @@ -607,7 +607,7 @@ expected = { "error" => a_hash_including( "kind" => "bad_request", - "message" => /cannot be ordered - Service template does not belong to a service catalog, Service template is not configured to be displayed/ + "message" => /cannot be ordered - Service template is not configured to be displayed/ ) } expect(response).to have_http_status(:bad_request)