From cb291c8dd794bf8fb465c7b74fc9ba04162a8849 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 19 Nov 2024 15:22:46 +0000 Subject: [PATCH 1/3] Add Landing Pages to the list of edition filters It's getting a bit annoying not being able to find all the landing pages on the editions index page. This adds the edition class to the filter, but removes it for non-gds-admins, since landing pages are currently restricted to those users. --- app/helpers/admin/edition_actions_helper.rb | 1 + lib/whitehall.rb | 1 + test/unit/app/helpers/admin/edition_actions_helper_test.rb | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/app/helpers/admin/edition_actions_helper.rb b/app/helpers/admin/edition_actions_helper.rb index 3c1eff1fb31..edc1cac79b5 100644 --- a/app/helpers/admin/edition_actions_helper.rb +++ b/app/helpers/admin/edition_actions_helper.rb @@ -159,6 +159,7 @@ def edition_type_options_for_select(user, selected) def type_options_container(user) Whitehall.edition_classes.map { |edition_type| next if edition_type == FatalityNotice && !user.can_handle_fatalities? + next if edition_type == LandingPage && !user.gds_admin? [edition_type.format_name.humanize.pluralize, edition_type.model_name.singular] }.compact diff --git a/lib/whitehall.rb b/lib/whitehall.rb index 1a9add51aa5..1e3f6e2f611 100644 --- a/lib/whitehall.rb +++ b/lib/whitehall.rb @@ -162,6 +162,7 @@ def self.edition_classes DetailedGuide, DocumentCollection, FatalityNotice, + LandingPage, NewsArticle, Publication, Speech, diff --git a/test/unit/app/helpers/admin/edition_actions_helper_test.rb b/test/unit/app/helpers/admin/edition_actions_helper_test.rb index 0e426385a66..8055d701da8 100644 --- a/test/unit/app/helpers/admin/edition_actions_helper_test.rb +++ b/test/unit/app/helpers/admin/edition_actions_helper_test.rb @@ -45,4 +45,11 @@ class Admin::EditionActionsHelperTest < ActionView::TestCase assert_same_elements @editions + ["Fatality notices"], types end + + test "#filter_edition_type_opt_groups should include landing pages when the user is an admin" do + filter_options = filter_edition_type_opt_groups(create(:gds_admin), nil) + types = filter_options[1].last.map { |type| type[:text] } + + assert_same_elements @editions + ["Fatality notices", "Landing pages"], types + end end From a90b3f64f00cfae24f33f2763389abe7cd76ab83 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 19 Nov 2024 15:32:16 +0000 Subject: [PATCH 2/3] Exclude LandingPage from searchable classes We're happy with LandingPages being sent to the search indexes via. publishing-api, there's no need for them to appear here too. --- app/presenters/search_api_presenters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/presenters/search_api_presenters.rb b/app/presenters/search_api_presenters.rb index 1cff36644b4..f9eeded599e 100644 --- a/app/presenters/search_api_presenters.rb +++ b/app/presenters/search_api_presenters.rb @@ -16,7 +16,7 @@ def self.present_all_detailed_content end def self.searchable_classes_for_government_index - searchable_classes - [DetailedGuide] + searchable_classes - [DetailedGuide, LandingPage] end def self.searchable_classes From 95c7688332ea52b1ae53d7514135bcaf35c8e9a5 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 19 Nov 2024 16:04:48 +0000 Subject: [PATCH 3/3] Support admin link rewriting for landing pages Now that LandingPage is part of the edition_classes list, we get tests that check link rewriting works. Which it didn't, because we hadn't put landing-pages in the edition_route_path_segments array. --- lib/whitehall.rb | 2 +- .../app/helpers/govspeak_helper_link_rewriting_test.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/whitehall.rb b/lib/whitehall.rb index 1e3f6e2f611..96998f76b8c 100644 --- a/lib/whitehall.rb +++ b/lib/whitehall.rb @@ -172,7 +172,7 @@ def self.edition_classes end def self.edition_route_path_segments - %w[news speeches policies publications consultations priority detailed-guides case-studies statistical-data-sets fatalities collections supporting-pages calls-for-evidence worldwide-organisations] + %w[news speeches policies publications consultations priority detailed-guides case-studies statistical-data-sets fatalities collections supporting-pages calls-for-evidence worldwide-organisations landing-pages] end def self.analytics_format(format) diff --git a/test/unit/app/helpers/govspeak_helper_link_rewriting_test.rb b/test/unit/app/helpers/govspeak_helper_link_rewriting_test.rb index 7a84e0a00e7..e6696c1ad73 100644 --- a/test/unit/app/helpers/govspeak_helper_link_rewriting_test.rb +++ b/test/unit/app/helpers/govspeak_helper_link_rewriting_test.rb @@ -6,7 +6,12 @@ class GovspeakHelperLinkRewritingTest < ActionView::TestCase Whitehall.edition_classes.each do |edition_class| test "should rewrite absolute path to an admin page for a published #{edition_class} as link to its public page" do - edition = create("published_#{edition_class.name.underscore}") + document = if edition_class == LandingPage + create(:document, slug: "/starts-with-slash") + else + create(:document) + end + edition = create("published_#{edition_class.name.underscore}", document:) assert_rewrites_link(from: admin_edition_path(edition), to: edition.public_url) end end