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

[#58159] Fixed set of project stages and gates editable on project overview page

Dombi Attilab8de6438e676
diff --git a/app/models/project.rb b/app/models/project.rb
index cb377c6b5ad..8d028fb72e7 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -86,6 +86,7 @@ class Project < ApplicationRecord
has_many :notification_settings, dependent: :destroy
has_many :project_storages, dependent: :destroy, class_name: "Storages::ProjectStorage"
has_many :storages, through: :project_storages
+ has_many :life_cycles, class_name: "Projects::LifeCycle", dependent: :destroy
store_attribute :settings, :deactivate_work_package_attachments, :boolean
@@ -174,7 +175,7 @@ class Project < ApplicationRecord
scopes :activated_time_activity,
:visible_with_activated_time_activity
- enum status_code: {
+ enum :status_code, {
on_track: 0,
at_risk: 1,
off_track: 2,
diff --git a/app/models/projects.rb b/app/models/projects.rb
new file mode 100644
index 00000000000..27b2504bd99
--- /dev/null
+++ b/app/models/projects.rb
@@ -0,0 +1,5 @@
+module Projects
+ def self.table_name_prefix
+ "projects_"
+ end
+end
diff --git a/app/models/projects/gate.rb b/app/models/projects/gate.rb
new file mode 100644
index 00000000000..41543f85b86
--- /dev/null
+++ b/app/models/projects/gate.rb
@@ -0,0 +1,38 @@
+#-- 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 Projects::Gate < Projects::LifeCycle
+ validates :date, presence: true
+ validate :validate_restricted_attributes
+
+ def validate_restricted_attributes
+ if start_date.present? || end_date.present?
+ errors.add(:base, :date_range_not_allowed)
+ end
+ end
+end
diff --git a/app/models/projects/life_cycle.rb b/app/models/projects/life_cycle.rb
new file mode 100644
index 00000000000..f3c4e5d1bab
--- /dev/null
+++ b/app/models/projects/life_cycle.rb
@@ -0,0 +1,44 @@
+#-- 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 Projects::LifeCycle < ApplicationRecord
+ belongs_to :project
+ has_many :work_packages, dependent: :nullify
+
+ validates :name, presence: true
+ validates :type, inclusion: { in: %w[Projects::Stage Projects::Gate], message: :must_be_a_stage_or_gate }
+
+ def initialize(*args)
+ if instance_of? Projects::LifeCycle
+ # Do not allow directly instantiating this class
+ raise NotImplementedError, "Cannot instantiate the base Projects::LifeCycle class directly."
+ end
+
+ super
+ end
+end
diff --git a/app/models/projects/stage.rb b/app/models/projects/stage.rb
new file mode 100644
index 00000000000..1081e3a9f3f
--- /dev/null
+++ b/app/models/projects/stage.rb
@@ -0,0 +1,38 @@
+#-- 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 Projects::Stage < Projects::LifeCycle
+ validates :start_date, :end_date, presence: true
+ validate :validate_restricted_attributes
+
+ def validate_restricted_attributes
+ if date.present?
+ errors.add(:base, :date_not_allowed)
+ end
+ end
+end
diff --git a/app/models/work_package.rb b/app/models/work_package.rb
index e02d14aa81d..1d4437d1b58 100644
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@ -54,6 +54,7 @@ class WorkPackage < ApplicationRecord
belongs_to :assigned_to, class_name: "Principal", optional: true
belongs_to :responsible, class_name: "Principal", optional: true
belongs_to :version, optional: true
+ belongs_to :life_cycle, class_name: "Projects::LifeCycle", optional: true
belongs_to :priority, class_name: "IssuePriority"
belongs_to :category, class_name: "Category", optional: true
@@ -302,7 +303,7 @@ class WorkPackage < ApplicationRecord
end
def done_ratio
- if WorkPackage.status_based_mode? && status && status.default_done_ratio
+ if WorkPackage.status_based_mode? && status&.default_done_ratio
status.default_done_ratio
else
read_attribute(:done_ratio)
@@ -377,7 +378,7 @@ class WorkPackage < ApplicationRecord
# Set the done_ratio using the status if that setting is set. This will keep the done_ratios
# even if the user turns off the setting later
def update_done_ratio_from_status
- if WorkPackage.status_based_mode? && status && status.default_done_ratio
+ if WorkPackage.status_based_mode? && status&.default_done_ratio
self.done_ratio = status.default_done_ratio
end
end
@@ -631,7 +632,7 @@ class WorkPackage < ApplicationRecord
# Default assignment based on category
def default_assign
- if assigned_to.nil? && category && category.assigned_to
+ if assigned_to.nil? && category&.assigned_to
self.assigned_to = category.assigned_to
end
end
diff --git a/config/initializers/feature_decisions.rb b/config/initializers/feature_decisions.rb
index 838b3617f56..1af9d4f3b80 100644
--- a/config/initializers/feature_decisions.rb
+++ b/config/initializers/feature_decisions.rb
@@ -56,3 +56,6 @@ OpenProject::FeatureDecisions.define_singleton_method(:primerized_work_package_a
(Setting.exists?("feature_primerized_work_package_activities_active") &&
Setting.send(:feature_primerized_work_package_activities_active?))
end
+
+OpenProject::FeatureDecisions.add :stages_and_gates,
+ description: "Enables the under construction feature of stages and gates."
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c3a3fa4fcb8..3f7793e5a28 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1106,6 +1106,18 @@ en:
enabled_modules:
dependency_missing: "The module '%{dependency}' needs to be enabled as well since the module '%{module}' depends on it."
format: "%{message}"
+ projects/gate:
+ attributes:
+ base:
+ date_range_not_allowed: "Cannot assign `start_date` or `end_date` to a Gate"
+ projects/life_cycle:
+ attributes:
+ type:
+ must_be_a_stage_or_gate: "must be either Stage or Gate"
+ projects/stage:
+ attributes:
+ base:
+ date_not_allowed: "Cannot assign `date` to a Stage"
project_custom_field_project_mapping:
attributes:
project_ids:
diff --git a/db/migrate/20241030154245_create_projects_life_cycles.rb b/db/migrate/20241030154245_create_projects_life_cycles.rb
new file mode 100644
index 00000000000..acb220dfbbe
--- /dev/null
+++ b/db/migrate/20241030154245_create_projects_life_cycles.rb
@@ -0,0 +1,43 @@
+#-- 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 CreateProjectsLifeCycles < ActiveRecord::Migration[7.1]
+ def change
+ create_table :projects_life_cycles do |t|
+ t.string :type
+ t.string :name
+ t.date :start_date
+ t.date :end_date
+ t.date :date
+ t.belongs_to :color, type: :int
+ t.references :project, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20241101124648_add_life_cycle_to_work_packages.rb b/db/migrate/20241101124648_add_life_cycle_to_work_packages.rb
new file mode 100644
index 00000000000..74dece8486e
--- /dev/null
+++ b/db/migrate/20241101124648_add_life_cycle_to_work_packages.rb
@@ -0,0 +1,5 @@
+class AddLifeCycleToWorkPackages < ActiveRecord::Migration[7.1]
+ def change
+ add_reference :work_packages, :life_cycle, foreign_key: { to_table: :projects_life_cycles }, null: true
+ end
+end
diff --git a/spec/factories/project_life_cycle_factory.rb b/spec/factories/project_life_cycle_factory.rb
new file mode 100644
index 00000000000..c822999a3b6
--- /dev/null
+++ b/spec/factories/project_life_cycle_factory.rb
@@ -0,0 +1,40 @@
+#-- 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.
+#++
+
+FactoryBot.define do
+ factory :project_stage, class: "::Projects::Stage" do
+ sequence(:name) { |n| "Stage No. #{n}" }
+ start_date { Date.current - 2.days }
+ end_date { Date.current + 2.days }
+ end
+
+ factory :project_gate, class: "::Projects::Gate" do
+ sequence(:name) { |n| "Gate No. #{n}" }
+ date { Date.current + 2.days }
+ end
+end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 63eca53f4e7..a5ff8bc6452 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -381,6 +381,10 @@ RSpec.describe Project do
end
end
+ describe "life_cycles" do
+ it { is_expected.to have_many(:life_cycles).class_name("Projects::LifeCycle").dependent(:destroy) }
+ end
+
describe "#enabled_module_names=", with_settings: { default_projects_modules: %w(work_package_tracking repository) } do
context "when assigning a new value" do
let(:new_value) { %w(work_package_tracking news) }
diff --git a/spec/models/projects/gate_spec.rb b/spec/models/projects/gate_spec.rb
new file mode 100644
index 00000000000..b725c812cf8
--- /dev/null
+++ b/spec/models/projects/gate_spec.rb
@@ -0,0 +1,57 @@
+#-- 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.
+#++
+
+require "rails_helper"
+require "support/shared/projects_life_cycle_helpers"
+
+RSpec.describe Projects::Gate do
+ it_behaves_like "a Projects::LifeCycle event"
+
+ describe "validations" do
+ it { is_expected.to validate_presence_of(:date) }
+
+ it "is invalid if `start_date` is present" do
+ gate_with_start_date = build(:project_gate, start_date: Time.zone.today)
+
+ expect(gate_with_start_date).not_to be_valid
+ expect(gate_with_start_date.errors[:base]).to include("Cannot assign `start_date` or `end_date` to a Gate")
+ end
+
+ it "is invalid if `end_date` is present" do
+ gate_with_end_date = build(:project_gate, end_date: Time.zone.today)
+
+ expect(gate_with_end_date).not_to be_valid
+ expect(gate_with_end_date.errors[:base]).to include("Cannot assign `start_date` or `end_date` to a Gate")
+ end
+
+ it "is valid if neither `start_date` nor `end_date` are present" do
+ valid_gate = build(:project_gate)
+ expect(valid_gate).to be_valid
+ end
+ end
+end
diff --git a/spec/models/projects/life_cycle_spec.rb b/spec/models/projects/life_cycle_spec.rb
new file mode 100644
index 00000000000..354de103985
--- /dev/null
+++ b/spec/models/projects/life_cycle_spec.rb
@@ -0,0 +1,48 @@
+#-- 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.
+#++
+
+require "rails_helper"
+
+RSpec.describe Projects::LifeCycle do
+ it "cannot be instantiated" do
+ expect { described_class.new }.to raise_error(NotImplementedError)
+ end
+
+ it "cannot be instantiated with an invalid type" do
+ expect { described_class.new(type: "InvalidType") }.to raise_error(ActiveRecord::SubclassNotFound)
+ end
+
+ it "can be instantiated with a valid type" do
+ expect { described_class.new(type: "Projects::Gate") }.not_to raise_error
+ end
+
+ # For more specs see:
+ # - spec/support/shared/projects_life_cycle_helpers.rb
+ # - spec/models/projects/gate_spec.rb
+ # - spec/models/projects/stage_spec.rb
+end
diff --git a/spec/models/projects/stage_spec.rb b/spec/models/projects/stage_spec.rb
new file mode 100644
index 00000000000..9224917c0df
--- /dev/null
+++ b/spec/models/projects/stage_spec.rb
@@ -0,0 +1,51 @@
+#-- 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.
+#++
+
+require "rails_helper"
+require "support/shared/projects_life_cycle_helpers"
+
+RSpec.describe Projects::Stage do
+ it_behaves_like "a Projects::LifeCycle event"
+
+ describe "validations" do
+ it { is_expected.to validate_presence_of(:start_date) }
+ it { is_expected.to validate_presence_of(:end_date) }
+
+ it "is valid when `start_date` and `end_date` are present" do
+ valid_stage = build(:project_stage)
+ expect(valid_stage).to be_valid
+ end
+
+ it "adds an error when `date` is set" do
+ stage_with_date = build(:project_stage, date: Time.zone.today)
+
+ expect(stage_with_date).not_to be_valid
+ expect(stage_with_date.errors[:base]).to include("Cannot assign `date` to a Stage")
+ end
+ end
+end
diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rb
index 68eec331053..08523150002 100644
--- a/spec/models/work_package_spec.rb
+++ b/spec/models/work_package_spec.rb
@@ -70,6 +70,7 @@ RSpec.describe WorkPackage do
it { is_expected.to belong_to(:assigned_to).class_name("Principal").optional }
it { is_expected.to belong_to(:responsible).class_name("Principal").optional }
it { is_expected.to belong_to(:version).optional }
+ it { is_expected.to belong_to(:life_cycle).class_name("Projects::LifeCycle").optional }
it { is_expected.to belong_to(:priority).class_name("IssuePriority") }
it { is_expected.to belong_to(:category).optional }
it { is_expected.to have_many(:time_entries).dependent(:delete_all) }
diff --git a/spec/support/shared/projects_life_cycle_helpers.rb b/spec/support/shared/projects_life_cycle_helpers.rb
new file mode 100644
index 00000000000..71407a3792b
--- /dev/null
+++ b/spec/support/shared/projects_life_cycle_helpers.rb
@@ -0,0 +1,46 @@
+#-- 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.
+#++
+
+RSpec.shared_examples_for "a Projects::LifeCycle event" do
+ it "inherits from Projects::LifeCycle" do
+ expect(described_class < Projects::LifeCycle).to be true
+ end
+
+ describe "validations" do
+ it { is_expected.to belong_to(:project) }
+ it { is_expected.to have_many(:work_packages) }
+ it { is_expected.to validate_presence_of(:name) }
+
+ it "is invalid if type is not Stage or Gate" do
+ life_cycle = described_class.new
+ life_cycle.type = "InvalidType"
+ expect(life_cycle).not_to be_valid
+ expect(life_cycle.errors[:type]).to include("must be either Stage or Gate")
+ end
+ end
+end