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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Exclude text custom fields from sorting
Klaus Zanders083742339e29
diff --git a/app/models/queries/projects/orders/custom_field_order.rb b/app/models/queries/projects/orders/custom_field_order.rbindex b72391421f4..8e98698eef8 100644--- a/app/models/queries/projects/orders/custom_field_order.rb+++ b/app/models/queries/projects/orders/custom_field_order.rb@@ -29,17 +29,27 @@class Queries::Projects::Orders::CustomFieldOrder < Queries::Orders::Baseself.model = Project.all+ EXCLUDED_CUSTOM_FIELD_TYPES = %w(text)+ KEY_FORMAT = /cf_(\d+)/+validates :custom_field, presence: { message: I18n.t(:"activerecord.errors.messages.does_not_exist") }def self.key- /cf_(\d+)/+ valid_ids = RequestStore.fetch(:custom_sortable_project_custom_fields) do+ ProjectCustomField.where.not(field_format: EXCLUDED_CUSTOM_FIELD_TYPES).visible.pluck(:id).join("|")+ end++ /cf_(#{valid_ids})/enddef custom_field@custom_field ||= begin- id = self.class.key.match(attribute)[1]+ id = KEY_FORMAT.match(attribute)[1]- ProjectCustomField.visible.find_by_id(id)+ ProjectCustomField+ .where.not(field_format: EXCLUDED_CUSTOM_FIELD_TYPES)+ .visible+ .find_by(id:)endenddiff --git a/spec/models/queries/projects/orders/custom_field_order_spec.rb b/spec/models/queries/projects/orders/custom_field_order_spec.rbnew file mode 100644index 00000000000..086850848d8--- /dev/null+++ b/spec/models/queries/projects/orders/custom_field_order_spec.rb@@ -0,0 +1,44 @@+#-- 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::Orders::CustomFieldOrder do+ let!(:cf_text) { FactoryBot.create(:text_project_custom_field) }+ let!(:cf_int) { FactoryBot.create(:integer_project_custom_field) }++ it "does not allow to sort by the text field" do+ cf = described_class.new("cf_#{cf_text.id}")+ expect(cf).not_to be_available+ end++ it "allows to sort by all other fields" do+ cf = described_class.new("cf_#{cf_int.id}")+ expect(cf).to be_available+ end+end