Commit da17a051 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'wolf/feat/milestone-hide-mr' into 'master'

Hide MRs in milestones when they're disabled

See merge request gitlab-org/gitlab!20985
parents 313d08e5 be69dc7d
...@@ -22,4 +22,8 @@ class DashboardGroupMilestone < GlobalMilestone ...@@ -22,4 +22,8 @@ class DashboardGroupMilestone < GlobalMilestone
def dashboard_milestone? def dashboard_milestone?
true true
end end
def merge_requests_enabled?
true
end
end end
...@@ -12,4 +12,8 @@ class DashboardMilestone < GlobalMilestone ...@@ -12,4 +12,8 @@ class DashboardMilestone < GlobalMilestone
def project_milestone? def project_milestone?
true true
end end
def merge_requests_enabled?
project.merge_requests_enabled?
end
end end
...@@ -41,4 +41,8 @@ class GroupMilestone < GlobalMilestone ...@@ -41,4 +41,8 @@ class GroupMilestone < GlobalMilestone
def legacy_group_milestone? def legacy_group_milestone?
true true
end end
def merge_requests_enabled?
true
end
end end
...@@ -274,6 +274,16 @@ class Milestone < ApplicationRecord ...@@ -274,6 +274,16 @@ class Milestone < ApplicationRecord
project_id.present? project_id.present?
end end
def merge_requests_enabled?
if group_milestone?
# Assume that groups have at least one project with merge requests enabled.
# Otherwise, we would need to load all of the projects from the database.
true
elsif project_milestone?
project&.merge_requests_enabled?
end
end
private private
# Milestone titles must be unique across project milestones and group milestones # Milestone titles must be unique across project milestones and group milestones
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
.col-sm-4.milestone-progress .col-sm-4.milestone-progress
= milestone_progress_bar(milestone) = milestone_progress_bar(milestone)
= link_to pluralize(milestone.total_issues_count(current_user), 'Issue'), issues_path = link_to pluralize(milestone.total_issues_count(current_user), 'Issue'), issues_path
- if milestone.merge_requests_enabled?
&middot; &middot;
= link_to pluralize(milestone.merge_requests_visible_to_user(current_user).size, 'Merge Request'), merge_requests_path = link_to pluralize(milestone.merge_requests_visible_to_user(current_user).size, 'Merge Request'), merge_requests_path
.float-lg-right.light #{milestone.percent_complete(current_user)}% complete .float-lg-right.light #{milestone.percent_complete(current_user)}% complete
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
= render_if_exists 'shared/milestones/weight', milestone: milestone = render_if_exists 'shared/milestones/weight', milestone: milestone
- if milestone.merge_requests_enabled?
.block.merge-requests .block.merge-requests
.sidebar-collapsed-icon.has-tooltip{ title: milestone_merge_requests_tooltip_text(milestone), data: { container: 'body', html: 'true', placement: 'left', boundary: 'viewport' } } .sidebar-collapsed-icon.has-tooltip{ title: milestone_merge_requests_tooltip_text(milestone), data: { container: 'body', html: 'true', placement: 'left', boundary: 'viewport' } }
%strong %strong
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
= link_to '#tab-issues', class: 'nav-link active', data: { toggle: 'tab', show: '.tab-issues-buttons' } do = link_to '#tab-issues', class: 'nav-link active', data: { toggle: 'tab', show: '.tab-issues-buttons' } do
= _('Issues') = _('Issues')
%span.badge.badge-pill= milestone.issues_visible_to_user(current_user).size %span.badge.badge-pill= milestone.issues_visible_to_user(current_user).size
- if milestone.merge_requests_enabled?
%li.nav-item %li.nav-item
= link_to '#tab-merge-requests', class: 'nav-link', data: { toggle: 'tab', endpoint: milestone_tab_path(milestone, 'merge_requests') } do = link_to '#tab-merge-requests', class: 'nav-link', data: { toggle: 'tab', endpoint: milestone_tab_path(milestone, 'merge_requests') } do
= _('Merge Requests') = _('Merge Requests')
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
.tab-content.milestone-content .tab-content.milestone-content
.tab-pane.active#tab-issues{ data: { sort_endpoint: (sort_issues_project_milestone_path(@project, @milestone) if @project && current_user) } } .tab-pane.active#tab-issues{ data: { sort_endpoint: (sort_issues_project_milestone_path(@project, @milestone) if @project && current_user) } }
= render 'shared/milestones/issues_tab', issues: issues, show_project_name: show_project_name, show_full_project_name: show_full_project_name = render 'shared/milestones/issues_tab', issues: issues, show_project_name: show_project_name, show_full_project_name: show_full_project_name
- if milestone.merge_requests_enabled?
.tab-pane#tab-merge-requests .tab-pane#tab-merge-requests
-# loaded async -# loaded async
= render "shared/milestones/tab_loading" = render "shared/milestones/tab_loading"
......
---
title: Hide Merge Request information on milestones when MRs are disabled for project
merge_request: 20985
author: Wolfgang Faust
type: changed
...@@ -30,6 +30,7 @@ describe 'Dashboard > Milestones' do ...@@ -30,6 +30,7 @@ describe 'Dashboard > Milestones' do
expect(current_path).to eq dashboard_milestones_path expect(current_path).to eq dashboard_milestones_path
expect(page).to have_content(milestone.title) expect(page).to have_content(milestone.title)
expect(page).to have_content(group.name) expect(page).to have_content(group.name)
expect(first('.milestone')).to have_content('Merge Requests')
end end
describe 'new milestones dropdown', :js do describe 'new milestones dropdown', :js do
...@@ -46,4 +47,23 @@ describe 'Dashboard > Milestones' do ...@@ -46,4 +47,23 @@ describe 'Dashboard > Milestones' do
end end
end end
end end
describe 'with merge requests disabled' do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, :merge_requests_disabled, namespace: user.namespace) }
let!(:milestone) { create(:milestone, project: project) }
before do
group.add_developer(user)
sign_in(user)
visit dashboard_milestones_path
end
it 'does not see milestones' do
expect(current_path).to eq dashboard_milestones_path
expect(page).to have_content(milestone.title)
expect(first('.milestone')).to have_no_content('Merge Requests')
end
end
end end
...@@ -18,6 +18,7 @@ describe "User views milestones" do ...@@ -18,6 +18,7 @@ describe "User views milestones" do
expect(page).to have_content(milestone.title) expect(page).to have_content(milestone.title)
.and have_content(milestone.expires_at) .and have_content(milestone.expires_at)
.and have_content("Issues") .and have_content("Issues")
.and have_content("Merge Requests")
end end
context "with issues" do context "with issues" do
...@@ -32,6 +33,7 @@ describe "User views milestones" do ...@@ -32,6 +33,7 @@ describe "User views milestones" do
.and have_selector("#tab-issues li.issuable-row", count: 2) .and have_selector("#tab-issues li.issuable-row", count: 2)
.and have_content(issue.title) .and have_content(issue.title)
.and have_content(closed_issue.title) .and have_content(closed_issue.title)
.and have_selector("#tab-merge-requests")
end end
end end
...@@ -62,3 +64,32 @@ describe "User views milestones" do ...@@ -62,3 +64,32 @@ describe "User views milestones" do
end end
end end
end end
describe "User views milestones with no MR" do
set(:user) { create(:user) }
set(:project) { create(:project, :merge_requests_disabled) }
set(:milestone) { create(:milestone, project: project) }
before do
project.add_developer(user)
sign_in(user)
visit(project_milestones_path(project))
end
it "shows milestone" do
expect(page).to have_content(milestone.title)
.and have_content(milestone.expires_at)
.and have_content("Issues")
.and have_no_content("Merge Requests")
end
it "opens milestone" do
click_link(milestone.title)
expect(current_path).to eq(project_milestone_path(project, milestone))
expect(page).to have_content(milestone.title)
.and have_selector("#tab-issues")
.and have_no_selector("#tab-merge-requests")
end
end
...@@ -106,6 +106,40 @@ describe Milestone do ...@@ -106,6 +106,40 @@ describe Milestone do
end end
end end
describe '#merge_requests_enabled?' do
context "per project" do
it "is true for projects with MRs enabled" do
project = create(:project, :merge_requests_enabled)
milestone = create(:milestone, project: project)
expect(milestone.merge_requests_enabled?).to be(true)
end
it "is false for projects with MRs disabled" do
project = create(:project, :repository_enabled, :merge_requests_disabled)
milestone = create(:milestone, project: project)
expect(milestone.merge_requests_enabled?).to be(false)
end
it "is false for projects with repository disabled" do
project = create(:project, :repository_disabled)
milestone = create(:milestone, project: project)
expect(milestone.merge_requests_enabled?).to be(false)
end
end
context "per group" do
let(:group) { create(:group) }
let(:milestone) { create(:milestone, group: group) }
it "is always true for groups, for performance reasons" do
expect(milestone.merge_requests_enabled?).to be(true)
end
end
end
describe "unique milestone title" do describe "unique milestone title" do
context "per project" do context "per project" do
it "does not accept the same title in a project twice" do it "does not accept the same title in a project twice" do
......
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