Commit f43ee18b authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '320976-jira-issue-with-image' into 'master'

Jira Issue Detail page: Replace Jira private images with links

See merge request gitlab-org/gitlab!54098
parents 3075d6bf 720b77f3
......@@ -4,7 +4,8 @@ module Integrations
module Jira
class IssueDetailEntity < ::Integrations::Jira::IssueEntity
expose :description_html do |jira_issue|
Banzai::Pipeline::GfmPipeline.call(jira_issue.renderedFields['description'], project: nil)[:output].to_html
Banzai::Pipeline::JiraGfmPipeline
.call(jira_issue.renderedFields['description'], project: project)[:output].to_html
end
expose :state do |jira_issue|
......
# frozen_string_literal: true
module Banzai
module Filter
# HTML filter that replaces the Jira private images with the link to the image.
class JiraPrivateImageLinkFilter < HTML::Pipeline::Filter
PRIVATE_IMAGE_PATH = '/secure/attachment/'
def call
doc.xpath('descendant-or-self::img').each do |img|
next unless img['src'].start_with?(PRIVATE_IMAGE_PATH)
img_link = "#{project.jira_service.url}#{img['src']}"
link = "<a href=\"#{img_link}\">#{img_link}</a>"
img.replace(link)
end
doc
end
def project
context[:project]
end
end
end
end
# frozen_string_literal: true
module Banzai
module Pipeline
class JiraGfmPipeline < ::Banzai::Pipeline::GfmPipeline
def self.filters
[
Banzai::Filter::JiraPrivateImageLinkFilter,
*super
]
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Banzai::Filter::JiraPrivateImageLinkFilter do
include FilterSpecHelper
let_it_be(:project) { create(:project) }
let_it_be(:jira_service) { create(:jira_service, project: project) }
let_it_be(:context) { { project: project } }
context 'with a Jira private image' do
let(:img_link) { '/secure/attachment/10017/10017_jira-logo.jpg' }
it 'replaces the Jira private images with the link to the image' do
doc = filter("<img src=\"#{img_link}\">", context)
expect(doc.to_html).to eq("<a href=\"#{jira_service.url}#{img_link}\">#{jira_service.url}#{img_link}</a>")
end
end
context 'with other image' do
let(:img_link) { 'http://example.com/image.jpg' }
it 'keeps the original image' do
doc = filter("<img src=\"#{img_link}\">", context)
expect(doc.to_html).to eq("<img src=\"#{img_link}\">")
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