summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChantal Rollison <crollison@gitlab.com>2018-09-10 17:37:21 -0700
committerChantal Rollison <crollison@gitlab.com>2018-09-13 08:08:53 -0700
commite580c2261d12b4542eafba6b5db3b3656d57ed63 (patch)
treea175ed72fc13c64886952424e084f9b32742fcb0
parentc7d1eef671dbf598814a6c2ff1f81b924583ae8a (diff)
downloadgitlab-ce-e580c2261d12b4542eafba6b5db3b3656d57ed63.tar.gz
Filter group milestones based on user membership
-rw-r--r--app/controllers/dashboard/milestones_controller.rb2
-rw-r--r--app/models/dashboard_group_milestone.rb2
-rw-r--r--changelogs/unreleased/ccr-50483_add_filter_for_group_milestones.yml5
-rw-r--r--spec/controllers/dashboard/milestones_controller_spec.rb8
-rw-r--r--spec/features/dashboard/milestones_spec.rb3
5 files changed, 14 insertions, 6 deletions
diff --git a/app/controllers/dashboard/milestones_controller.rb b/app/controllers/dashboard/milestones_controller.rb
index 0469e7e1e1f..78f7f6d4e23 100644
--- a/app/controllers/dashboard/milestones_controller.rb
+++ b/app/controllers/dashboard/milestones_controller.rb
@@ -22,7 +22,7 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController
private
def group_milestones
- groups = GroupsFinder.new(current_user, all_available: true).execute
+ groups = GroupsFinder.new(current_user, all_available: false).execute
DashboardGroupMilestone.build_collection(groups)
end
diff --git a/app/models/dashboard_group_milestone.rb b/app/models/dashboard_group_milestone.rb
index 4e39f60b0d2..067e14dda1c 100644
--- a/app/models/dashboard_group_milestone.rb
+++ b/app/models/dashboard_group_milestone.rb
@@ -13,7 +13,7 @@ class DashboardGroupMilestone < GlobalMilestone
end
def self.build_collection(groups)
- MilestonesFinder.new(group_ids: groups.pluck(:id)).execute.map { |m| new(m) } # rubocop: disable CodeReuse/Finder
+ MilestonesFinder.new(group_ids: groups.select(:id)).execute.map { |m| new(m) } # rubocop: disable CodeReuse/Finder
end
override :group_milestone?
diff --git a/changelogs/unreleased/ccr-50483_add_filter_for_group_milestones.yml b/changelogs/unreleased/ccr-50483_add_filter_for_group_milestones.yml
new file mode 100644
index 00000000000..f8fe50a2c48
--- /dev/null
+++ b/changelogs/unreleased/ccr-50483_add_filter_for_group_milestones.yml
@@ -0,0 +1,5 @@
+---
+title: Filter group milestones based on user membership.
+merge_request: 21660
+author:
+type: fixed
diff --git a/spec/controllers/dashboard/milestones_controller_spec.rb b/spec/controllers/dashboard/milestones_controller_spec.rb
index 505c040b5d5..56047c0c8d2 100644
--- a/spec/controllers/dashboard/milestones_controller_spec.rb
+++ b/spec/controllers/dashboard/milestones_controller_spec.rb
@@ -3,9 +3,11 @@ require 'spec_helper'
describe Dashboard::MilestonesController do
let(:project) { create(:project) }
let(:group) { create(:group) }
+ let(:public_group) { create(:group, :public) }
let(:user) { create(:user) }
let(:project_milestone) { create(:milestone, project: project) }
let(:group_milestone) { create(:milestone, group: group) }
+ let!(:public_milestone) { create(:milestone, group: public_group) }
let(:milestone) do
DashboardMilestone.build(
[project],
@@ -43,13 +45,13 @@ describe Dashboard::MilestonesController do
end
describe "#index" do
- it 'should contain group and project milestones' do
+ it 'returns group and project milestones to which the user belongs' 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)
+ expect(json_response.map { |i| i["first_milestone"]["id"] }).to match_array([group_milestone.id, project_milestone.id])
+ expect(json_response.map { |i| i["group_name"] }.compact).to match_array(group.name)
end
end
end
diff --git a/spec/features/dashboard/milestones_spec.rb b/spec/features/dashboard/milestones_spec.rb
index d9d67788b38..8fb2e37e269 100644
--- a/spec/features/dashboard/milestones_spec.rb
+++ b/spec/features/dashboard/milestones_spec.rb
@@ -17,8 +17,9 @@ describe 'Dashboard > Milestones' do
let(:project) { create(:project, namespace: user.namespace) }
let!(:milestone) { create(:milestone, project: project) }
let!(:milestone2) { create(:milestone, group: group) }
+
before do
- project.add_maintainer(user)
+ group.add_developer(user)
sign_in(user)
visit dashboard_milestones_path
end