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 class Projects::MilestonesController < Projects::ApplicationController
include Gitlab::Utils::StrongMemoize
include MilestoneActions include MilestoneActions
before_action :check_issuables_available! before_action :check_issuables_available!
...@@ -103,7 +104,7 @@ class Projects::MilestonesController < Projects::ApplicationController ...@@ -103,7 +104,7 @@ class Projects::MilestonesController < Projects::ApplicationController
protected protected
def milestones def milestones
@milestones ||= begin strong_memoize(:milestones) do
MilestonesFinder.new(search_params).execute MilestonesFinder.new(search_params).execute
end end
end end
...@@ -121,10 +122,10 @@ class Projects::MilestonesController < Projects::ApplicationController ...@@ -121,10 +122,10 @@ class Projects::MilestonesController < Projects::ApplicationController
end end
def search_params def search_params
if @project.group && can?(current_user, :read_group, @project.group) if request.format.json? && @project.group && can?(current_user, :read_group, @project.group)
group = @project.group groups = @project.group.self_and_ancestors
end 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
end end
...@@ -11,7 +11,7 @@ module Projects ...@@ -11,7 +11,7 @@ module Projects
order: { due_date: :asc, title: :asc } 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]) MilestonesFinder.new(finder_params).execute.select([:iid, :title])
end 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 ...@@ -57,8 +57,8 @@ describe Projects::MilestonesController do
context "as json" do context "as json" do
let!(:group) { create(:group, :public) } let!(:group) { create(:group, :public) }
let!(:group_milestone) { create(:milestone, group: group) } 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 before do
project.update(namespace: group) project.update(namespace: group)
get :index, namespace_id: project.namespace.id, project_id: project.id, format: :json get :index, namespace_id: project.namespace.id, project_id: project.id, format: :json
...@@ -68,8 +68,25 @@ describe Projects::MilestonesController do ...@@ -68,8 +68,25 @@ describe Projects::MilestonesController do
milestones = assigns(:milestones) milestones = assigns(:milestones)
expect(milestones.count).to eq(2) expect(milestones.count).to eq(2)
expect(milestones.where(project_id: nil).first).to eq(group_milestone) expect(milestones).to match_array([milestone, group_milestone])
expect(milestones.where(group_id: nil).first).to eq(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 end
end end
......
...@@ -115,5 +115,20 @@ describe Projects::AutocompleteService do ...@@ -115,5 +115,20 @@ describe Projects::AutocompleteService do
expect(milestone_titles).to eq([group_milestone2.title, group_milestone1.title]) expect(milestone_titles).to eq([group_milestone2.title, group_milestone1.title])
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)
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
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