Skip to content

Commit

Permalink
Merge pull request ManageIQ#16716 from gtanzillo/custom-reports-tenan…
Browse files Browse the repository at this point in the history
…t-level

Expand scope of report definitions that visible to a user
(cherry picked from commit eff2583)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1532857
  • Loading branch information
carbonin authored and d-m-u committed Jun 6, 2018
1 parent 67dee1e commit 0deb257
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/miq_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MiqReport < ApplicationRecord
all
else
where(
arel_table[:rpt_type].eq('Custom').and(arel_table[:miq_group_id].eq(user.current_group_id))
arel_table[:rpt_type].eq('Custom').and(arel_table[:miq_group_id].in(user.current_tenant.miq_groups.pluck(:id)))
.or(
arel_table[:rpt_type].eq('Default')
)
Expand Down
18 changes: 18 additions & 0 deletions spec/models/miq_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
end

describe MiqReport do
context ".for_user" do
let(:my_user) { FactoryGirl.create(:user_with_group) }
let(:group_in_my_tenant) { FactoryGirl.create(:miq_group, :tenant => my_user.current_tenant) }

let(:other_tenant) { FactoryGirl.create(:tenant) }
let(:group_in_other_tenant) { FactoryGirl.create(:miq_group, :tenant => other_tenant) }

let!(:my_report) { FactoryGirl.create(:miq_report, :miq_group => my_user.current_group, :rpt_type => "Custom") }
let!(:report_in_my_tenant) { FactoryGirl.create(:miq_report, :miq_group => group_in_my_tenant, :rpt_type => "Custom") }
let!(:report_in_another_tenant) { FactoryGirl.create(:miq_report, :miq_group => group_in_other_tenant, :rpt_type => "Custom") }

it "returns reports created by me or anyone in a group in my tenant" do
User.current_user = my_user

expect(described_class.for_user(my_user)).to match_array([my_report, report_in_my_tenant])
end
end

context "report with filtering in Registry" do
let(:options) { {:targets_hash => true, :userid => "admin"} }
let(:miq_task) { FactoryGirl.create(:miq_task) }
Expand Down

0 comments on commit 0deb257

Please sign in to comment.