Skip to content

Commit

Permalink
Fixes #32848 - Support linking to docs.theforeman.org
Browse files Browse the repository at this point in the history
An effort is under way to use docs.theforeman.org as the primary
documentation source. It is already the official documentation source
for Katello, but until now it wasn't easily possible to (correctly) link
to it.

The documentation is built in 3 flavors:

* Katello (index-katello.html)
* Debian/Ubuntu (index-deb.html)
* Enterprise Linux (index-el.html)
  • Loading branch information
ekohl committed Jun 27, 2023
1 parent ee3a8f6 commit a792ed1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 16 deletions.
18 changes: 18 additions & 0 deletions app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def external_url(type:, options: {})
'https://projects.theforeman.org/projects/foreman/issues'
when 'vmrc'
'https://www.vmware.com/go/download-vmrc'
when 'docs'
docs_url(guide: options['section'], **options.slice('chapter', 'flavor'))
end
end

Expand All @@ -38,6 +40,22 @@ def documentation_url(section = "", options = {})
root_url + (section || '')
end

# For new documentation at docs.theforeman.org
def docs_url(guide, chapter, flavor: nil)
version = SETTINGS[:version].short
# TODO: setting?
flavor ||= if plugin_present?('katello')
'katello'
elsif File.exist?('/etc/debian_version')
'deb'
else
'el'
end
chapter_hash = "##{chapter}" if chapter

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

def plugin_documentation_url
name, version, section, root_url = plugin_documentation_params.values_at(:name, :version, :section, :root_url)
path = root_url || foreman_org_path("plugins")
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ def edit_inline(object, property, options = {})
editable(object, property, {:type => type, :title => title, :value => value, :class => klass, :source => select_values, :url => update_url, :placeholder => placeholder}.compact)
end

def documentation_url(section = "", options = {})
main_app.external_link_url(options.merge(type: 'manual', params: { section: section }))
def documentation_url(section = nil, type: 'manual', **options)
main_app.external_link_url(type: type, section: section, params: options)
end

def spinner(text = '', options = {})
Expand Down
13 changes: 13 additions & 0 deletions test/controllers/links_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,18 @@ class LinksControllerTest < ActionController::TestCase
assert_redirected_to /15.0/
assert_redirected_to /Usage/
end

test '#plugin_documentation_url and new docs page' do
get :show, params: {
type: 'docs',
section: 'TestSection',
chapter: 'TestChapter',
}

assert_redirected_to /docs.theforeman.org/
assert_redirected_to /TestSection/
assert_redirected_to /foreman-el/
assert_redirected_to /#TestChapter/
end
end
end
6 changes: 6 additions & 0 deletions test/helpers/application_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def test_generate_link_for
assert_match /my_plugin/, url
end

test '#documentation_url and new docs page' do
url = documentation_url('TestSection', { type: 'docs', chapter: 'test_chapter' })

assert_match %r{links/docs/TestSection\?chapter=test_chapter}, url
end

test '#documentation_button forwards options to #documentation_url' do
expects(:icon_text).returns('http://nowhere.com')
expects(:link_to).returns('<a>test</a>'.html_safe)
Expand Down
13 changes: 12 additions & 1 deletion webpack/assets/javascripts/react_app/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,22 @@ export const stringIsPositiveNumber = value => {

/**
* Get manual url based on version
* @param {String} section - section id for foreman documetation
* @param {String} section - section id for foreman documentation
*/
export const getManualURL = section => foremanUrl(`/links/manual/${section}`);
export const getWikiURL = section => foremanUrl(`/links/wiki/${section}`);

/**
* Get the documentation URL
* @param {String} guide - The guide containing the documentation
* @param {String} chapter - Optional chapter within the guide
* @returns {String}
*/
export const getDocsURL = (guide, chapter = null) => {
const url = foremanUrl(`/links/docs/${guide}`);
return chapter ? `{url}?chapter={encodeURIComponent(chapter)}` : url;
};

/**
* Transform the Date object to date string accepted in the server
* @param {Date}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { HelpIcon } from '@patternfly/react-icons';

import { translate as __ } from '../../../common/I18n';
import { getDocsURL } from '../../../common/helpers';
import {
useForemanOrganization,
useForemanLocation,
Expand All @@ -39,7 +40,6 @@ import {
selectPluginData,
} from './RegistrationCommandsPageSelectors';
import { dataAction, commandAction } from './RegistrationCommandsPageActions';
import { docUrl } from './RegistrationCommandsPageConstants';

import General from './components/General';
import Advanced from './components/Advanced';
Expand All @@ -53,7 +53,6 @@ const RegistrationCommandsPage = () => {
// Context
const currentOrganization = useForemanOrganization();
const currentLocation = useForemanLocation();
const foremanVersion = useForemanVersion();

// Form tabs
const [activeTab, setActiveTab] = useState(0);
Expand Down Expand Up @@ -191,7 +190,10 @@ const RegistrationCommandsPage = () => {
</GridItem>
<GridItem span={6}>
<a
href={docUrl(foremanVersion)}
href={getDocsURL(
'Managing_Hosts',
'registering-a-host_managing-hosts'
)}
target="_blank"
rel="noreferrer"
className="pf-c-button pf-m-secondary pf-m-small pull-right"
Expand Down

0 comments on commit a792ed1

Please sign in to comment.