Commit 1f5032ef authored by Phil Hughes's avatar Phil Hughes

Merge branch '47735-milestone-regression' into 'master'

Resolve "Regressions for assigning group milestone from ancestor"

Closes #47735

See merge request gitlab-org/gitlab-ce!19721
parents a66af9b1 379a6a70
...@@ -56,7 +56,7 @@ export default class MilestoneSelect { ...@@ -56,7 +56,7 @@ export default class MilestoneSelect {
if (issueUpdateURL) { if (issueUpdateURL) {
milestoneLinkTemplate = _.template( milestoneLinkTemplate = _.template(
'<a href="/<%- full_path %>/milestones/<%- iid %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>', '<a href="<%- web_url %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>',
); );
milestoneLinkNoneTemplate = '<span class="no-value">None</span>'; milestoneLinkNoneTemplate = '<span class="no-value">None</span>';
} }
......
...@@ -416,6 +416,10 @@ module API ...@@ -416,6 +416,10 @@ module API
expose :state, :created_at, :updated_at expose :state, :created_at, :updated_at
expose :due_date expose :due_date
expose :start_date expose :start_date
expose :web_url do |milestone, _options|
Gitlab::UrlBuilder.build(milestone)
end
end end
class IssueBasic < ProjectEntity class IssueBasic < ProjectEntity
......
...@@ -65,7 +65,7 @@ module Banzai ...@@ -65,7 +65,7 @@ module Banzai
# We don't support IID lookups for group milestones, because IIDs can # We don't support IID lookups for group milestones, because IIDs can
# clash between group and project milestones. # clash between group and project milestones.
if project.group && !params[:iid] if project.group && !params[:iid]
finder_params[:group_ids] = [project.group.id] finder_params[:group_ids] = project.group.self_and_ancestors.select(:id)
end end
MilestonesFinder.new(finder_params).find_by(params) MilestonesFinder.new(finder_params).find_by(params)
......
...@@ -26,6 +26,8 @@ module Gitlab ...@@ -26,6 +26,8 @@ module Gitlab
project_snippet_url(object.project, object) project_snippet_url(object.project, object)
when Snippet when Snippet
snippet_url(object) snippet_url(object)
when Milestone
milestone_url(object)
else else
raise NotImplementedError.new("No URL builder defined for #{object.class}") raise NotImplementedError.new("No URL builder defined for #{object.class}")
end end
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
"created_at": { "type": "date" }, "created_at": { "type": "date" },
"updated_at": { "type": "date" }, "updated_at": { "type": "date" },
"start_date": { "type": "date" }, "start_date": { "type": "date" },
"due_date": { "type": "date" } "due_date": { "type": "date" },
"web_url": { "type": "string" }
}, },
"required": [ "required": [
"id", "iid", "title", "description", "state", "id", "iid", "title", "description", "state",
......
...@@ -3,7 +3,8 @@ require 'spec_helper' ...@@ -3,7 +3,8 @@ require 'spec_helper'
describe Banzai::Filter::MilestoneReferenceFilter do describe Banzai::Filter::MilestoneReferenceFilter do
include FilterSpecHelper include FilterSpecHelper
let(:group) { create(:group, :public) } let(:parent_group) { create(:group, :public) }
let(:group) { create(:group, :public, parent: parent_group) }
let(:project) { create(:project, :public, group: group) } let(:project) { create(:project, :public, group: group) }
it 'requires project context' do it 'requires project context' do
...@@ -340,6 +341,13 @@ describe Banzai::Filter::MilestoneReferenceFilter do ...@@ -340,6 +341,13 @@ describe Banzai::Filter::MilestoneReferenceFilter do
expect(doc.css('a')).to be_empty expect(doc.css('a')).to be_empty
end end
it 'supports parent group references', :nested_groups do
milestone.update!(group: parent_group)
doc = reference_filter("See #{reference}")
expect(doc.css('a').first.text).to eq(milestone.name)
end
end end
context 'group context' do context 'group context' do
......
...@@ -22,6 +22,31 @@ describe Gitlab::UrlBuilder do ...@@ -22,6 +22,31 @@ describe Gitlab::UrlBuilder do
end end
end end
context 'when passing a Milestone' do
let(:group) { create(:group) }
let(:project) { create(:project, :public, namespace: group) }
context 'belonging to a project' do
it 'returns a proper URL' do
milestone = create(:milestone, project: project)
url = described_class.build(milestone)
expect(url).to eq "#{Settings.gitlab['url']}/#{milestone.project.full_path}/milestones/#{milestone.iid}"
end
end
context 'belonging to a group' do
it 'returns a proper URL' do
milestone = create(:milestone, group: group)
url = described_class.build(milestone)
expect(url).to eq "#{Settings.gitlab['url']}/groups/#{milestone.group.full_path}/-/milestones/#{milestone.iid}"
end
end
end
context 'when passing a MergeRequest' do context 'when passing a MergeRequest' do
it 'returns a proper URL' do it 'returns a proper URL' do
merge_request = build_stubbed(:merge_request, iid: 42) merge_request = build_stubbed(:merge_request, iid: 42)
......
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