diff --git a/app/models/service_template.rb b/app/models/service_template.rb index 56ddcbf45aa4..91a56b56fbe5 100644 --- a/app/models/service_template.rb +++ b/app/models/service_template.rb @@ -38,6 +38,8 @@ class ServiceTemplate < ApplicationRecord include NewWithTypeStiMixin include TenancyMixin include ArchivedMixin + include ReservedMixin + reserve_attribute :internal, :boolean include_concern 'Filter' belongs_to :tenant @@ -74,6 +76,7 @@ class ServiceTemplate < ApplicationRecord scope :without_service_template_catalog_id, -> { where(:service_template_catalog_id => nil) } scope :with_existent_service_template_catalog_id, -> { where.not(:service_template_catalog_id => nil) } scope :displayed, -> { where(:display => true) } + scope :public_service_templates, -> { where.not(:id => ServiceTemplate.includes(:reserved_rec).joins(:reserved_rec).select { |s| s.internal == true }.collect(&:id)) } def self.catalog_item_types ci_types = Set.new(Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types)) diff --git a/app/models/service_template_transformation_plan.rb b/app/models/service_template_transformation_plan.rb index 84505f6aef6c..fa6c3dc2bfc6 100644 --- a/app/models/service_template_transformation_plan.rb +++ b/app/models/service_template_transformation_plan.rb @@ -7,6 +7,8 @@ def request_type "transformation_plan" end + default_value_for :internal, true + def transformation_mapping service_resources.find_by(:resource_type => 'TransformationMapping').resource end diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index 71ed306b4261..4357e1454e4f 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -37,6 +37,17 @@ } end + describe '.public_service_templates' do + it 'display public service templates' do + st1 = FactoryGirl.create(:service_template_transformation_plan) + st2 = FactoryGirl.create(:service_template) + + expect(st1.internal).to be_truthy + expect(st2.internal).to be_falsey + expect(ServiceTemplate.public_service_templates).to match_array([st2]) + end + end + describe '.create_catalog_item' do it 'creates and returns a transformation plan' do service_template = described_class.create_catalog_item(catalog_item_options)