Commit 486e9740 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '214164_use_configuration_option_for_offline_documentation' into 'master'

Add configuration option support for documentation pages

See merge request gitlab-org/gitlab!52001
parents 6223d35e 09e4ebea
...@@ -84,7 +84,16 @@ class HelpController < ApplicationController ...@@ -84,7 +84,16 @@ class HelpController < ApplicationController
end end
def documentation_base_url def documentation_base_url
@documentation_base_url ||= Gitlab::CurrentSettings.current_application_settings.help_page_documentation_base_url.presence @documentation_base_url ||= documentation_base_url_from_yml_configuration || documentation_base_url_from_db
end
# DEPRECATED
def documentation_base_url_from_db
Gitlab::CurrentSettings.current_application_settings.help_page_documentation_base_url.presence
end
def documentation_base_url_from_yml_configuration
::Gitlab.config.gitlab_docs.host.presence if ::Gitlab.config.gitlab_docs.enabled
end end
def documentation_file_path def documentation_file_path
......
...@@ -310,6 +310,13 @@ Settings.pages['secret_file'] ||= Rails.root.join('.gitlab_pages_secret') ...@@ -310,6 +310,13 @@ Settings.pages['secret_file'] ||= Rails.root.join('.gitlab_pages_secret')
Settings.pages['storage_path'] = Settings.pages['path'] Settings.pages['storage_path'] = Settings.pages['path']
Settings.pages['object_store'] = ObjectStoreSettings.legacy_parse(Settings.pages['object_store']) Settings.pages['object_store'] = ObjectStoreSettings.legacy_parse(Settings.pages['object_store'])
#
# GitLab documentation
#
Settings['gitlab_docs'] ||= Settingslogic.new({})
Settings.gitlab_docs['enabled'] ||= false
Settings.gitlab_docs['host'] = nil unless Settings.gitlab_docs.enabled
# #
# Geo # Geo
# #
......
...@@ -7,6 +7,43 @@ RSpec.describe HelpController do ...@@ -7,6 +7,43 @@ RSpec.describe HelpController do
let(:user) { create(:user) } let(:user) { create(:user) }
shared_examples 'documentation pages local render' do
it 'renders HTML' do
aggregate_failures do
is_expected.to render_template('show.html.haml')
expect(response.media_type).to eq 'text/html'
end
end
end
shared_examples 'documentation pages redirect' do |documentation_base_url|
let(:gitlab_version) { '13.4.0-ee' }
before do
stub_version(gitlab_version, 'ignored_revision_value')
end
it 'redirects user to custom documentation url with a specified version' do
is_expected.to redirect_to("#{documentation_base_url}/13.4/ee/#{path}.html")
end
context 'when it is a pre-release' do
let(:gitlab_version) { '13.4.0-pre' }
it 'redirects user to custom documentation url without a version' do
is_expected.to redirect_to("#{documentation_base_url}/ee/#{path}.html")
end
end
context 'when feature flag is disabled' do
before do
stub_feature_flags(help_page_documentation_redirect: false)
end
it_behaves_like 'documentation pages local render'
end
end
before do before do
sign_in(user) sign_in(user)
end end
...@@ -99,69 +136,70 @@ RSpec.describe HelpController do ...@@ -99,69 +136,70 @@ RSpec.describe HelpController do
describe 'GET #show' do describe 'GET #show' do
context 'for Markdown formats' do context 'for Markdown formats' do
subject { get :show, params: { path: path }, format: :md }
let(:path) { 'ssh/README' }
context 'when requested file exists' do context 'when requested file exists' do
before do before do
expect_file_read(File.join(Rails.root, 'doc/ssh/README.md'), content: fixture_file('blockquote_fence_after.md')) expect_file_read(File.join(Rails.root, 'doc/ssh/README.md'), content: fixture_file('blockquote_fence_after.md'))
get :show, params: { path: 'ssh/README' }, format: :md subject
end end
it 'assigns to @markdown' do it 'assigns to @markdown' do
expect(assigns[:markdown]).not_to be_empty expect(assigns[:markdown]).not_to be_empty
end end
it 'renders HTML' do it_behaves_like 'documentation pages local render'
aggregate_failures do
expect(response).to render_template('show.html.haml')
expect(response.media_type).to eq 'text/html'
end
end
end end
context 'when a custom help_page_documentation_url is set' do context 'when a custom help_page_documentation_url is set in database' do
before do before do
stub_application_setting(help_page_documentation_base_url: documentation_base_url) stub_application_setting(help_page_documentation_base_url: 'https://in-db.gitlab.com')
stub_version(gitlab_version, 'deadbeaf')
end end
subject { get :show, params: { path: path }, format: 'html' } it_behaves_like 'documentation pages redirect', 'https://in-db.gitlab.com'
end
let(:gitlab_version) { '13.4.0-ee' } context 'when a custom help_page_documentation_url is set in configuration file' do
let(:documentation_base_url) { 'https://docs.gitlab.com' } let(:host) { 'https://in-yaml.gitlab.com' }
let(:path) { 'ssh/README' } let(:docs_enabled) { true }
it 'redirects user to custom documentation url with a specified version' do before do
is_expected.to redirect_to("#{documentation_base_url}/13.4/ee/#{path}.html") allow(Settings).to receive(:gitlab_docs) { double(enabled: docs_enabled, host: host) }
end end
context 'when documentation url ends with a slash' do it_behaves_like 'documentation pages redirect', 'https://in-yaml.gitlab.com'
let(:documentation_base_url) { 'https://docs.gitlab.com/' }
it 'redirects user to custom documentation url without slash duplicates' do context 'when gitlab_docs is disabled' do
is_expected.to redirect_to("https://docs.gitlab.com/13.4/ee/#{path}.html") let(:docs_enabled) { false }
end
it_behaves_like 'documentation pages local render'
end end
context 'when it is a pre-release' do context 'when host is missing' do
let(:gitlab_version) { '13.4.0-pre' } let(:host) { nil }
it 'redirects user to custom documentation url without a version' do it_behaves_like 'documentation pages local render'
is_expected.to redirect_to("#{documentation_base_url}/ee/#{path}.html")
end
end end
end
context 'when feature flag is disabled' do context 'when help_page_documentation_url is set in both db and configuration file' do
before do before do
stub_feature_flags(help_page_documentation_redirect: false) stub_application_setting(help_page_documentation_base_url: 'https://in-db.gitlab.com')
end allow(Settings).to receive(:gitlab_docs) { double(enabled: true, host: 'https://in-yaml.gitlab.com') }
end
it 'renders HTML' do it_behaves_like 'documentation pages redirect', 'https://in-yaml.gitlab.com'
aggregate_failures do end
is_expected.to render_template('show.html.haml')
expect(response.media_type).to eq 'text/html' context 'when help_page_documentation_url has a trailing slash' do
end before do
end allow(Settings).to receive(:gitlab_docs) { double(enabled: true, host: 'https://in-yaml.gitlab.com/') }
end end
it_behaves_like 'documentation pages redirect', 'https://in-yaml.gitlab.com'
end end
context 'when requested file is missing' do context 'when requested file is missing' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment