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

[IVANCHUK] Refactor get_rec_cls to get proper record class for various items #7241

Merged
33 changes: 6 additions & 27 deletions app/controllers/application_controller/ci_processing.rb
Expand Up @@ -222,7 +222,7 @@ def breadcrumb_name(_model)
def process_cloud_object_storage_buttons(pressed)
assert_privileges(pressed)

klass = get_rec_cls
klass = record_class
task = pressed.sub("#{klass.name.underscore.to_sym}_", "")

return tag(klass) if task == "tag"
Expand All @@ -247,33 +247,12 @@ def cloud_object_store_button_operation(klass, task)
process_objects(items.ids.sort, method, display_name)
end

def get_rec_cls
# FIXME: the specs for ci_processing rely on setting (and testing) request.parameters['controller'].
# That is wrong and needs to be fixed.
case request.parameters["controller"] || controller_name
when "miq_template"
MiqTemplate
when "orchestration_stack"
params[:display] == "instances" ? VmOrTemplate : OrchestrationStack
when "service"
Service
when "cloud_object_store_container"
params[:pressed].starts_with?("cloud_object_store_object") ? CloudObjectStoreObject : CloudObjectStoreContainer
when "cloud_object_store_object"
CloudObjectStoreObject
when "ems_storage"
params[:pressed].starts_with?("cloud_object_store_object") ? CloudObjectStoreObject : CloudObjectStoreContainer
when "ems_cluster"
%w[all_vms vms].include?(params[:display]) || params[:pressed].starts_with?('miq_template') ? VmOrTemplate : EmsCluster
when "storage"
%w[all_vms vms].include?(params[:display]) ? VmOrTemplate : Storage
else
VmOrTemplate
end
def record_class
VmOrTemplate
end

def process_objects(objs, task, display_name = nil)
klass = get_rec_cls
klass = record_class
klass_str = klass.to_s

assert_rbac(klass, objs)
Expand Down Expand Up @@ -410,7 +389,7 @@ def retirevms_now
def check_compliance_vms
assert_privileges(params[:pressed])

