From 5eb197127f760638340ae28e66e12ae57039ddb1 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Tue, 9 Jul 2019 13:21:06 +0200 Subject: [PATCH] Fix relative links in protocolsio iframe Closes SCI-3660 --- .../javascripts/protocols/external_protocols_tab.js | 8 ++++++++ app/controllers/external_protocols_controller.rb | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/protocols/external_protocols_tab.js b/app/assets/javascripts/protocols/external_protocols_tab.js index 4a623afa9..bcc0c2b12 100644 --- a/app/assets/javascripts/protocols/external_protocols_tab.js +++ b/app/assets/javascripts/protocols/external_protocols_tab.js @@ -4,6 +4,7 @@ function applyClickCallbackOnProtocolCards() { $('.protocol-card').off('click').on('click', function(e) { var currProtocolCard = $(this); + var baseTag = document.createElement('base'); // Check whether this card is already active and deactivate it if ($(currProtocolCard).hasClass('active')) { @@ -30,7 +31,14 @@ function applyClickCallbackOnProtocolCards() { $('.empty-preview-panel').hide(); $('.full-preview-panel').show(); $('.btn-holder').html($(currProtocolCard).find('.external-import-btn').clone()); + + // Set base tag to account for relative links in the iframe + baseTag.href = data.base_uri; + iFrame.contents().find('head').html(baseTag); + + // Set iframe content iFrame.contents().find('body').html(data.html); + scrollbox.scrollTo(0); iFrame.contents().find('body').find('table.htCore').css('width', '100%'); iFrame.contents().find('body').find('span').css('word-break', 'break-word'); diff --git a/app/controllers/external_protocols_controller.rb b/app/controllers/external_protocols_controller.rb index 751ae2373..07960ce63 100644 --- a/app/controllers/external_protocols_controller.rb +++ b/app/controllers/external_protocols_controller.rb @@ -31,10 +31,13 @@ class ExternalProtocolsController < ApplicationController api_client = "ProtocolImporters::#{endpoint_name}::ApiClient".constantize.new html_preview = api_client.protocol_html_preview(show_params[:protocol_id]) + base_uri = URI.parse(html_preview.request.last_uri.to_s) + base_uri = "#{base_uri.scheme}://#{base_uri.host}" render json: { protocol_source: show_params[:protocol_source], protocol_id: show_params[:protocol_id], + base_uri: base_uri, html: html_preview } rescue StandardError => e @@ -103,15 +106,15 @@ class ExternalProtocolsController < ApplicationController end def index_params - params.permit(:protocol_source, :key, :page_id, :page_size, :sort_by) + params.permit(:team_id, :protocol_source, :key, :page_id, :page_size, :sort_by) end def show_params - params.permit(:protocol_source, :protocol_id) + params.permit(:team_id, :protocol_source, :protocol_id) end def new_params - params.permit(:protocol_source, :protocol_client_id) + params.permit(:team_id, :protocol_source, :protocol_client_id) end def create_protocol_params