diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index 1ac45c73b..fc970f5cc 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -1,12 +1,8 @@ -# The controller for actions related to the about pages class AboutController < ApplicationController - + before_action :check_external_link, only: [:tess, :registering, :learning_paths, :developers, :us] skip_before_action :authenticate_user!, :authenticate_user_from_token! - - def tess - end - def us + def tess end def registering @@ -18,4 +14,22 @@ def learning_paths def developers end + def us + end + + private + + def check_external_link + if TeSS::Config.site['about_us_link'].present? + base = TeSS::Config.site['about_us_link'].to_s.chomp('/') + action_name_map = { + 'tess' => '/', + 'registering' => '/content/intro-content/', + 'learning_paths' => '/content/learning-paths/', + 'developers' => '/developers/code-data/', + 'us' => '/overview/about/' + } + redirect_to "#{base}#{action_name_map.fetch(action_name)}", allow_other_host: true + end + end end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 52da0aeca..0de4eabe7 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -64,7 +64,7 @@ <%= menu_group(pull: 'right') do %> <% main_tabs.each do |t| %> - <%= menu_item t("features.#{t[:feature]}.short"), t[:link] %> + <%= menu_item t("features.#{t[:feature]}.short"), t[:link], (t[:feature] == 'about' && TeSS::Config.site['about_us_link'].present? ? { target: '_blank', rel: 'noopener' } : {}) %> <% end %> <% if directory_tabs.present? %> diff --git a/config/tess.example.yml b/config/tess.example.yml index c8a51db5e..299cc1e5a 100644 --- a/config/tess.example.yml +++ b/config/tess.example.yml @@ -131,6 +131,7 @@ default: &default directory_tabs: ['trainers', 'content_providers', 'nodes', 'spaces'] # The order in with the 'about us' tabs appear about_us_tab_order: ['tess_club', 'contact', 'team', 'funding', 'acknowledgements', 'cite'] + about_us_link: https://elixirtess.github.io/docs # no / at the end n_provider_ids: 5 calendar_event_maxlength: 5 content_provider_grid_long: true # true for full width in grid, false for short diff --git a/test/config/test_tess.yml b/test/config/test_tess.yml index b2511a0fe..7df36ac09 100644 --- a/test/config/test_tess.yml +++ b/test/config/test_tess.yml @@ -30,6 +30,7 @@ default: &default repository: '' supported_by: 'elixir_supported_by' widget_example: 'elixir_widget_example' + about_us_link: gmaps_api_key: '' mailer: delivery_method: test diff --git a/test/controllers/about_controller_test.rb b/test/controllers/about_controller_test.rb index 6f550d878..72ef8f4dc 100644 --- a/test/controllers/about_controller_test.rb +++ b/test/controllers/about_controller_test.rb @@ -127,4 +127,31 @@ class AboutControllerTest < ActionController::TestCase assert_response :success end end + + test 'should redirect about pages to external link when configured' do + site_settings = TeSS::Config.site.dup + site_settings['about_us_link'] = 'https://example.org' + + with_settings(site: site_settings) do + get :tess + assert_response :redirect + assert_redirected_to 'https://example.org/' + + get :registering + assert_response :redirect + assert_redirected_to 'https://example.org/content/intro-content/' + + get :learning_paths + assert_response :redirect + assert_redirected_to 'https://example.org/content/learning-paths/' + + get :developers + assert_response :redirect + assert_redirected_to 'https://example.org/developers/code-data/' + + get :us + assert_response :redirect + assert_redirected_to 'https://example.org/overview/about/' + end + end end