-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7557 from h-kataria/split_policy_log
Split policy log
- Loading branch information
Showing
13 changed files
with
172 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
class MiqPolicyLogController < 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 index | ||
assert_privileges('policy_log') | ||
flash_to_session | ||
assert_privileges('policy_log') | ||
@breadcrumbs = [] | ||
@log = $policy_log.contents(nil, 1000) | ||
add_flash(_("Logs for this %{product} Server are not available for viewing") % {:product => Vmdb::Appliance.PRODUCT_NAME}, :warning) if @log.blank? | ||
@lastaction = "policy_logs" | ||
@layout = "miq_policy_logs" | ||
@msg_title = "Policy" | ||
drop_breadcrumb(:name => _("Log"), :url => "/miq_ae_policy/log") | ||
end | ||
|
||
# handle buttons pressed on the button bar | ||
def button | ||
@edit = session[:edit] # Restore @edit for adv search box | ||
@refresh_div = "main_div" # Default div for button.rjs to refresh | ||
if params[:pressed] == "refresh_log" | ||
refresh_log | ||
return | ||
end | ||
|
||
unless @refresh_partial # if no button handler ran, show not implemented msg | ||
add_flash(_("Button not yet implemented"), :error) | ||
@refresh_partial = "layouts/flash_msg" | ||
@refresh_div = "flash_msg_div" | ||
end | ||
end | ||
|
||
def refresh_log | ||
assert_privileges('policy_log') | ||
@log = $policy_log.contents(nil, 1000) | ||
@server = MiqServer.my_server | ||
add_flash(_("Logs for this %{product} Server are not available for viewing") % {:product => Vmdb::Appliance.PRODUCT_NAME}, :warning) if @log.blank? | ||
replace_main_div(:partial => "layouts/log_viewer") | ||
end | ||
|
||
# Send the log in text format | ||
def fetch_log | ||
assert_privileges('policy_log') | ||
disable_client_cache | ||
send_data($policy_log.contents(nil, nil), | ||
:filename => "policy.log") | ||
AuditEvent.success(:userid => session[:userid], | ||
:event => "download_policy_log", | ||
:message => "Policy log downloaded") | ||
end | ||
|
||
def self.table_name | ||
@table_name = "log" | ||
end | ||
|
||
private | ||
|
||
def get_session_data | ||
@title = _("Log") | ||
@layout = "miq_policy_log" | ||
@lastaction = session[:miq_policy_log_lastaction] | ||
end | ||
|
||
def set_session_data | ||
super | ||
session[:layout] = @layout | ||
session[:miq_policy_log_lastaction] = @lastaction | ||
end | ||
|
||
def breadcrumbs_options | ||
{ | ||
:breadcrumbs => [ | ||
{:title => _("Control")}, | ||
menu_breadcrumb, | ||
].compact, | ||
} | ||
end | ||
|
||
def menu_breadcrumb | ||
{:title => _('Log')} | ||
end | ||
|
||
menu_section :con | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
describe MiqPolicyLogController do | ||
before do | ||
stub_user(:features => :all) | ||
end | ||
|
||
context "GenericSessionMixin" do | ||
let(:lastaction) { 'lastaction' } | ||
let(:layout) { 'miq_policy_log' } | ||
|
||
describe '#get_session_data' do | ||
it "Sets variables correctly" do | ||
allow(controller).to receive(:session).and_return(:miq_policy_log_lastaction => lastaction, | ||
:layout => layout) | ||
controller.send(:get_session_data) | ||
|
||
expect(controller.instance_variable_get(:@title)).to eq("Log") | ||
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_log_lastaction]).to eq(lastaction) | ||
expect(controller.session[:layout]).to eq(layout) | ||
end | ||
end | ||
end | ||
|
||
describe "breadcrumbs" do | ||
before { EvmSpecHelper.local_miq_server } | ||
|
||
it "shows 'log' on log screen" do | ||
get :index | ||
|
||
expect(controller.data_for_breadcrumbs.pluck(:title)[1]).to eq("Log") | ||
end | ||
end | ||
end |
Oops, something went wrong.