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

Remove Project#life_cycles association, remove Project::LifeCycle#date database field and use start_date instead.

Dombi Attila0885c1d3511e
diff --git a/app/models/project.rb b/app/models/project.rb
index 0893018a0ba..7799b0ed094 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -87,7 +87,6 @@ class Project < ApplicationRecord
has_many :project_storages, dependent: :destroy, class_name: "Storages::ProjectStorage"
has_many :storages, through: :project_storages
has_many :project_life_cycles, class_name: "Project::LifeCycle", dependent: :destroy
- has_many :life_cycles, through: :project_life_cycles
store_attribute :settings, :deactivate_work_package_attachments, :boolean
diff --git a/app/models/project/gate.rb b/app/models/project/gate.rb
index 1aef0ec5464..211001e2740 100644
--- a/app/models/project/gate.rb
+++ b/app/models/project/gate.rb
@@ -27,12 +27,14 @@
#++
class Project::Gate < Project::LifeCycle
+ alias_attribute :date, :start_date
+
validates :date, presence: true
- validate :validate_restricted_attributes
+ validate :end_date_not_allowed
- def validate_restricted_attributes
- if start_date.present? || end_date.present?
- errors.add(:base, :date_range_not_allowed)
+ def end_date_not_allowed
+ if end_date.present?
+ errors.add(:base, :end_date_not_allowed)
end
end
end
diff --git a/app/models/project/stage.rb b/app/models/project/stage.rb
index 31a82be13ff..afd6090a067 100644
--- a/app/models/project/stage.rb
+++ b/app/models/project/stage.rb
@@ -28,11 +28,4 @@
class Project::Stage < Project::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/config/locales/en.yml b/config/locales/en.yml
index 290f07d11ff..b1286e98254 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1121,11 +1121,7 @@ en:
project/gate:
attributes:
base:
- date_range_not_allowed: "Cannot assign `start_date` or `end_date` to a Gate"
- project/stage:
- attributes:
- base:
- date_not_allowed: "Cannot assign `date` to a Stage"
+ end_date_not_allowed: "Cannot assign `end_date` to a Gate"
query:
attributes:
project:
diff --git a/db/migrate/20241105151352_create_project_life_cycles.rb b/db/migrate/20241105151352_create_project_life_cycles.rb
index e5576093b07..3aab5365def 100644
--- a/db/migrate/20241105151352_create_project_life_cycles.rb
+++ b/db/migrate/20241105151352_create_project_life_cycles.rb
@@ -4,7 +4,6 @@ class CreateProjectLifeCycles < ActiveRecord::Migration[7.1]
t.string :type
t.date :start_date
t.date :end_date
- t.date :date
t.references :project, foreign_key: true
t.references :life_cycle, foreign_key: true
diff --git a/spec/models/project/gate_spec.rb b/spec/models/project/gate_spec.rb
index b4408cd86bc..49a594e78e1 100644
--- a/spec/models/project/gate_spec.rb
+++ b/spec/models/project/gate_spec.rb
@@ -35,21 +35,14 @@ RSpec.describe Project::Gate do
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")
+ expect(gate_with_end_date.errors[:base]).to include("Cannot assign `end_date` to a Gate")
end
- it "is valid if neither `start_date` nor `end_date` are present" do
+ it "is valid if `end_date` is not present" do
valid_gate = build(:project_gate)
expect(valid_gate).to be_valid
end
diff --git a/spec/models/project/stage_spec.rb b/spec/models/project/stage_spec.rb
index 6e2ac4f2ee6..35b8231ed08 100644
--- a/spec/models/project/stage_spec.rb
+++ b/spec/models/project/stage_spec.rb
@@ -40,12 +40,5 @@ RSpec.describe Project::Stage 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/project_spec.rb b/spec/models/project_spec.rb
index 01e21868959..57cce3c2cce 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -383,7 +383,6 @@ RSpec.describe Project do
describe "life_cycles" do
it { is_expected.to have_many(:project_life_cycles).class_name("Project::LifeCycle").dependent(:destroy) }
- it { is_expected.to have_many(:life_cycles).through(:project_life_cycles) }
end
describe "#enabled_module_names=", with_settings: { default_projects_modules: %w(work_package_tracking repository) } do