From b51e610d0342c70937d55bfea84fe93f01ed5567 Mon Sep 17 00:00:00 2001 From: Thomas Hutterer <thutterer@gitlab.com> Date: Tue, 16 Apr 2024 10:40:06 +0000 Subject: [PATCH] Fix link to self-hosted docs in sidebar help menu Changelog: fixed --- .../super_sidebar/components/help_center.vue | 6 ++--- app/controllers/help_controller.rb | 4 +++ app/helpers/sidebars_helper.rb | 1 + config/routes/help.rb | 1 + spec/controllers/help_controller_spec.rb | 26 +++++++++++++++++++ .../components/help_center_spec.js | 6 ++--- spec/frontend/super_sidebar/mock_data.js | 1 + 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/super_sidebar/components/help_center.vue b/app/assets/javascripts/super_sidebar/components/help_center.vue index 90ca222aecbc7..399cf4e12c5cb 100644 --- a/app/assets/javascripts/super_sidebar/components/help_center.vue +++ b/app/assets/javascripts/super_sidebar/components/help_center.vue @@ -8,7 +8,7 @@ import { } from '@gitlab/ui'; import GitlabVersionCheckBadge from '~/gitlab_version_check/components/gitlab_version_check_badge.vue'; import { helpPagePath } from '~/helpers/help_page_helper'; -import { FORUM_URL, DOCS_URL, PROMO_URL } from 'jh_else_ce/lib/utils/url_utility'; +import { FORUM_URL, PROMO_URL } from 'jh_else_ce/lib/utils/url_utility'; import { __, s__ } from '~/locale'; import { STORAGE_KEY } from '~/whats_new/utils/notification'; import Tracking from '~/tracking'; @@ -92,7 +92,7 @@ export default { }, { text: this.$options.i18n.docs, - href: DOCS_URL, + href: this.sidebarData.docs_path, extraAttrs: { ...this.trackingAttrs('gitlab_documentation'), }, @@ -113,7 +113,7 @@ export default { }, { text: this.$options.i18n.contribute, - href: helpPagePath('', { anchor: 'contributing-to-gitlab' }), + href: helpPagePath('', { anchor: 'contribute-to-gitlab' }), extraAttrs: { ...this.trackingAttrs('contribute_to_gitlab'), }, diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb index dbf80010cde7b..fd7527ecf4385 100644 --- a/app/controllers/help_controller.rb +++ b/app/controllers/help_controller.rb @@ -51,6 +51,10 @@ def show end end + def redirect_to_docs + redirect_to documentation_base_url + end + def shortcuts end diff --git a/app/helpers/sidebars_helper.rb b/app/helpers/sidebars_helper.rb index d890b39e35594..4ead70839f56e 100644 --- a/app/helpers/sidebars_helper.rb +++ b/app/helpers/sidebars_helper.rb @@ -49,6 +49,7 @@ def super_sidebar_logged_out_context(panel:, panel_type:) # rubocop:disable Metr current_menu_items: panel.super_sidebar_menu_items, current_context_header: panel.super_sidebar_context_header, support_path: support_url, + docs_path: help_docs_path, display_whats_new: display_whats_new?, whats_new_most_recent_release_items_count: whats_new_most_recent_release_items_count, whats_new_version_digest: whats_new_version_digest, diff --git a/config/routes/help.rb b/config/routes/help.rb index 54ad3d43081e9..65d3c00dd4595 100644 --- a/config/routes/help.rb +++ b/config/routes/help.rb @@ -4,4 +4,5 @@ get 'help/shortcuts' => 'help#shortcuts' get 'help/instance_configuration' => 'help#instance_configuration' get 'help/drawers/*markdown_file' => 'help#drawers' +get 'help/docs' => 'help#redirect_to_docs' get 'help/*path' => 'help#show', as: :help_page diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index d966caa331ff3..9c8b198124c9b 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -404,6 +404,32 @@ end end + describe 'GET #docs' do + subject { get :redirect_to_docs } + + context 'with no custom docs URL configured' do + it 'redirects to docs.gitlab.com' do + subject + + expect(response).to redirect_to('https://docs.gitlab.com') + end + end + + context 'with a custom docs URL configured' do + let(:custom_docs_url) { 'https://foo.example.com' } + + before do + stub_application_setting(help_page_documentation_base_url: custom_docs_url) + end + + it 'redirects to the configured docs URL' do + subject + + expect(response).to redirect_to(custom_docs_url) + end + end + end + def stub_two_factor_required allow(controller).to receive(:two_factor_authentication_required?).and_return(true) allow(controller).to receive(:current_user_requires_two_factor?).and_return(true) diff --git a/spec/frontend/super_sidebar/components/help_center_spec.js b/spec/frontend/super_sidebar/components/help_center_spec.js index c12c9f460e800..8bed08b56ae28 100644 --- a/spec/frontend/super_sidebar/components/help_center_spec.js +++ b/spec/frontend/super_sidebar/components/help_center_spec.js @@ -4,7 +4,7 @@ import toggleWhatsNewDrawer from '~/whats_new'; import { mountExtended } from 'helpers/vue_test_utils_helper'; import HelpCenter from '~/super_sidebar/components/help_center.vue'; import { helpPagePath } from '~/helpers/help_page_helper'; -import { DOCS_URL, FORUM_URL, PROMO_URL } from 'jh_else_ce/lib/utils/url_utility'; +import { FORUM_URL, PROMO_URL } from 'jh_else_ce/lib/utils/url_utility'; import { useLocalStorageSpy } from 'helpers/local_storage_helper'; import { STORAGE_KEY } from '~/whats_new/utils/notification'; import { helpCenterState } from '~/super_sidebar/constants'; @@ -53,7 +53,7 @@ describe('HelpCenter component', () => { }, { text: HelpCenter.i18n.docs, - href: DOCS_URL, + href: sidebarData.docs_path, extraAttrs: trackingAttrs('gitlab_documentation'), }, { @@ -68,7 +68,7 @@ describe('HelpCenter component', () => { }, { text: HelpCenter.i18n.contribute, - href: helpPagePath('', { anchor: 'contributing-to-gitlab' }), + href: helpPagePath('', { anchor: 'contribute-to-gitlab' }), extraAttrs: trackingAttrs('contribute_to_gitlab'), }, { diff --git a/spec/frontend/super_sidebar/mock_data.js b/spec/frontend/super_sidebar/mock_data.js index 067caec5ff4a1..925dc8b4114fd 100644 --- a/spec/frontend/super_sidebar/mock_data.js +++ b/spec/frontend/super_sidebar/mock_data.js @@ -102,6 +102,7 @@ export const sidebarData = { projects_path: 'path/to/projects', groups_path: 'path/to/groups', support_path: '/support', + docs_path: '/help/docs', display_whats_new: true, whats_new_most_recent_release_items_count: 5, whats_new_version_digest: 1, -- GitLab