diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-14 15:08:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-14 15:08:21 +0300 |
commit | 674e7e2c3d295704bdf504dd0caa2e5a2d9b5cd2 (patch) | |
tree | 7454890d4f7aa8644c9e89954a978466e4416815 /app/models/iteration.rb | |
parent | c7ad2610df033b370845995ac3bbe269a191d9bb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/iteration.rb')
-rw-r--r-- | app/models/iteration.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/iteration.rb b/app/models/iteration.rb new file mode 100644 index 00000000000..630d25d3ec5 --- /dev/null +++ b/app/models/iteration.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class Iteration < ApplicationRecord + include Timebox + + self.table_name = 'sprints' + + STATE_ID_MAP = { + active: 1, + closed: 2 + }.with_indifferent_access.freeze + + include AtomicInternalId + + has_many :issues, foreign_key: 'sprint_id' + has_many :merge_requests, foreign_key: 'sprint_id' + + belongs_to :project + belongs_to :group + + has_internal_id :iid, scope: :project, init: ->(s) { s&.project&.iterations&.maximum(:iid) } + has_internal_id :iid, scope: :group, init: ->(s) { s&.group&.iterations&.maximum(:iid) } + + state_machine :state, initial: :active do + event :close do + transition active: :closed + end + + event :activate do + transition closed: :active + end + + state :active, value: Iteration::STATE_ID_MAP[:active] + state :closed, value: Iteration::STATE_ID_MAP[:closed] + end +end |