Commit d40c5fa0 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ccr/group_milestone_on_dashboard' into 'master'

Add group milestones to dashboard milestone page

Closes #35748

See merge request gitlab-org/gitlab-ce!20618
parents c4be8de7 90aae02b
......@@ -21,8 +21,19 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController
private
def group_milestones
groups = GroupsFinder.new(current_user, all_available: true).execute
DashboardGroupMilestone.build_collection(groups)
end
# See [#39545](https://gitlab.com/gitlab-org/gitlab-ce/issues/39545) for info about the deprecation of dynamic milestones
def dynamic_milestones
DashboardMilestone.build_collection(@projects, params)
end
def milestones
@milestones = DashboardMilestone.build_collection(@projects, params)
@milestones = group_milestones + dynamic_milestones
end
def milestone
......
......@@ -233,4 +233,12 @@ module MilestonesHelper
group_milestone_path(@group, milestone.iid, milestone: params)
end
end
def group_or_dashboard_milestone_path(milestone)
if milestone.group_milestone?
group_milestone_path(milestone.group, milestone.iid, milestone: { title: milestone.title })
else
dashboard_milestone_path(milestone.safe_title, title: milestone.title)
end
end
end
# frozen_string_literal: true
# Dashboard Group Milestones are milestones that allow us to pull more info out for the UI that the Milestone object doesn't allow for
class DashboardGroupMilestone < GlobalMilestone
extend ::Gitlab::Utils::Override
attr_reader :group_name
override :initialize
def initialize(milestone)
super(milestone.title, Array(milestone))
@group_name = milestone.group.full_name
end
def self.build_collection(groups)
MilestonesFinder.new(group_ids: groups.pluck(:id)).execute.map { |m| new(m) }
end
override :group_milestone?
def group_milestone?
@first_milestone.group_milestone?
end
override :milestoneish_ids
def milestoneish_ids
milestones.map(&:id)
end
def group
@first_milestone.group
end
def iid
@first_milestone.iid
end
end
# frozen_string_literal: true
# Global Milestones are milestones that can be shared across multiple projects
class GlobalMilestone
include Milestoneish
......
# frozen_string_literal: true
# Group Milestones are milestones that can be shared among many projects within the same group
class GroupMilestone < GlobalMilestone
attr_accessor :group
......
= render 'shared/milestones/milestone',
milestone_path: dashboard_milestone_path(milestone.safe_title, title: milestone.title),
milestone_path: group_or_dashboard_milestone_path(milestone),
issues_path: issues_dashboard_path(milestone_title: milestone.title),
merge_requests_path: merge_requests_dashboard_path(milestone_title: milestone.title),
milestone: milestone,
......
---
title: Adds the ability to view group milestones on the dashboard milestone page.
merge_request: 20618
author:
type: fixed
---
title: Adds the project and group name to the return type for project and group milestones.
merge_request: 20890
author:
type: changed
......@@ -2,8 +2,10 @@ require 'spec_helper'
describe Dashboard::MilestonesController do
let(:project) { create(:project) }
let(:group) { create(:group) }
let(:user) { create(:user) }
let(:project_milestone) { create(:milestone, project: project) }
let(:group_milestone) { create(:milestone, group: group) }
let(:milestone) do
DashboardMilestone.build(
[project],
......@@ -11,13 +13,17 @@ describe Dashboard::MilestonesController do
)
end
let(:issue) { create(:issue, project: project, milestone: project_milestone) }
let(:group_issue) { create(:issue, milestone: group_milestone) }
let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
let!(:group_label) { create(:group_label, group: group, title: 'Group Issue Label', issues: [group_issue]) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: project_milestone) }
let(:milestone_path) { dashboard_milestone_path(milestone.safe_title, title: milestone.title) }
before do
sign_in(user)
project.add_maintainer(user)
group.add_developer(user)
end
it_behaves_like 'milestone tabs'
......@@ -35,4 +41,15 @@ describe Dashboard::MilestonesController do
expect(response).to have_gitlab_http_status(200)
end
end
describe "#index" do
it 'should contain group and project milestones' do
get :index, format: :json
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(2)
expect(json_response.map { |i| i["first_milestone"]["id"] }).to include(group_milestone.id, project_milestone.id)
expect(json_response.map { |i| i["group_name"] }).to include(group.name)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment