Skip to content

Commit

Permalink
Merge pull request #1906 from syncrou/skip_rbac_on_nil_or_null
Browse files Browse the repository at this point in the history
Skip calling Rbac on a null or nil target_class
(cherry picked from commit fb1cba5)

https://bugzilla.redhat.com/show_bug.cgi?id=1481851
  • Loading branch information
mzazrivec authored and simaishi committed Aug 15, 2017
1 parent cdb049e commit fd54f3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/controllers/ops_controller/settings/automate_schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ def automate_schedules_set_vars
end

def fetch_target_ids
targets = Rbac.filtered(params[:target_class]).select(:id, :name)
unless targets.nil?
targets = targets.sort_by { |t| t.name.downcase }.collect { |t| [t.name, t.id.to_s] }
target_id = ""
if params[:target_class] && params[:target_class] != 'null'
targets = Rbac.filtered(params[:target_class]).select(:id, :name)
unless targets.nil?
targets = targets.sort_by { |t| t.name.downcase }.collect { |t| [t.name, t.id.to_s] }
end
end

render :json => {
:target_id => target_id,
:target_id => '',
:targets => targets
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@
end
end

describe "#fetch_target_ids" do
include OpsController::Settings::AutomateSchedules
let(:ops) { OpsController.new }

before do
ops.instance_variable_set(:@params, {})
end

[nil, 'null'].each do |target|
it "skips Rbac if :target_class is #{target}" do
ops.params = {:target_class => target }
expect(ops).to receive(:render).once
expect(Rbac).to receive(:filtered).never
ops.fetch_target_ids
end
end
end

describe "#fetch_automate_request_vars" do
include OpsController::Settings::AutomateSchedules
let(:ops) { OpsController.new }
Expand Down

0 comments on commit fd54f3a

Please sign in to comment.