Commit 6426b507 authored by Jarka Kadlecová's avatar Jarka Kadlecová

Include all ancestors milestones in json list & autocomplete

parent 50fda506
class Projects::MilestonesController < Projects::ApplicationController
include Gitlab::Utils::StrongMemoize
include MilestoneActions
before_action :check_issuables_available!
......@@ -103,7 +104,7 @@ class Projects::MilestonesController < Projects::ApplicationController
protected
def milestones
@milestones ||= begin
strong_memoize(:milestones) do
MilestonesFinder.new(search_params).execute
end
end
......@@ -121,10 +122,10 @@ class Projects::MilestonesController < Projects::ApplicationController
end
def search_params
if @project.group && can?(current_user, :read_group, @project.group)
group = @project.group
if request.format.json? && @project.group && can?(current_user, :read_group, @project.group)
groups = @project.group.self_and_ancestors
end
params.permit(:state).merge(project_ids: @project.id, group_ids: group&.id)
params.permit(:state).merge(project_ids: @project.id, group_ids: groups&.select(:id))
end
end
......@@ -11,7 +11,7 @@ module Projects
order: { due_date: :asc, title: :asc }
}
finder_params[:group_ids] = [@project.group.id] if @project.group
finder_params[:group_ids] = @project.group.self_and_ancestors.select(:id) if @project.group
MilestonesFinder.new(finder_params).execute.select([:iid, :title])
end
......
---
title: Include milestones from parent groups when assigning a milestone to an issue or merge request
merge_request:
author:
type: changed
......@@ -57,8 +57,8 @@ describe Projects::MilestonesController do
context "as json" do
let!(:group) { create(:group, :public) }
let!(:group_milestone) { create(:milestone, group: group) }
let!(:group_member) { create(:group_member, group: group, user: user) }
context 'with a single group ancestor' do
before do
project.update(namespace: group)
get :index, namespace_id: project.namespace.id, project_id: project.id, format: :json
......@@ -68,8 +68,25 @@ describe Projects::MilestonesController do
milestones = assigns(:milestones)
expect(milestones.count).to eq(2)
expect(milestones.where(project_id: nil).first).to eq(group_milestone)
expect(milestones.where(group_id: nil).first).to eq(milestone)
expect(milestones).to match_array([milestone, group_milestone])
end
end
context 'with nested groups', :nested_groups do
let!(:subgroup) { create(:group, :public, parent: group) }
let!(:subgroup_milestone) { create(:milestone, group: subgroup) }
before do
project.update(namespace: subgroup)
get :index, namespace_id: project.namespace.id, project_id: project.id, format: :json
end
it "queries projects milestones and all ancestors milestones" do
milestones = assigns(:milestones)
expect(milestones.count).to eq(3)
expect(milestones).to match_array([milestone, group_milestone, subgroup_milestone])
end
end
end
end
......
......@@ -115,5 +115,20 @@ describe Projects::AutocompleteService do
expect(milestone_titles).to eq([group_milestone2.title, group_milestone1.title])
end
context 'with nested groups', :nested_groups do
let(:subgroup) { create(:group, :public, parent: group) }
let!(:subgroup_milestone) { create(:milestone, group: subgroup) }
before do
project.update(namespace: subgroup)
end
it 'includes project milestones and all acestors milestones' do
expect(milestone_titles).to match_array(
[project_milestone.title, group_milestone2.title, group_milestone1.title, subgroup_milestone.title]
)
end
end
end
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