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 inactive phases from group by
Tobias Dillmannb3c872f546eb
diff --git a/app/models/queries/work_packages.rb b/app/models/queries/work_packages.rbindex 876daaea279..e880e9aa8e2 100644--- a/app/models/queries/work_packages.rb+++ b/app/models/queries/work_packages.rb@@ -84,6 +84,7 @@ module Queries::WorkPackagesexclude Filter::RelatableFilterselect Selects::PropertySelect+ select Selects::ProjectPhaseSelectselect Selects::CustomFieldSelectselect Selects::RelationToTypeSelectselect Selects::RelationOfTypeSelectdiff --git a/app/models/queries/work_packages/selects/project_phase_select.rb b/app/models/queries/work_packages/selects/project_phase_select.rbnew file mode 100644index 00000000000..70e6d20f2fc--- /dev/null+++ b/app/models/queries/work_packages/selects/project_phase_select.rb@@ -0,0 +1,92 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 Queries::WorkPackages::Selects::ProjectPhaseSelect < Queries::WorkPackages::Selects::WorkPackageSelect+ def initialize+ super(:project_phase,+ association: "project_phase_definition",+ group_by_column_name: "project_phase_definition",+ sortable: "pd.position",+ groupable: group_by_statement,+ groupable_join: group_by_join_statement,+ groupable_select: groupable_select+ )+ end++ def groupable_select+ Arel.sql(+ <<~SQL.squish+ CASE WHEN COALESCE(pd.id, 0) = 0 THEN NULL ELSE COALESCE(pd.id, 0) END AS project_phase_definition_id+ SQL+ )+ end++ def group_by_statement+ "COALESCE(pd.id, 0)"+ end++ def order_for_count+ Arel.sql(+ <<~SQL.squish+ CASE WHEN COALESCE(pd.id, 0) = 0 THEN 1 ELSE 0 END+ SQL+ )+ end++ def group_by_join_statement+ <<~SQL.squish+ LEFT OUTER JOIN (+ SELECT d.id, d.position+ FROM project_phase_definitions d+ JOIN project_phases ph ON ph.definition_id = d.id+ JOIN projects p ON ph.project_id = p.id+ WHERE ph.active = true+ GROUP BY d.id+ ) pd+ ON project_phase_definition_id = pd.id+ SQL+ end++ def self.instances(context = nil)+ allowed = if context+ OpenProject::FeatureDecisions.stages_and_gates_active? &&+ User.current.allowed_in_project?(:view_project_phases, context)+ else+ OpenProject::FeatureDecisions.stages_and_gates_active? &&+ User.current.allowed_in_any_project?(:view_project_phases)+ end++ if allowed+ [new]+ else+ []+ end+ end+enddiff --git a/app/models/queries/work_packages/selects/property_select.rb b/app/models/queries/work_packages/selects/property_select.rbindex 008c6e196a2..a34d172626a 100644--- a/app/models/queries/work_packages/selects/property_select.rb+++ b/app/models/queries/work_packages/selects/property_select.rb@@ -51,21 +51,6 @@ class Queries::WorkPackages::Selects::PropertySelect < Queries::WorkPackages::Sesortable: "position",groupable: "#{WorkPackage.table_name}.type_id"},- project_phase: {- association: "project_phase_definition",- group_by_column_name: "project_phase_definition",- sortable: "#{Project::PhaseDefinition.table_name}.position",- groupable: "#{Project::PhaseDefinition.table_name}.id",- only_if: ->(project) do- if project- OpenProject::FeatureDecisions.stages_and_gates_active? &&- User.current.allowed_in_project?(:view_project_phases, project)- else- OpenProject::FeatureDecisions.stages_and_gates_active? &&- User.current.allowed_in_any_project?(:view_project_phases)- end- end- },parent: {association: "ancestors_relations",sortable: false@@ -159,13 +144,9 @@ class Queries::WorkPackages::Selects::PropertySelect < Queries::WorkPackages::Se}}- def self.instances(context = nil)+ def self.instances(_context = nil)property_selects.filter_map do |name, options|- condition = options[:only_if]-- if !condition || condition.call(context)- new(name, options.except(:only_if))- end+ new(name, options)endendenddiff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex 8ad6edb7cd8..c86cffb3df7 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -689,10 +689,6 @@ module API@project_phase ||= represented.project_phaseend- def project_phase_definition- @project_phase_definition ||= represented.project_phase_definition- end-def phase_set_and_active?project_phase&.active?end