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

Expand scope of report definitions that visible to a user #16716

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/miq_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what happened in the specs, but maybe it's not safe to set User.current_user as that sets a thread variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I had that line there when the tests were passing. I'm gonna restart and hope it succeeds.


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