Commit e580c226 authored by Chantal Rollison's avatar Chantal Rollison

Filter group milestones based on user membership

parent c7d1eef6
......@@ -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
......
......@@ -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?
......
---
title: Filter group milestones based on user membership.
merge_request: 21660
author:
type: fixed
......@@ -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
......@@ -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
......
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