Skip to content

Commit

Permalink
Merge pull request #7556 from h-kataria/split_policy_rsop
Browse files Browse the repository at this point in the history
Split policy rsop
  • Loading branch information
gtanzillo authored Jan 14, 2021
2 parents ba3c2da + eec54d2 commit bb2e334
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 102 deletions.
11 changes: 3 additions & 8 deletions app/controllers/miq_policy_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class MiqPolicyController < ApplicationController
include_concern 'Events'
include_concern 'Policies'
include_concern 'Rsop'

before_action :check_privileges
before_action :get_session_data
Expand Down Expand Up @@ -395,11 +394,7 @@ def folder_get_info(folder_node)

def get_session_data
@title = _("Policies")
@layout = if request.parameters["action"] == "wait_for_task" # Don't change layout when wait_for_task came in for RSOP
session[:layout]
else
params[:action]&.starts_with?("rsop") ? "miq_policy_rsop" : "miq_policy"
end
@layout = "miq_policy"
@lastaction = session[:miq_policy_lastaction]
@display = session[:miq_policy_display]
@current_page = session[:miq_policy_current_page]
Expand Down Expand Up @@ -430,15 +425,15 @@ def breadcrumbs_options
{:title => _("Control")},
menu_breadcrumb,
].compact,
:not_tree => %w[rsop log].include?(action_name),
:not_tree => %w[log].include?(action_name),
:record_title => :description,
}
end

def menu_breadcrumb
return nil if %w[log].include?(action_name)

{:title => action_name == 'rsop' ? _('Simulation') : _('Explorer')}
{:title => _('Explorer')}
end

menu_section :con
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
module MiqPolicyController::Rsop
extend ActiveSupport::Concern
class MiqPolicyRsopController < ApplicationController
before_action :check_privileges
before_action :get_session_data
after_action :cleanup_action
after_action :set_session_data

include Mixins::GenericSessionMixin
include Mixins::BreadcrumbsMixin

def title
@title = _("Simulation")
end

def self.table_name
@table_name = "miq_policy_rsop"
end

def index
assert_privileges('policy_simulation')
flash_to_session
@breadcrumbs = []
session[:changed] = false
@sb[:rsop] ||= {} # Leave exising values
rsop_put_objects_in_sb(find_filtered(ExtManagementSystem), :emss)
rsop_put_objects_in_sb(find_filtered(EmsCluster), :clusters)
rsop_put_objects_in_sb(find_filtered(Host), :hosts)
rsop_put_objects_in_sb(find_filtered(Vm), :vms)
rsop_put_objects_in_sb(find_filtered(Storage), :datastores)
@rsop_events = MiqEventDefinitionSet.all.collect { |e| [e.description, e.id.to_s] }.sort
@rsop_event_sets = MiqEventDefinitionSet.find(@sb[:rsop][:event]).miq_event_definitions.collect { |e| [e.description, e.id.to_s] }.sort unless @sb[:rsop][:event].nil?
end

def rsop
assert_privileges('policy_simulation')
@explorer = true
if params[:button] == "submit"
if params[:task_id] # First time thru, kick off the report generate task
miq_task = MiqTask.find(params[:task_id]) # Not first time, read the task record
Expand Down Expand Up @@ -45,19 +73,7 @@ def rsop
elsif params[:button] == "reset"
@sb[:rsop] = {} # Reset all RSOP stored values
session[:changed] = nil
javascript_redirect(:action => 'rsop')
else # No params, first time in
@breadcrumbs = []
session[:changed] = false
@sb[:rsop] ||= {} # Leave exising values
rsop_put_objects_in_sb(find_filtered(ExtManagementSystem), :emss)
rsop_put_objects_in_sb(find_filtered(EmsCluster), :clusters)
rsop_put_objects_in_sb(find_filtered(Host), :hosts)
rsop_put_objects_in_sb(find_filtered(Vm), :vms)
rsop_put_objects_in_sb(find_filtered(Storage), :datastores)
@rsop_events = MiqEventDefinitionSet.all.collect { |e| [e.description, e.id.to_s] }.sort
@rsop_event_sets = MiqEventDefinitionSet.find(@sb[:rsop][:event]).miq_event_definitions.collect { |e| [e.description, e.id.to_s] }.sort unless @sb[:rsop][:event].nil?
render :layout => "application"
javascript_redirect(:action => 'index')
end
end

