Commit 9f752b20 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch '327001-fix-mr-label-system-notes-link' into 'master'

Fix label links in MR system notes

See merge request gitlab-org/gitlab!79928
parents 9c560f4c 4daa5ea8
...@@ -54,7 +54,7 @@ class ResourceLabelEvent < ResourceEvent ...@@ -54,7 +54,7 @@ class ResourceLabelEvent < ResourceEvent
end end
def banzai_render_context(field) def banzai_render_context(field)
super.merge(pipeline: :label, only_path: true) super.merge(pipeline: :label, only_path: true, label_url_method: label_url_method)
end end
def refresh_invalid_reference def refresh_invalid_reference
...@@ -91,6 +91,10 @@ class ResourceLabelEvent < ResourceEvent ...@@ -91,6 +91,10 @@ class ResourceLabelEvent < ResourceEvent
end end
end end
def label_url_method
issuable.is_a?(MergeRequest) ? :project_merge_requests_url : :project_issues_url
end
def expire_etag_cache def expire_etag_cache
issuable.expire_note_etag_cache issuable.expire_note_etag_cache
end end
......
...@@ -15,19 +15,23 @@ module EE ...@@ -15,19 +15,23 @@ module EE
end end
end end
override :discussion_id_key
def discussion_id_key
(super + [label&.scoped_label?]).compact # label can be nil as we don't remove resource events when deleting labels
end
override :issuable override :issuable
def issuable def issuable
epic || super epic || super
end end
override :banzai_render_context private
def banzai_render_context(field)
epic ? super.merge(label_url_method: :group_epics_url) : super override :label_url_method
def label_url_method
return :group_epics_url if issuable.is_a?(Epic)
super
end
override :discussion_id_key
def discussion_id_key
(super + [label&.scoped_label?]).compact # label can be nil as we don't remove resource events when deleting labels
end end
end end
end end
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe LabelNote do RSpec.describe LabelNote do
include Gitlab::Routing.url_helpers
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:label) { create(:label, project: project) } let_it_be(:label) { create(:label, project: project) }
...@@ -14,11 +16,27 @@ RSpec.describe LabelNote do ...@@ -14,11 +16,27 @@ RSpec.describe LabelNote do
let_it_be(:resource) { create(:issue, project: project) } let_it_be(:resource) { create(:issue, project: project) }
it_behaves_like 'label note created from events' it_behaves_like 'label note created from events'
it 'includes a link to the list of issues filtered by the label' do
note = described_class.from_events([
create(:resource_label_event, label: label, issue: resource)
])
expect(note.note_html).to include(project_issues_path(project, label_name: label.title))
end
end end
context 'when resource is merge request' do context 'when resource is merge request' do
let_it_be(:resource) { create(:merge_request, source_project: project, target_project: project) } let_it_be(:resource) { create(:merge_request, source_project: project, target_project: project) }
it_behaves_like 'label note created from events' it_behaves_like 'label note created from events'
it 'includes a link to the list of merge requests filtered by the label' do
note = described_class.from_events([
create(:resource_label_event, label: label, merge_request: resource)
])
expect(note.note_html).to include(project_merge_requests_path(project, label_name: label.title))
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