Skip to content

Commit a5142a4

Browse files
committed
Revert the search code update
1 parent 81f3d0f commit a5142a4

5 files changed

Lines changed: 23 additions & 28 deletions

File tree

app/controllers/kaui/accounts_controller.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ def index
77
@search_query = params[:q]
88
@advance_search_query = @search_query || request.query_string
99
if @search_query.present?
10-
# Fetch 2 to determine if there's exactly 1 match without relying on
11-
# pagination_max_nb_records which can be unreliable for small result sets
12-
accounts = Kaui::Account.list_or_search(@search_query, 0, 2, options_for_klient)
13-
if accounts.empty?
10+
account = Kaui::Account.list_or_search(@search_query, -1, 1, options_for_klient).first
11+
if account.nil?
1412
flash[:error] = "No account matches \"#{@search_query}\""
1513
redirect_to kaui_engine.home_path
16-
return
17-
elsif accounts.length == 1
18-
redirect_to kaui_engine.account_path(accounts.first.account_id)
19-
return
14+
else
15+
redirect_to kaui_engine.account_path(account.account_id)
2016
end
17+
return
2118
end
2219
@search_fields = Kaui::Account::ADVANCED_SEARCH_COLUMNS.map { |attr| [attr, attr.split('_').join(' ').capitalize] }
2320
@dropdown_default = default_columns(Kaui.account_search_columns.call[2], Kaui::Account::SENSIVITE_DATA_FIELDS)

app/controllers/kaui/home_controller.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def splitting_new_search(search_query)
3535
(search_query || '').split(':').map(&:strip)
3636
end
3737

38-
def account_search(search_query, search_by = nil, _fast = 0, options = {})
38+
def account_search(search_query, search_by = nil, fast = 0, options = {})
3939
if search_by == 'ID'
4040
begin
4141
account = Kaui::Account.find_by_id(search_query, false, false, options)
@@ -51,11 +51,10 @@ def account_search(search_query, search_by = nil, _fast = 0, options = {})
5151
search_error("No account matches \"#{search_query}\"")
5252
end
5353
else
54-
accounts = Kaui::Account.list_or_search(search_query, 0, 2, options)
55-
account = accounts.first
56-
if accounts.empty?
54+
account = Kaui::Account.list_or_search(search_query, 0, 1, options).first
55+
if account.blank?
5756
search_error("No account matches \"#{search_query}\"")
58-
elsif accounts.length == 1
57+
elsif true?(fast)
5958
redirect_to account_path(account.account_id) and return
6059
else
6160
redirect_to accounts_path(q: search_query) and return

test/functional/kaui/accounts_controller_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class AccountsControllerTest < Kaui::FunctionalTestHelper
1010
end
1111

1212
test 'should get index one account' do
13-
# When searching by exact account_id, only one result exists → redirect directly to account detail
1413
parameters = {
14+
fast: '1',
1515
q: @account.account_id
1616
}
1717

@@ -20,6 +20,7 @@ class AccountsControllerTest < Kaui::FunctionalTestHelper
2020
assert_redirected_to account_path(@account.account_id)
2121

2222
parameters = {
23+
fast: '1',
2324
q: 'THIS_IS_NOT_FOUND_REDIRECT'
2425
}
2526

test/functional/kaui/admin_tenants_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def create_kaui_tenant
365365
def installed_plugins
366366
installed_plugins = []
367367
nodes_info = KillBillClient::Model::NodesInfo.nodes_info(build_options(@tenant, USERNAME, PASSWORD)) || []
368-
plugins_info = nodes_info.flat_map { |node| node.plugins_info || [] }
368+
plugins_info = nodes_info.first.plugins_info || []
369369
plugins_info.each do |plugin|
370370
next if plugin.plugin_key.nil? || plugin.version.nil?
371371
next if installed_plugins.any? { |p| p[:plugin_name].eql?(plugin.plugin_name) }

test/functional/kaui/home_controller_test.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,37 @@ class HomeControllerTest < Kaui::FunctionalTestHelper
4242

4343
test 'should understand account search queries' do
4444
dummy_uuid = SecureRandom.uuid.to_s
45-
# search by account_id (unique UUID) → redirects directly to account detail
45+
# search defaults using a UUID
4646
get :search, params: { q: query_builder('ACCOUNT', @account.account_id) }
47-
assert_redirected_to account_path(@account.account_id)
47+
assert_redirected_to accounts_path(q: @account.account_id)
4848

49-
# search by name ('Kaui' is shared across test accounts) → redirects to list
49+
# search defaults using a String
5050
get :search, params: { q: query_builder('ACCOUNT', @account.name) }
5151
assert_redirected_to accounts_path(q: @account.name)
5252

53-
# search by account_id again → redirects directly to account detail
53+
# search by ID
5454
get :search, params: { q: query_builder('ACCOUNT', @account.account_id) }
55-
assert_redirected_to account_path(@account.account_id)
55+
assert_redirected_to accounts_path(q: @account.account_id)
5656

5757
# search by ID and fails
5858
get :search, params: { q: query_builder('ACCOUNT', dummy_uuid) }
5959
assert_redirected_to home_path
6060
assert_equal "No account matches \"#{dummy_uuid}\"", flash[:error]
6161

62-
# search by external_key (unique UUID) → redirects directly to account detail
62+
# search by EXTERNAL_KEY
6363
get :search, params: { q: query_builder('ACCOUNT', @account.external_key) }
64-
assert_redirected_to account_path(@account.account_id)
64+
assert_redirected_to accounts_path(q: @account.external_key)
6565

6666
# search by EXTERNAL_KEY and fails
6767
get :search, params: { q: query_builder('ACCOUNT', dummy_uuid) }
6868
assert_redirected_to home_path
6969
assert_equal "No account matches \"#{dummy_uuid}\"", flash[:error]
7070

71-
# search by name (shared) → redirects to list
71+
# search by BLANK only first
7272
get :search, params: { q: query_builder('ACCOUNT', @account.name) }
7373
assert_redirected_to accounts_path(q: @account.name)
7474

75-
# search by name again (shared) → redirects to list
75+
# search by BLANK
7676
get :search, params: { q: query_builder('ACCOUNT', @account.name) }
7777
assert_redirected_to accounts_path(q: @account.name)
7878

@@ -327,11 +327,9 @@ class HomeControllerTest < Kaui::FunctionalTestHelper
327327
test 'should understand tag search queries' do
328328
dummy_uuid = SecureRandom.uuid.to_s
329329
tag = create_tag
330-
# search by tag UUID: Kill Bill tag search doesn't support lookup by tag_id,
331-
# so this falls through to an error
330+
# search by ID
332331
get :search, params: { q: query_builder('TAG', tag[0].tag_id) }
333-
assert_redirected_to home_path
334-
assert_equal "No tag matches \"#{tag[0].tag_id}\"", flash[:error]
332+
assert_redirected_to tags_path(q: tag[0].tag_id)
335333

336334
# search by ID and fails
337335
get :search, params: { q: query_builder('TAG', dummy_uuid) }

0 commit comments

Comments
 (0)