Expand Down Expand Up @@ -156,4 +172,35 @@ def rsop_button_pressed
page << javascript_reload_toolbars
end
end

def get_session_data
@title = _("Simulation")
@layout = "miq_policy_rsop"
@lastaction = session[:miq_policy_rsop_lastaction]
@display = session[:miq_policy_rsop_display]
@current_page = session[:miq_policy_rsop_current_page]
end

def set_session_data
super
session[:layout] = @layout
session[:miq_policy_rsop_current_page] = @current_page
end

def breadcrumbs_options
{
:breadcrumbs => [
{:title => _("Control")},
menu_breadcrumb,
].compact,
# :not_tree => %w[rsop export log].include?(action_name),
# :record_title => :description,
}
end

def menu_breadcrumb
{:title => _('Simulation')}
end

menu_section :con
end
5 changes: 2 additions & 3 deletions app/helpers/application_helper/page_layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,14 @@ def inner_layout_present?
begin
@explorer || params[:action] == "explorer" ||
(params[:controller] == "miq_ae_tools" && (params[:action] == "resolve" || params[:action] == "show")) ||
(params[:controller] == "miq_policy" && params[:action] == "rsop") ||
params[:controller] == "utilization"
params[:controller] == "miq_policy_rsop" || params[:controller] == "utilization"
end
end

def simulate?
@simulate ||=
begin
rsop = controller.controller_name == 'miq_policy' && controller.action_name == 'rsop'
rsop = controller.controller_name == 'miq_policy_rsop' && controller.action_name == 'rsop'
resolve = controller.controller_name == 'miq_ae_tools' && controller.action_name == 'resolve'
rsop || resolve
end
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/menu/default_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def control_menu_section
Menu::Item.new('miq_action', N_('Actions'), 'miq_action', {:feature => 'miq_action', :any => true}, '/miq_action/explorer'),
Menu::Item.new('miq_alert_set', N_('Alert Profiles'), 'miq_alert_set', {:feature => 'miq_alert_set', :any => true}, '/miq_alert_set/explorer'),
Menu::Item.new('miq_alert', N_('Alerts'), 'miq_alert', {:feature => 'miq_alert', :any => true}, '/miq_alert/explorer'),
Menu::Item.new('miq_policy_rsop', N_('Simulation'), 'policy_simulation', {:feature => 'policy_simulation'}, '/miq_policy/rsop'),
Menu::Item.new('miq_policy_export', N_('Import / Export'), 'policy_import_export', {:feature => 'policy_import_export'}, '/miq_policy_export'),
Menu::Item.new('miq_policy_rsop', N_('Simulation'), 'policy_simulation', {:feature => 'policy_simulation'}, '/miq_policy_rsop'),
Menu::Item.new('miq_policy_export', N_('Import / Export'), 'policy_import_export', {:feature => 'policy_import_export'}, '/miq_policy/export'),
Menu::Item.new('miq_policy_logs', N_('Log'), 'policy_log', {:feature => 'policy_log'}, '/miq_policy/log')
])
end
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 10 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,6 @@
explorer
fetch_log
log
rsop
),
:post => %w(
button
Expand All @@ -2101,10 +2100,6 @@
policy_field_changed
quick_search
reload
rsop
rsop_option_changed
rsop_show_options
rsop_toggle
tree_autoload
tree_select
wait_for_task
Expand All @@ -2114,6 +2109,16 @@
x_post
},

:miq_policy_rsop => {
:post => %w(
rsop
rsop_option_changed
rsop_show_options
rsop_toggle
wait_for_task
)
},

