Skip to content

Commit

Permalink
Support branding links to docs.theforeman.org
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Jan 17, 2024
1 parent 392b4fc commit ac86d31
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/controllers/concerns/documentation_controller_branding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions lib/foreman_theme_satellite/documentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions test/functionals/documentation_links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions test/integration/documentation_controller_branding_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ac86d31

Please sign in to comment.