Add group milestones to dashboard milestone page
This commit is contained in:
parent
c4be8de7ad
commit
90aae02bd7
9 changed files with 87 additions and 5 deletions
|
@ -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
|
||||
|
|
36
app/models/dashboard_group_milestone.rb
Normal file
36
app/models/dashboard_group_milestone.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# 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
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Global Milestones are milestones that can be shared across multiple projects
|
||||
class GlobalMilestone
|
||||
include Milestoneish
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# 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
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
= 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,
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Adds the ability to view group milestones on the dashboard milestone page.
|
||||
merge_request: 20618
|
||||
author:
|
||||
type: fixed
|
5
changelogs/unreleased/cr-add-path-of-group-milestone.yml
Normal file
5
changelogs/unreleased/cr-add-path-of-group-milestone.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
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(:user) { create(:user) }
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue