Merge branch '36862-subgroup-milestones' into 'master'
Include all ancestors milestones in json list & autocomplete Closes #36862 See merge request gitlab-org/gitlab-ce!19317
This commit is contained in:
commit
fb3f95bcaf
5 changed files with 52 additions and 14 deletions
|
@ -1,4 +1,5 @@
|
|||
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
|
||||
|
|
5
changelogs/unreleased/36862-subgroup-milestones.yml
Normal file
5
changelogs/unreleased/36862-subgroup-milestones.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Include milestones from parent groups when assigning a milestone to an issue or merge request
|
||||
merge_request:
|
||||
author:
|
||||
type: changed
|
|
@ -57,19 +57,36 @@ 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) }
|
||||
|
||||
before do
|
||||
project.update(namespace: group)
|
||||
get :index, namespace_id: project.namespace.id, project_id: project.id, format: :json
|
||||
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
|
||||
end
|
||||
|
||||
it "queries projects milestones and groups milestones" do
|
||||
milestones = assigns(:milestones)
|
||||
|
||||
expect(milestones.count).to eq(2)
|
||||
expect(milestones).to match_array([milestone, group_milestone])
|
||||
end
|
||||
end
|
||||
|
||||
it "queries projects milestones and groups milestones" do
|
||||
milestones = assigns(:milestones)
|
||||
context 'with nested groups', :nested_groups do
|
||||
let!(:subgroup) { create(:group, :public, parent: group) }
|
||||
let!(:subgroup_milestone) { create(:milestone, group: subgroup) }
|
||||
|
||||
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)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue