Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal column to service template for transformation plan #17748

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class ServiceTemplate < ApplicationRecord
include NewWithTypeStiMixin
include TenancyMixin
include ArchivedMixin
include ReservedMixin
reserve_attribute :internal, :boolean
include_concern 'Filter'

belongs_to :tenant
Expand Down Expand Up @@ -77,6 +79,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 => Reserve.where(:resource_type => "ServiceTemplate").all.collect { |r| r.resource_id if r.reserved[:internal] }.compact) }

def self.catalog_item_types
ci_types = Set.new(Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types))
Expand Down
2 changes: 2 additions & 0 deletions app/models/service_template_transformation_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def request_type
"transformation_plan"
end

default_value_for :internal, true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also want a default_value_for :internal, false at the base class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really want such a default_value? Without default we don't need to insert a record in the reserved table.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this upstream once we have the real column, so it is fine to ignore while we are working on the reserves table commits.


def transformation_mapping
service_resources.find_by(:resource_type => 'TransformationMapping').resource
end
Expand Down
11 changes: 11 additions & 0 deletions spec/models/service_template_transformation_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down