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,8 +43,9 @@ ...@@ -43,8 +43,9 @@
.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
&middot; - if milestone.merge_requests_enabled?
= link_to pluralize(milestone.merge_requests_visible_to_user(current_user).size, 'Merge Request'), merge_requests_path &middot;
= 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
.col-sm-2 .col-sm-2
.milestone-actions.d-flex.justify-content-sm-start.justify-content-md-end .milestone-actions.d-flex.justify-content-sm-start.justify-content-md-end
......
...@@ -105,38 +105,39 @@ ...@@ -105,38 +105,39 @@
= render_if_exists 'shared/milestones/weight', milestone: milestone = render_if_exists 'shared/milestones/weight', milestone: milestone
.block.merge-requests - if milestone.merge_requests_enabled?
.sidebar-collapsed-icon.has-tooltip{ title: milestone_merge_requests_tooltip_text(milestone), data: { container: 'body', html: 'true', placement: 'left', boundary: 'viewport' } } .block.merge-requests
%strong .sidebar-collapsed-icon.has-tooltip{ title: milestone_merge_requests_tooltip_text(milestone), data: { container: 'body', html: 'true', placement: 'left', boundary: 'viewport' } }
= custom_icon('mr_bold') %strong
%span= milestone.merge_requests.count = custom_icon('mr_bold')
.title.hide-collapsed %span= milestone.merge_requests.count
Merge requests .title.hide-collapsed
%span.badge.badge-pill= milestone.merge_requests.count Merge requests
.value.hide-collapsed.bold %span.badge.badge-pill= milestone.merge_requests.count
- if !project || can?(current_user, :read_merge_request, project) .value.hide-collapsed.bold
%span.milestone-stat - if !project || can?(current_user, :read_merge_request, project)
= link_to milestones_browse_issuables_path(milestone, type: :merge_requests) do %span.milestone-stat
= link_to milestones_browse_issuables_path(milestone, type: :merge_requests) do
Open:
= milestone.merge_requests.opened.count
%span.milestone-stat
= link_to milestones_browse_issuables_path(milestone, type: :merge_requests, state: 'closed') do
Closed:
= milestone.merge_requests.closed.count
%span.milestone-stat
= link_to milestones_browse_issuables_path(milestone, type: :merge_requests, state: 'merged') do
Merged:
= milestone.merge_requests.merged.count
- else
%span.milestone-stat
Open: Open:
= milestone.merge_requests.opened.count = milestone.merge_requests.opened.count
%span.milestone-stat %span.milestone-stat
= link_to milestones_browse_issuables_path(milestone, type: :merge_requests, state: 'closed') do
Closed: Closed:
= milestone.merge_requests.closed.count = milestone.merge_requests.closed.count
%span.milestone-stat %span.milestone-stat
= link_to milestones_browse_issuables_path(milestone, type: :merge_requests, state: 'merged') do
Merged: Merged:
= milestone.merge_requests.merged.count = milestone.merge_requests.merged.count
- else
%span.milestone-stat
Open:
= milestone.merge_requests.opened.count
%span.milestone-stat
Closed:
= milestone.merge_requests.closed.count
%span.milestone-stat
Merged:
= milestone.merge_requests.merged.count
- if project - if project
- recent_releases, total_count, more_count = recent_releases_with_counts(milestone) - recent_releases, total_count, more_count = recent_releases_with_counts(milestone)
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
= 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
%li.nav-item - if milestone.merge_requests_enabled?
= link_to '#tab-merge-requests', class: 'nav-link', data: { toggle: 'tab', endpoint: milestone_tab_path(milestone, 'merge_requests') } do %li.nav-item
= _('Merge Requests') = link_to '#tab-merge-requests', class: 'nav-link', data: { toggle: 'tab', endpoint: milestone_tab_path(milestone, 'merge_requests') } do
%span.badge.badge-pill= milestone.merge_requests_visible_to_user(current_user).size = _('Merge Requests')
%span.badge.badge-pill= milestone.merge_requests_visible_to_user(current_user).size
%li.nav-item %li.nav-item
= link_to '#tab-participants', class: 'nav-link', data: { toggle: 'tab', endpoint: milestone_tab_path(milestone, 'participants') } do = link_to '#tab-participants', class: 'nav-link', data: { toggle: 'tab', endpoint: milestone_tab_path(milestone, 'participants') } do
= _('Participants') = _('Participants')
...@@ -26,9 +27,10 @@ ...@@ -26,9 +27,10 @@
.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
.tab-pane#tab-merge-requests - if milestone.merge_requests_enabled?
-# loaded async .tab-pane#tab-merge-requests
= render "shared/milestones/tab_loading" -# loaded async
= render "shared/milestones/tab_loading"
.tab-pane#tab-participants .tab-pane#tab-participants
-# 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