Commit 90aae02b authored by Chantal Rollison's avatar Chantal Rollison Committed by Kamil Trzciński

Add group milestones to dashboard milestone page

parent c4be8de7
...@@ -21,8 +21,19 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController ...@@ -21,8 +21,19 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController
private 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 def milestones
@milestones = DashboardMilestone.build_collection(@projects, params) @milestones = group_milestones + dynamic_milestones
end end
def milestone def milestone
......
...@@ -233,4 +233,12 @@ module MilestonesHelper ...@@ -233,4 +233,12 @@ module MilestonesHelper
group_milestone_path(@group, milestone.iid, milestone: params) group_milestone_path(@group, milestone.iid, milestone: params)
end end
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 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 # frozen_string_literal: true
# Global Milestones are milestones that can be shared across multiple projects
class GlobalMilestone class GlobalMilestone
include Milestoneish include Milestoneish
......
# frozen_string_literal: true # frozen_string_literal: true
# Group Milestones are milestones that can be shared among many projects within the same group
class GroupMilestone < GlobalMilestone class GroupMilestone < GlobalMilestone
attr_accessor :group attr_accessor :group
......
= render 'shared/milestones/milestone', = 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), issues_path: issues_dashboard_path(milestone_title: milestone.title),
merge_requests_path: merge_requests_dashboard_path(milestone_title: milestone.title), merge_requests_path: merge_requests_dashboard_path(milestone_title: milestone.title),
milestone: milestone, 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' ...@@ -2,8 +2,10 @@ require 'spec_helper'
describe Dashboard::MilestonesController do describe Dashboard::MilestonesController do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:group) { create(:group) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project_milestone) { create(:milestone, project: project) } let(:project_milestone) { create(:milestone, project: project) }
let(:group_milestone) { create(:milestone, group: group) }
let(:milestone) do let(:milestone) do
DashboardMilestone.build( DashboardMilestone.build(
[project], [project],
...@@ -11,13 +13,17 @@ describe Dashboard::MilestonesController do ...@@ -11,13 +13,17 @@ describe Dashboard::MilestonesController do
) )
end end
let(:issue) { create(:issue, project: project, milestone: project_milestone) } 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!(: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!(: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) } let(:milestone_path) { dashboard_milestone_path(milestone.safe_title, title: milestone.title) }
before do before do
sign_in(user) sign_in(user)
project.add_maintainer(user) project.add_maintainer(user)
group.add_developer(user)
end end
it_behaves_like 'milestone tabs' it_behaves_like 'milestone tabs'
...@@ -35,4 +41,15 @@ describe Dashboard::MilestonesController do ...@@ -35,4 +41,15 @@ describe Dashboard::MilestonesController do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
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 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