Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix/search for projects (#8815)

ulferts5a7176e6e15b
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 5116f60d85c..d95bc15a929 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -178,7 +178,7 @@ class SearchController < ApplicationController
end
def provision_gon
- available_search_types = Redmine::Search.available_search_types.dup.push('all')
+ available_search_types = search_types.dup.push('all')
gon.global_search = {
search_term: @question,
diff --git a/app/models/project.rb b/app/models/project.rb
index 13daff9812a..2f1d72dddf6 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -148,6 +148,12 @@ class Project < ApplicationRecord
project_key: 'id',
permission: nil
+ # Necessary for acts_as_searchable which depends on the event_datetime method for sorting
+ acts_as_event title: Proc.new { |o| "#{Project.model_name.human}: #{o.name}" },
+ url: Proc.new { |o| { controller: 'overviews/overviews', action: 'show', project_id: o } },
+ author: nil,
+ datetime: :created_at
+
validates :name,
presence: true,
length: { maximum: 255 }
diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb
index b23b7acc738..975c4ec100c 100644
--- a/spec/features/search_spec.rb
+++ b/spec/features/search_spec.rb
@@ -167,7 +167,7 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:
end
end
- describe 'work package search' do
+ describe 'search for work packages' do
context 'search in all projects' do
let(:params) { [project, { q: query, work_packages: 1 }] }
@@ -342,6 +342,29 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:
end
end
+ describe 'search for projects' do
+ let!(:searched_for_project) { FactoryBot.create(:project, name: 'Searched for project') }
+ let!(:other_project) { FactoryBot.create(:project, name: 'Other project') }
+
+ context 'globally' do
+ it 'finds the project' do
+ select_autocomplete(page.find('.top-menu-search--input'),
+ query: "Searched",
+ select_text: "In all projects ↵")
+
+ within '.global-search--tabs' do
+ click_on 'Projects'
+ end
+
+ expect(page)
+ .to have_link(searched_for_project.name)
+
+ expect(page)
+ .to have_no_link(other_project.name)
+ end
+ end
+ end
+
describe 'pagination' do
context 'project wide search' do
it 'works' do