Skip to content

Commit

Permalink
Fixes #37434 - Use nightly for develop manual links
Browse files Browse the repository at this point in the history
Foreman has for the longest time had
https://theforeman.org/manuals/$next redirect to
https://theforeman.org/manuals/nightly in our Apache configuration. This
means that on every branching we need to modify this. It also doesn't
play well with caching and using pure static webservers.

If Foreman uses nightly as the version, this whole redirect is no longer needed.
  • Loading branch information
ekohl authored and evgeni committed May 17, 2024
1 parent 000a516 commit 0f9352a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
9 changes: 6 additions & 3 deletions app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,20 @@ def foreman_org_path(sub_path)
"https://theforeman.org/#{sub_path}"
end

def documentation_version
SETTINGS[:version].tag == 'develop' ? 'nightly' : SETTINGS[:version].short
end

def documentation_url(section = "", options = {})
root_url = options[:root_url] || foreman_org_path("manuals/#{SETTINGS[:version].short}/index.html#")
root_url = options[:root_url] || foreman_org_path("manuals/#{documentation_version}/index.html#")
root_url + (section || '')
end

# For new documentation at docs.theforeman.org
def docs_url(guide:, flavor:, chapter: nil)
version = SETTINGS[:version].tag == 'develop' ? 'nightly' : SETTINGS[:version].short
chapter_hash = "##{chapter}" if chapter

"https://docs.theforeman.org/#{version}/#{guide}/index-#{flavor}.html#{chapter_hash}"
"https://docs.theforeman.org/#{documentation_version}/#{guide}/index-#{flavor}.html#{chapter_hash}"
end

def plugin_documentation_url
Expand Down
23 changes: 17 additions & 6 deletions test/controllers/links_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

class LinksControllerTest < ActionController::TestCase
describe 'documentation' do
test '#documentation_url returns global url if no section specified' do
get :show, params: { type: 'manual' }
test '#documentation_url returns global url if no section specified on develop' do
with_temporary_settings(version: Foreman::Version.new('3.10-develop')) do
get :show, params: { type: 'manual' }

assert_redirected_to /index.html/
assert_redirected_to 'https://theforeman.org/manuals/nightly/index.html#'
end
end

test '#documentation_url returns global url if no section specified on stable' do
with_temporary_settings(version: Foreman::Version.new('3.9.1')) do
get :show, params: { type: 'manual' }

assert_redirected_to 'https://theforeman.org/manuals/3.9/index.html#'
end
end

test '#documentation_url returns foreman docs url with a given section' do
get :show, params: { type: 'manual', section: '1.1TestSection' }
with_temporary_settings(version: Foreman::Version.new('3.10-develop')) do
get :show, params: { type: 'manual', section: '1.1TestSection' }

assert_redirected_to /TestSection/
assert_redirected_to /manuals/
assert_redirected_to 'https://theforeman.org/manuals/nightly/index.html#1.1TestSection'
end
end

test '#documentation_url receives a root_url option' do
Expand Down

0 comments on commit 0f9352a

Please sign in to comment.