records = find_records_with_rbac(get_rec_cls, checked_or_params)
records = find_records_with_rbac(record_class, checked_or_params)
# Check each record if there is any compliance policy assigned to it
if records.any? { |record| !record.has_compliance_policies? }
javascript_flash(
Expand Down Expand Up @@ -620,7 +599,7 @@ def process_resourcepools(rps, task)
# on a record
# options - other optional parameters
def generic_button_operation(action, action_name, operation, options = {})
records = find_records_with_rbac(get_rec_cls, checked_or_params)
records = find_records_with_rbac(record_class, checked_or_params)
if testable_action(action) && !records_support_feature?(records, action_to_feature(action))
javascript_flash(
:text => _("%{action_name} action does not apply to selected items") % {:action_name => action_name},
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller/compare.rb
Expand Up @@ -1207,6 +1207,7 @@ def compare_to_json(view)
@grid_cols_json = @cols.to_json.to_s.html_safe

@lastaction = "compare_miq"
@explorer = true if request.xml_http_request? && explorer_controller?
end

def compare_build_record_rows(view, section, records, fields)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/cloud_object_store_container_controller.rb
Expand Up @@ -119,6 +119,10 @@ def form_params_create

private

def record_class
params[:pressed].starts_with?('cloud_object_store_object') ? CloudObjectStoreObject : CloudObjectStoreContainer
end

def retrieve_provider_regions
managers = ManageIQ::Providers::CloudManager.supported_subclasses.select(&:supports_regions?)
managers.each_with_object({}) do |manager, provider_regions|
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/cloud_object_store_object_controller.rb
Expand Up @@ -29,6 +29,10 @@ def title

private

def record_class
CloudObjectStoreObject
end

def textual_group_list
[%i[properties relationships], %i[tags]]
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/ems_cluster_controller.rb
Expand Up @@ -95,6 +95,10 @@ def button

private

def record_class
%w[all_vms vms].include?(params[:display]) || params[:pressed].starts_with?('miq_template') ? VmOrTemplate : EmsCluster
end

def textual_group_list
[
%i[relationships],
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/ems_infra_controller.rb
Expand Up @@ -224,6 +224,19 @@ def ems_infra_form_fields

private

def record_class
case params[:pressed]
when /^ems_cluster/
EmsCluster
when /^orchestration_stack/
OrchestrationStack
when /^storage/
Storage
else
VmOrTemplate
end
end

############################
# Special EmsCloud link builder for restful routes
def show_link(ems, options = {})
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/ems_storage_controller.rb
Expand Up @@ -73,6 +73,10 @@ def breadcrumbs_options

private

def record_class
params[:pressed].starts_with?('cloud_object_store_object') ? CloudObjectStoreObject : CloudObjectStoreContainer
end

def textual_group_list
[
%i[properties status],
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/host_controller.rb
Expand Up @@ -429,6 +429,17 @@ def host_form_fields

private

def record_class
case params[:display] || @display
when 'storages'
Storage
when 'vms', 'miq_templates'
VmOrTemplate
else
Host
end
end

def textual_group_list
[
%i[properties relationships],
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/miq_template_controller.rb
Expand Up @@ -18,6 +18,10 @@ def index

private

def record_class
MiqTemplate
end

def get_session_data
@title = _("Templates")
@layout = session[:miq_template_type] ? session[:miq_template_type] : "miq_template"
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/orchestration_stack_controller.rb
Expand Up @@ -146,6 +146,10 @@ def stacks_ot_copy

private

def record_class
params[:display] == 'instances' ? VmOrTemplate : OrchestrationStack
end

def textual_group_list
[%i[properties lifecycle relationships], %i[tags]]
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/resource_pool_controller.rb
Expand Up @@ -64,6 +64,10 @@ def button

private

def record_class
%w[all_vms vms].include?(params[:display]) ? VmOrTemplate : ResourcePool
end

def textual_group_list
[%i[properties relationships], %i[configuration smart_management]]
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/service_controller.rb
Expand Up @@ -204,6 +204,10 @@ def display_generic_objects

private

def record_class
Service
end

def sanitize_output(stdout)
htm = stdout.gsub('"', '\"')

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/storage_controller.rb
Expand Up @@ -471,6 +471,10 @@ def storage_scan

private

def record_class
%w[all_vms vms].include?(params[:display]) ? VmOrTemplate : Storage
end

def session_reset
if @record
session[:edit] = @edit = nil
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/vm_common.rb
Expand Up @@ -87,7 +87,7 @@ def reload
end

def show_timeline
db = get_rec_cls
db = record_class
@display = "timeline"
session[:tl_record_id] = params[:id] if params[:id]
@record = find_record_with_rbac(db, session[:tl_record_id])
Expand Down Expand Up @@ -460,18 +460,21 @@ def policies
:options => @policy_options)
@edit = session[:edit] if session[:edit]
if @edit && @edit[:explorer]
@sb[:explorer] = true
if session[:policies].empty?
render_flash(_("No policies were selected for Policy Simulation."), :error)
return
end
@in_a_form = true
replace_right_cell(:action => 'policy_sim', :refresh_breadcrumbs => false)
else
@sb[:explorer] = nil
render :template => 'vm/show'
end
end

def policy_show_options
@explorer = @sb[:explorer]
if params[:passed] == "null" || params[:passed] == ""
@policy_options[:passed] = false
@policy_options[:failed] = true
Expand All @@ -495,6 +498,7 @@ def policy_show_options

# Show/Unshow out of scope items
def policy_options
@explorer = @sb[:explorer]
@vm = @record = identify_record(params[:id], VmOrTemplate)
@policy_options ||= {}
@policy_options[:out_of_scope] = (params[:out_of_scope] == "1")
Expand Down