:miq_policy_set => {
:get => %w(
edit
Expand Down
3 changes: 3 additions & 0 deletions spec/config/routes.pending.yml
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ MiqPolicyController:
- x_show
MiqPolicyExportController:
- report_data
MiqPolicyRsopController:
- report_data
- wait_for_task
MiqPolicySetController:
- form_field_changed
- index
Expand Down
26 changes: 0 additions & 26 deletions spec/controllers/miq_policy_controller/rsop_spec.rb

This file was deleted.

9 changes: 1 addition & 8 deletions spec/controllers/miq_policy_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
let(:display) { 'display' }
let(:current_page) { 'current_page' }
let(:server_options) { 'server options' }
let(:layout) { 'layout' }
let(:layout) { 'miq_policy' }

describe '#get_session_data' do
it "Sets variables correctly" do
Expand All @@ -140,7 +140,6 @@
:server_options => server_options,
:layout => layout)
allow(controller).to receive(:alert_build_pulldowns).and_return(nil)
allow(controller.request).to receive(:parameters).and_return('action' => 'wait_for_task')
controller.send(:get_session_data)

expect(controller.instance_variable_get(:@title)).to eq("Policies")
Expand Down Expand Up @@ -199,12 +198,6 @@
expect(controller.data_for_breadcrumbs.pluck(:title)[1]).to eq("Explorer")
end

it "shows 'simulation' on rsop screen" do
get :rsop

expect(controller.data_for_breadcrumbs.pluck(:title)[1]).to eq("Simulation")
end

it "shows 'log' on log screen" do
get :log

Expand Down
61 changes: 61 additions & 0 deletions spec/controllers/miq_policy_rsop_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
describe MiqPolicyRsopController do
before do
stub_user(:features => :all)
end

context "GenericSessionMixin" do
let(:lastaction) { 'lastaction' }
let(:layout) { 'miq_policy_rsop' }

describe '#get_session_data' do
it "Sets variables correctly" do
allow(controller).to receive(:session).and_return(:miq_policy_rsop_lastaction => lastaction,
:layout => layout)
controller.send(:get_session_data)

expect(controller.instance_variable_get(:@title)).to eq("Simulation")
expect(controller.instance_variable_get(:@layout)).to eq(layout)
expect(controller.instance_variable_get(:@lastaction)).to eq(lastaction)
end
end

describe '#set_session_data' do
it "Sets session correctly" do
controller.instance_variable_set(:@lastaction, lastaction)
controller.instance_variable_set(:@layout, layout)
controller.send(:set_session_data)

expect(controller.session[:miq_policy_rsop_lastaction]).to eq(lastaction)
expect(controller.session[:layout]).to eq(layout)
end
end
end

describe "#index" do
it "first time on RSOP screen, session[:changed] should be false" do
session[:changed] = true
controller.instance_variable_set(:@current_user,
FactoryBot.create(:user,
:name => "foo",
:miq_groups => [],
:userid => "foo"))
controller.instance_variable_set(:@sb, {})
allow(controller).to receive(:rsop_put_objects_in_sb)
allow(controller).to receive(:find_filtered)
allow(controller).to receive(:appliance_name)
get :index
expect(session[:changed]).to be_falsey
expect(response).to render_template('miq_policy_rsop/index')
end
end

describe "breadcrumbs" do
before { EvmSpecHelper.local_miq_server }

it "shows 'simulation' on rsop screen" do
post :rsop

expect(controller.data_for_breadcrumbs.pluck(:title)[1]).to eq("Simulation")
end
end
end
34 changes: 0 additions & 34 deletions spec/routing/miq_policy_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,6 @@
end
end

describe '#rsop' do
it 'routes with GET' do
expect(get("/#{controller_name}/rsop")).to route_to("#{controller_name}#rsop")
end

it 'routes with POST' do
expect(post("/#{controller_name}/rsop")).to route_to("#{controller_name}#rsop")
end
end

describe '#rsop_option_changed' do
it 'routes with POST' do
expect(post("/#{controller_name}/rsop_option_changed")).to route_to("#{controller_name}#rsop_option_changed")
end
end

describe '#rsop_toggle' do
it 'routes with POST' do
expect(post("/#{controller_name}/rsop_toggle")).to route_to("#{controller_name}#rsop_toggle")
end
end

describe '#rsop_show_options' do
it 'routes with POST' do
expect(post("/#{controller_name}/rsop_show_options")).to route_to("#{controller_name}#rsop_show_options")
end
end

describe '#wait_for_task' do
it 'routes with POST' do
expect(post("/#{controller_name}/wait_for_task")).to route_to("#{controller_name}#wait_for_task")
end
end

describe '#miq_event_edit' do
it 'routes with POST' do
expect(post("/#{controller_name}/miq_event_edit")).to route_to("#{controller_name}#miq_event_edit")
Expand Down
Loading

0 comments on commit bb2e334

Please sign in to comment.