From ac86d31cfc10573f41db7396fe789e0793cf5389 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 17 Jan 2024 09:00:24 +0100 Subject: [PATCH] Support branding links to docs.theforeman.org --- .../concerns/documentation_controller_branding.rb | 9 +++++++++ lib/foreman_theme_satellite/documentation.rb | 6 ++++++ test/functionals/documentation_links_test.rb | 12 ++++++++++++ .../documentation_controller_branding_test.rb | 15 +++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 test/integration/documentation_controller_branding_test.rb diff --git a/app/controllers/concerns/documentation_controller_branding.rb b/app/controllers/concerns/documentation_controller_branding.rb index fe832b9..33f3adf 100644 --- a/app/controllers/concerns/documentation_controller_branding.rb +++ b/app/controllers/concerns/documentation_controller_branding.rb @@ -30,4 +30,13 @@ def plugin_documentation_url def wiki_url(section: '') documentation_url(section) end + + # For new documentation at docs.theforeman.org + # We do not use flavor downstream, but keeping it here for the same method signature + # rubocop:disable Lint/UnusedMethodArgument + def docs_url(guide:, flavor:, chapter: nil) + url = ForemanThemeSatellite::Documentation::DOCS_GUIDES_LINKS.dig(guide, chapter) + url || "#{ForemanThemeSatellite.documentation_root}/#{guide.downcase}/#{chapter}" + end + # rubocop:enable Lint/UnusedMethodArgument end diff --git a/lib/foreman_theme_satellite/documentation.rb b/lib/foreman_theme_satellite/documentation.rb index 5cdad7d..aeaadb5 100644 --- a/lib/foreman_theme_satellite/documentation.rb +++ b/lib/foreman_theme_satellite/documentation.rb @@ -80,5 +80,11 @@ module Documentation SPECIAL_LINKS = [ [/docs\.theforeman\.org\/.*?\/Managing_Hosts\/.*?registering-a-host.*?managing-hosts/i, "#{ForemanThemeSatellite.documentation_root}/managing_hosts/registering_hosts_to_server_managing-hosts#Registering_Hosts_managing-hosts"], ] + + DOCS_GUIDES_LINKS = { + 'Managing_Hosts' => { + 'registering-a-host_managing-hosts' => "#{ForemanThemeSatellite.documentation_root}/managing_hosts/registering_hosts_to_server_managing-hosts#Registering_Hosts_managing-hosts", + } + }.freeze end end diff --git a/test/functionals/documentation_links_test.rb b/test/functionals/documentation_links_test.rb index 7179dcc..b8fc79e 100644 --- a/test/functionals/documentation_links_test.rb +++ b/test/functionals/documentation_links_test.rb @@ -41,4 +41,16 @@ class DocumentationLinksTest < ActiveSupport::TestCase refute_equal '404', res.code, "Documentation link #{doc_address} was not found" end end + + ForemanThemeSatellite::Documentation::DOCS_GUIDES_LINKS.each do |guide, chapters| + chapters.each do |key, doc_address| + test "#{guide} #{key} entry is valid" do + uri = URI(doc_address) + res = Net::HTTP.get_response(uri) + + # it can be either 200 or 302 + refute_equal '404', res.code, "Documentation link #{doc_address} was not found" + end + end + end end diff --git a/test/integration/documentation_controller_branding_test.rb b/test/integration/documentation_controller_branding_test.rb new file mode 100644 index 0000000..1834224 --- /dev/null +++ b/test/integration/documentation_controller_branding_test.rb @@ -0,0 +1,15 @@ +require 'test_plugin_helper' + +class DocumentationControllerBrandingTest < ActionDispatch::IntegrationTest + def test_docs_redirect_branded + get "/links/docs/Managing_Hosts?chapter=registering-a-host_managing-hosts" + + assert_redirected_to "https://access.redhat.com/documentation/en-us/red_hat_satellite/#{ForemanThemeSatellite.documentation_version}/html/managing_hosts/registering_hosts_to_server_managing-hosts#Registering_Hosts_managing-hosts" + end + + def test_docs_redirect_unknown_chapter + get "/links/docs/Managing_Hosts" + + assert_redirected_to "https://access.redhat.com/documentation/en-us/red_hat_satellite/#{ForemanThemeSatellite.documentation_version}/html/managing_hosts/" + end +end