Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/iteration.rb')
-rw-r--r--app/models/iteration.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/iteration.rb b/app/models/iteration.rb
index 7a35bb1cd1f..012a062712f 100644
--- a/app/models/iteration.rb
+++ b/app/models/iteration.rb
@@ -16,6 +16,7 @@ class Iteration < ApplicationRecord
belongs_to :project
belongs_to :group
+ belongs_to :iterations_cadence, class_name: 'Iterations::Cadence', foreign_key: :iterations_cadence_id, inverse_of: :iterations
has_internal_id :iid, scope: :project
has_internal_id :iid, scope: :group
@@ -26,6 +27,9 @@ class Iteration < ApplicationRecord
validate :dates_do_not_overlap, if: :start_or_due_dates_changed?
validate :future_date, if: :start_or_due_dates_changed?, unless: :skip_future_date_validation
validate :no_project, unless: :skip_project_validation
+ validate :validate_group
+
+ before_create :set_iterations_cadence
scope :upcoming, -> { with_state(:upcoming) }
scope :started, -> { with_state(:started) }
@@ -135,6 +139,30 @@ class Iteration < ApplicationRecord
errors.add(:project_id, s_("is not allowed. We do not currently support project-level iterations"))
end
+
+ # TODO: this method should be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/296099
+ def set_iterations_cadence
+ return if iterations_cadence
+ # For now we support only group iterations
+ # issue to clarify project iterations: https://gitlab.com/gitlab-org/gitlab/-/issues/299864
+ return unless group
+
+ self.iterations_cadence = group.iterations_cadences.first || create_default_cadence
+ end
+
+ def create_default_cadence
+ cadence_title = "#{group.name} Iterations"
+
+ Iterations::Cadence.create!(group: group, title: cadence_title, start_date: start_date)
+ end
+
+ # TODO: remove this as part of https://gitlab.com/gitlab-org/gitlab/-/issues/296100
+ def validate_group
+ return unless iterations_cadence
+ return if iterations_cadence.group_id == group_id
+
+ errors.add(:group, s_('is not valid. The iteration group has to match the iteration cadence group.'))
+ end
end
Iteration.prepend_if_ee('EE::Iteration')