Fixes #2628: KB link to public interface loses HTTP type.

This commit is contained in:
Mantas Masalskis 2020-02-18 15:36:47 +01:00 committed by Thorsten Eckel
parent 212e07e322
commit a01a2f3c91
4 changed files with 20 additions and 12 deletions

View file

@ -116,9 +116,8 @@ class App.KnowledgeBaseCustomAddressForm extends App.KnowledgeBaseForm
openSnippetsModal: (e) ->
@preventDefaultAndStopPropagation(e)
loader = new App.ControllerModalLoading(
container: @el.closest('.main')
)
button = e.currentTarget
button.disabled = true
@ajax(
id: 'knowledge_bases_init_admin'
@ -126,7 +125,7 @@ class App.KnowledgeBaseCustomAddressForm extends App.KnowledgeBaseForm
url: @object().manageUrl('server_snippets')
processData: true
success: (data, status, xhr) =>
loader.hide()
button.disabled = false
new App.KnowledgeBaseServerSnippet(
container: @el.closest('.main')
@ -135,7 +134,7 @@ class App.KnowledgeBaseCustomAddressForm extends App.KnowledgeBaseForm
address_type: data.address_type
)
error: (xhr) =>
loader.hide()
button.disabled = false
if xhr.status != 422
return

View file

@ -39,7 +39,7 @@ class KnowledgeBase::Public::CategoriesController < KnowledgeBase::Public::BaseC
path = help_root_path(locale: primary_locale.locale)
redirect_to custom_path_if_needed(path, knowledge_base)
redirect_to custom_path_if_needed(path, knowledge_base, full: true)
end
private

View file

@ -5,13 +5,20 @@ module KnowledgeBaseHelper
knowledge_base.send("#{layout_prefix}_layout")
end
def custom_path_if_needed(path, knowledge_base)
return path if knowledge_base.custom_address_matches? request
def custom_path_if_needed(path, knowledge_base, full: false)
return path unless knowledge_base.custom_address_matches? request
prefix = knowledge_base.custom_address_uri&.path
return path if prefix.nil?
custom_address = knowledge_base.custom_address_uri
return path unless custom_address
path.gsub(%r{^\/help}, prefix).presence || '/'
output = path.gsub(%r{^\/help}, custom_address.path || '').presence || '/'
if full
fqdn = request.headers.env['SERVER_NAME']
output = "#{custom_address.scheme}://#{custom_address.host || fqdn}#{output}"
end
output
end
def translation_locale_code(translation)

View file

@ -63,7 +63,9 @@ class KnowledgeBase < ApplicationModel
def custom_address_uri
return nil if custom_address.blank?
URI("protocol://#{custom_address}")
scheme = Setting.get('http_type') || 'http'
URI("#{scheme}://#{custom_address}")
rescue URI::InvalidURIError
nil
end