Commit 715959e5 authored by Douwe Maan's avatar Douwe Maan

Fix cross-project milestone ref with invalid project

parent ab1734f9
...@@ -17,9 +17,7 @@ module Banzai ...@@ -17,9 +17,7 @@ module Banzai
return super(text, pattern) if pattern != Milestone.reference_pattern return super(text, pattern) if pattern != Milestone.reference_pattern
text.gsub(pattern) do |match| text.gsub(pattern) do |match|
project = project_from_ref($~[:project]) milestone = find_milestone($~[:project], $~[:milestone_iid], $~[:milestone_name])
params = milestone_params($~[:milestone_iid].to_i, $~[:milestone_name])
milestone = project.milestones.find_by(params)
if milestone if milestone
yield match, milestone.iid, $~[:project], $~ yield match, milestone.iid, $~[:project], $~
...@@ -29,6 +27,22 @@ module Banzai ...@@ -29,6 +27,22 @@ module Banzai
end end
end end
def find_milestone(project_ref, milestone_id, milestone_name)
project = project_from_ref(project_ref)
return unless project
milestone_params = milestone_params(milestone_id, milestone_name)
project.milestones.find_by(milestone_params)
end
def milestone_params(iid, name)
if name
{ name: name.tr('"', '') }
else
{ iid: iid.to_i }
end
end
def url_for_object(milestone, project) def url_for_object(milestone, project)
h = Gitlab::Routing.url_helpers h = Gitlab::Routing.url_helpers
h.namespace_project_milestone_url(project.namespace, project, milestone, h.namespace_project_milestone_url(project.namespace, project, milestone,
...@@ -43,14 +57,6 @@ module Banzai ...@@ -43,14 +57,6 @@ module Banzai
html_safe html_safe
end end
end end
def milestone_params(iid, name)
if name
{ name: name.tr('"', '') }
else
{ iid: iid }
end
end
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