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

Do not change current_group for super admin user when executing Rbac#lookup_user_group #17347

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
22 changes: 12 additions & 10 deletions lib/rbac/filterer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,16 +573,18 @@ def lookup_user_group(user, userid, miq_group, miq_group_id)
miq_group_id ||= miq_group.try!(:id)
return [user, user.current_group] if user && user.current_group_id.to_s == miq_group_id.to_s

if user
if miq_group_id && (detected_group = user.miq_groups.detect { |g| g.id.to_s == miq_group_id.to_s })
user.current_group = detected_group
elsif miq_group_id && user.super_admin_user?
user.current_group = miq_group || MiqGroup.find_by(:id => miq_group_id)
end
else
miq_group ||= miq_group_id && MiqGroup.find_by(:id => miq_group_id)
end
[user, user.try(:current_group) || miq_group]
group = if user
if miq_group_id && (detected_group = user.miq_groups.detect { |g| g.id.to_s == miq_group_id.to_s })
user.current_group = detected_group
elsif miq_group_id && user.super_admin_user?
miq_group || MiqGroup.find_by(:id => miq_group_id)
else
user.try(:current_group)
end
else
miq_group || (miq_group_id && MiqGroup.find_by(:id => miq_group_id))
end
[user, group]
end

# for reports, user is currently nil, so use the group filter
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/rbac/filterer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,14 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects)
_, group = filter.send(:lookup_user_group, admin, nil, nil, random_group.id)
expect(group).to eq(random_group)
end

it "does not update user.current_group if user is super admin" do
admin = FactoryGirl.create(:user_admin)
admin_group = admin.current_group
random_group = FactoryGirl.create(:miq_group)
filter.send(:lookup_user_group, admin, nil, nil, random_group.id)
expect(admin.current_group).to eq(admin_group)
end
end

context "user" do
Expand Down