Skip to content

Commit 700aa89

Browse files
committed
Fixes #38656 - Make autocompletion honor permissions
1 parent 7391419 commit 700aa89

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

app/controllers/katello/concerns/filtered_auto_complete_search.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module FilteredAutoCompleteSearch
88
def auto_complete_search
99
begin
1010
options = resource_class.respond_to?(:completer_scope_options) ? resource_class.completer_scope_options(params[:search]) : {}
11-
items = resource_class.where(:id => self.index_relation).complete_for(params[:search], options)
11+
permission = resource_class.find_permission_name(:view)
12+
items = resource_class.authorized(permission).where(:id => self.index_relation).complete_for(params[:search], options)
1213
items = filter_autocomplete_items(items)
1314
items = items.map do |item|
1415
category = ['and', 'or', 'not', 'has'].include?(item.to_s.sub(/^.*\s+/, '')) ? _('Operators') : ''
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'katello_test_helper'
2+
3+
class AutoCompleteSearchTest < ActionController::TestCase
4+
# Chosen at random as a representative of the controllers supporting Katello's autocompletion
5+
tests ::Katello::Api::V2::ProductsController
6+
7+
def setup
8+
setup_controller_defaults_api
9+
end
10+
11+
test "only suggests options the user is allowed to see" do
12+
user = users(:one)
13+
org = user.organizations.first
14+
product1 = FactoryBot.create(:katello_product, :with_provider, organization_id: org.id)
15+
_product2 = FactoryBot.create(:katello_product, :with_provider, organization_id: org.id)
16+
setup_user('view', 'products', "name = \"#{product1.name}\"")
17+
18+
get :auto_complete_search, session: set_session_user(:one), params: { search: "name =", organization_id: org.id }
19+
assert_predicate response, :successful?
20+
suggestions = ActiveSupport::JSON.decode(response.body)
21+
assert_equal 1, suggestions.length
22+
assert_equal suggestions.first['part'], "name = \"#{product1.name}\""
23+
end
24+
end

0 commit comments

Comments
 (0)