Skip to content

Commit

Permalink
Changes to exclude service templates marked as service_type = internal
Browse files Browse the repository at this point in the history
This is to exclude Migration Plan Service Templates from Catalogs Explorer. Backend changes to support this are in ManageIQ/manageiq#17681

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1594408
  • Loading branch information
h-kataria committed Jul 30, 2018
1 parent ce557f1 commit 5fc42f8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions app/controllers/catalog_controller.rb
Expand Up @@ -1455,7 +1455,7 @@ def rearrange_groups_array

def get_available_resources(kls)
@edit[:new][:available_resources] = {}
Rbac.filtered(kls.constantize.where("type is null or type != 'ServiceTemplateAnsiblePlaybook'")).select(:id, :name).each do |r|
Rbac.filtered(kls.constantize.where("type is null or type not in (?)", ['ServiceTemplateAnsiblePlaybook', 'ServiceTemplateTransformationPlan'])).select(:id, :name).each do |r|
@edit[:new][:available_resources][r.id] = r.name if r.id.to_s != @edit[:rec_id].to_s &&
!@edit[:new][:selected_resources].include?(r.id) # don't add the servicetemplate record that's being edited, or add all vm templates
end
Expand Down Expand Up @@ -1733,9 +1733,10 @@ def get_node_info_handle_root_node
typ = root_node_model(x_active_tree)
@no_checkboxes = true if x_active_tree == :svcs_tree
if x_active_tree == :svccat_tree
service_template_list([:displayed, :with_existent_service_template_catalog_id], :no_checkboxes => true)
service_template_list([:displayed, :with_existent_service_template_catalog_id, :public_service_templates], :no_checkboxes => true)
else
options = {:model => typ.constantize}
options[:named_scope] = :public_service_templates if x_active_tree == :sandt_tree
options[:named_scope] = :orderable if x_active_tree == :ot_tree
process_show_list(options)
end
Expand Down Expand Up @@ -1765,7 +1766,7 @@ def get_node_info_handle_unassigned_node
def get_node_info_handle_stc_node(id)
if x_active_tree == :sandt_tree
# catalog items accordion also shows the non-"Display in Catalog" items
scope = [[:with_service_template_catalog_id, id]]
scope = [:public_service_templates, [:with_service_template_catalog_id, id]]
else
scope = [:displayed, [:with_service_template_catalog_id, id]]
end
Expand All @@ -1776,7 +1777,7 @@ def get_node_info_handle_stc_node(id)

def get_node_info_handle_leaf_node_stcat(id)
@record = ServiceTemplateCatalog.find(id)
@record_service_templates = Rbac.filtered(@record.service_templates)
@record_service_templates = Rbac.filtered(@record.service_templates.where("service_type != 'internal'"))
typ = TreeBuilder.get_model_for_prefix(@nodetype)
@right_cell_text = _("%{model} \"%{name}\"") % {:name => @record.name, :model => ui_lookup(:model => typ)}
end
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/tree_builder_catalog_items.rb
Expand Up @@ -22,9 +22,9 @@ def root_options

def x_get_tree_stc_kids(object, count_only)
templates = if object.id.nil?
ServiceTemplate.where(:service_template_catalog_id => nil)
ServiceTemplate.where("service_template_catalog_id is null and service_type != 'internal'")
else
object.service_templates
object.service_templates.where("service_type != 'internal'")
end
count_only_or_objects_filtered(count_only, templates, 'name')
end
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/tree_builder_service_catalog.rb
Expand Up @@ -25,14 +25,14 @@ def x_get_tree_roots(count_only, _options)
filtered_objects = []
# only show catalogs nodes that have any servicetemplate records under them
objects.each do |object|
items = Rbac.filtered(object.service_templates)
items = Rbac.filtered(object.service_templates.where("service_type != 'internal' and display is true"))
filtered_objects.push(object) unless items.empty?
end
count_only_or_objects(count_only, filtered_objects, 'name')
end

def x_get_tree_stc_kids(object, count_only)
objects = Rbac.filtered(object.service_templates.where(:display => true))
objects = Rbac.filtered(object.service_templates.where("service_type != 'internal' and display is true"))
count_only_or_objects(count_only, objects, 'name')
end
end
6 changes: 3 additions & 3 deletions spec/controllers/catalog_controller_spec.rb
Expand Up @@ -59,20 +59,20 @@
context 'get_view' do
it "returns all catalog items related to current tenant and root tenant when non-self service user is logged" do
login_as child_tenant_user
view, _pages = controller.send(:get_view, ServiceTemplate, {}, true)
view, _pages = controller.send(:get_view, ServiceTemplate, {:named_scope => :public_service_templates}, true)
expect(view.table.data.count).to eq(2)
end

it "returns all catalog items related to current user's groups when self service user is logged" do
allow_any_instance_of(MiqGroup).to receive_messages(:self_service? => true)
login_as child_tenant_user
view, _pages = controller.send(:get_view, ServiceTemplate, {}, true)
view, _pages = controller.send(:get_view, ServiceTemplate, {:named_scope => :public_service_templates}, true)
expect(view.table.data.count).to eq(1)
end

it "returns all catalog items when admin user is logged" do
login_as admin_user
view, _pages = controller.send(:get_view, ServiceTemplate, {}, true)
view, _pages = controller.send(:get_view, ServiceTemplate, {:named_scope => :public_service_templates}, true)
expect(view.table.data.count).to eq(2)
end
end
Expand Down

0 comments on commit 5fc42f8

Please sign in to comment.