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

convert id filter to list project filter

Ivan Kuchin37c4d36a492e
diff --git a/app/components/projects/projects_filters_component.rb b/app/components/projects/projects_filters_component.rb
index 6f902b19f54..219ac8465c0 100644
--- a/app/components/projects/projects_filters_component.rb
+++ b/app/components/projects/projects_filters_component.rb
@@ -50,7 +50,8 @@ class Projects::ProjectsFiltersComponent < Filter::FilterComponent
Queries::Projects::Filters::LatestActivityAtFilter,
Queries::Projects::Filters::NameAndIdentifierFilter,
Queries::Projects::Filters::TypeFilter,
- Queries::Projects::Filters::FavoredFilter
+ Queries::Projects::Filters::FavoredFilter,
+ Queries::Projects::Filters::IdFilter
]
allowlist << Queries::Filters::Shared::CustomFields::Base if EnterpriseToken.allows_to?(:custom_fields_in_projects_list)
diff --git a/app/models/queries/projects/filters/id_filter.rb b/app/models/queries/projects/filters/id_filter.rb
index a7ff0ad66d6..491c80d06a5 100644
--- a/app/models/queries/projects/filters/id_filter.rb
+++ b/app/models/queries/projects/filters/id_filter.rb
@@ -27,7 +27,11 @@
#++
class Queries::Projects::Filters::IdFilter < Queries::Projects::Filters::Base
- def type
- :integer
+ include Queries::Filters::Shared::ProjectFilter::Required
+
+ def self.key = :id
+
+ def human_name
+ I18n.t(:label_project, default: :"attributes.project")
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9607c686136..c437674eff2 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2311,6 +2311,7 @@ en:
label_product_version: "Product version"
label_profile: "Profile"
label_percent_complete: "% Complete"
+ label_project: "Project"
label_project_activity: "Project activity"
label_project_attribute_plural: "Project attributes"
label_project_attribute_manage_link: "Manage project attributes"
diff --git a/spec/models/queries/projects/filters/id_filter_spec.rb b/spec/models/queries/projects/filters/id_filter_spec.rb
new file mode 100644
index 00000000000..4035db221bc
--- /dev/null
+++ b/spec/models/queries/projects/filters/id_filter_spec.rb
@@ -0,0 +1,56 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+
+RSpec.describe Queries::Projects::Filters::IdFilter do
+ it_behaves_like "basic query filter" do
+ let(:model) { Project }
+ let(:class_key) { :id }
+ let(:type) { :list }
+ let(:human_name) { "Project" }
+
+ before do
+ visible_scope = instance_double(ActiveRecord::Relation)
+ allow(Project).to receive(:visible).and_return(visible_scope)
+ allow(visible_scope).to receive(:pluck).with(:id).and_return([1234])
+ end
+
+ describe "#allowed_values" do
+ it "is a list of the possible values" do
+ expect(instance.allowed_values).to eq([[1234, "1234"]])
+ end
+ end
+ end
+
+ it_behaves_like "list query filter" do
+ let(:model) { Project }
+ let(:attribute) { :id }
+ let(:valid_values) { ["42"] }
+ end
+end