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
treat favored just like any other column
ulfertsccf780ef5a78
diff --git a/app/models/queries/projects/factory.rb b/app/models/queries/projects/factory.rbindex 61c1d47cdfc..3ec6b3315a8 100644--- a/app/models/queries/projects/factory.rb+++ b/app/models/queries/projects/factory.rb@@ -109,8 +109,7 @@ class Queries::Projects::Factorydef list_with(name)Queries::Projects::ProjectQuery.new(name: I18n.t(name)) do |query|query.order("lft" => "asc")- default_selects = %w[favored name]- query.select(*(default_selects + Setting.enabled_projects_columns).uniq, add_not_existing: false)+ query.select(*Setting.enabled_projects_columns, add_not_existing: false)yield queryenddiff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 3777da14c0d..6e549ede74c 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -424,7 +424,7 @@ module Settingsdefault: false},enabled_projects_columns: {- default: %w[project_status public created_at latest_activity_at required_disk_space],+ default: %w[favored name project_status public created_at latest_activity_at required_disk_space],allowed: -> { Queries::Projects::ProjectQuery.new.available_selects.map { |s| s.attribute.to_s } }},enabled_scm: {@@ -761,14 +761,14 @@ module Settingsdefault: 3},httpx_operation_timeout: {- description: '',+ description: "",format: :float,writable: false,allowed: (0..),default: 10},httpx_request_timeout: {- description: '',+ description: "",format: :float,writable: false,allowed: (0..),diff --git a/db/migrate/20240430143313_update_default_project_columns.rb b/db/migrate/20240430143313_update_default_project_columns.rbnew file mode 100644index 00000000000..ec1fce0fc51--- /dev/null+++ b/db/migrate/20240430143313_update_default_project_columns.rb@@ -0,0 +1,43 @@+#-- 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.+#++++class UpdateDefaultProjectColumns < ActiveRecord::Migration[7.1]+ def up+ return unless Setting.where(name: "enabled_projects_columns").exists? # rubocop:disable Rails/WhereExists++ columns = Setting.enabled_projects_columns+ columns.unshift("name") if columns.exclude?("name")+ columns.unshift("favored") if columns.exclude?("favored")++ Setting.enabled_projects_columns = columns+ end++ def down+ # Nothing to do+ end+enddiff --git a/spec/migrations/update_default_project_columns_spec.rb b/spec/migrations/update_default_project_columns_spec.rbnew file mode 100644index 00000000000..2eeb1bd2b16--- /dev/null+++ b/spec/migrations/update_default_project_columns_spec.rb@@ -0,0 +1,100 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-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"+require Rails.root.join("db/migrate/20240430143313_update_default_project_columns.rb")++RSpec.describe UpdateDefaultProjectColumns, type: :model do+ # Silencing migration logs, since we are not interested in that during testing+ subject(:run_migration) do+ perform_enqueued_jobs do+ ActiveRecord::Migration.suppress_messages { described_class.new.up }+ end+ end++ context "with no setting existing" do+ it "does not create the setting" do+ run_migration++ expect(Setting.find_by(name: "enabled_projects_columns"))+ .to be_nil+ end+ end++ context "with the setting not having name nor favored column" do+ before do+ Setting.enabled_projects_columns = %w[project_status public]+ end++ it "prepends favored and name" do+ run_migration++ expect(Setting.find_by(name: "enabled_projects_columns").value)+ .to eql %w[favored name project_status public]+ end+ end++ context "with the setting having name but not the favored column" do+ before do+ Setting.enabled_projects_columns = %w[project_status name public]+ end++ it "prepends favored and name" do+ run_migration++ expect(Setting.find_by(name: "enabled_projects_columns").value)+ .to eql %w[favored project_status name public]+ end+ end++ context "with the setting not having name but the favored column" do+ before do+ Setting.enabled_projects_columns = %w[project_status favored public]+ end++ it "prepends favored and name" do+ run_migration++ expect(Setting.find_by(name: "enabled_projects_columns").value)+ .to eql %w[name project_status favored public]+ end+ end++ context "with the setting having both name and favored column" do+ before do+ Setting.enabled_projects_columns = %w[project_status favored public name]+ end++ it "prepends favored and name" do+ run_migration++ expect(Setting.find_by(name: "enabled_projects_columns").value)+ .to eql %w[project_status favored public name]+ end+ end+enddiff --git a/spec/models/queries/projects/factory_spec.rb b/spec/models/queries/projects/factory_spec.rbindex f8049ae608a..20c8f949a5e 100644--- a/spec/models/queries/projects/factory_spec.rb+++ b/spec/models/queries/projects/factory_spec.rb@@ -30,7 +30,7 @@ require "spec_helper"require "services/base_services/behaves_like_create_service"RSpec.describe Queries::Projects::Factory,- with_settings: { enabled_projects_columns: %w[name project_status] } do+ with_settings: { enabled_projects_columns: %w[favored name project_status] } dolet!(:query_finder) doscope = instance_double(ActiveRecord::Relation)@@ -73,7 +73,7 @@ RSpec.describe Queries::Projects::Factory,let(:id) { nil }let(:params) { {} }let(:default_selects) do- %i[favored] + Setting.enabled_projects_columns.map(&:to_sym)+ Setting.enabled_projects_columns.map(&:to_sym)endcurrent_user { build_stubbed(:user) }@@ -661,7 +661,7 @@ RSpec.describe Queries::Projects::Factory,it "has only the available fields (non admin only and only existing cf)" doexpect(find.selects.map(&:attribute))- .to eq(%i[favored name cf_1]) # rubocop:disable Naming/VariableNumber+ .to eq(%i[name cf_1]) # rubocop:disable Naming/VariableNumberendend