summaryrefslogtreecommitdiff
path: root/app/models/group_milestone.rb
blob: 60e97174e5080e5964545fea575f22f44afacdb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
# Group Milestones are milestones that can be shared among many projects within the same group
class GroupMilestone < GlobalMilestone
  attr_reader :group, :milestones

  def self.build_collection(group, projects, params)
    params =
      { state: params[:state], search_title: params[:search_title] }

    project_milestones = Milestone.of_projects(projects)
    project_milestones = project_milestones.search_title(params[:search_title]) if params[:search_title].present?
    child_milestones = Milestone.filter_by_state(project_milestones, params[:state])
    grouped_milestones = child_milestones.group_by(&:title)

    grouped_milestones.map do |title, grouped|
      new(title, grouped, group)
    end
  end

  def self.build(group, projects, title)
    child_milestones = Milestone.of_projects(projects).where(title: title)
    return if child_milestones.blank?

    new(title, child_milestones, group)
  end

  def initialize(title, milestones, group)
    @milestones = milestones
    @group = group
  end

  def milestone
    @milestone ||= milestones.find { |m| m.description.present? } || milestones.first
  end

  def issues_finder_params
    { group_id: group.id }
  end

  def legacy_group_milestone?
    true
  end

  def merge_requests_enabled?
    true
  end
end

GroupMilestone.include_if_ee('::EE::GroupMilestone')