From 20a4f25f4b7bd1ea5367a273fd0bdfbb3a2e78be Mon Sep 17 00:00:00 2001 From: JonathanHallam Date: Mon, 9 Dec 2024 10:51:56 +0000 Subject: [PATCH] Add basics for editionable topical events There's been an RFC accepted to editionablise all the remaining content types that are currently published by Whitehall. As part of a gift week project we're attempting to do that to topical events. We're unsure as to how far we'll get and will be liasing with the Whitehall Tech team to ensure we don't do anything too silly. This sets up the core components needed for Topical events. We'll build on this until we're as close to feature pairity as we can reasonably get in a week. https://github.com/alphagov/govuk-rfcs/blob/main/rfc-177-edition-all-content.md --- .../editionable_topical_events_controller.rb | 7 ++++++ .../admin/new_document_controller.rb | 1 + app/helpers/admin/new_document_helper.rb | 2 ++ app/helpers/admin/republishing_helper.rb | 1 + app/models/editionable_topical_event.rb | 5 +++++ .../editionable_topical_events/_form.html.erb | 3 +++ config/routes.rb | 2 ++ lib/whitehall/authority/enforcer.rb | 1 + .../rules/editionable_topical_event_rules.rb | 7 ++++++ test/factories/editionable_topical_events.rb | 7 ++++++ ...tionable_topical_events_controller_test.rb | 22 +++++++++++++++++++ .../admin/new_document_controller_test.rb | 17 ++++++++++++++ 12 files changed, 75 insertions(+) create mode 100644 app/controllers/admin/editionable_topical_events_controller.rb create mode 100644 app/models/editionable_topical_event.rb create mode 100644 app/views/admin/editionable_topical_events/_form.html.erb create mode 100644 lib/whitehall/authority/rules/editionable_topical_event_rules.rb create mode 100644 test/factories/editionable_topical_events.rb create mode 100644 test/functional/admin/editionable_topical_events_controller_test.rb diff --git a/app/controllers/admin/editionable_topical_events_controller.rb b/app/controllers/admin/editionable_topical_events_controller.rb new file mode 100644 index 000000000000..429b12daa1e4 --- /dev/null +++ b/app/controllers/admin/editionable_topical_events_controller.rb @@ -0,0 +1,7 @@ +class Admin::EditionableTopicalEventsController < Admin::EditionsController +private + + def edition_class + EditionableTopicalEvent + end +end diff --git a/app/controllers/admin/new_document_controller.rb b/app/controllers/admin/new_document_controller.rb index c38d98d3b2c7..fdd0ed1d9dbc 100644 --- a/app/controllers/admin/new_document_controller.rb +++ b/app/controllers/admin/new_document_controller.rb @@ -24,6 +24,7 @@ def redirect_path(new_document_type) publication: new_admin_publication_path, speech: new_admin_speech_path, statistical_data_set: new_admin_statistical_data_set_path, + editionable_topical_event: new_admin_editionable_topical_event_path, worldwide_organisation: new_admin_worldwide_organisation_path, landing_page: new_admin_landing_page_path, } diff --git a/app/helpers/admin/new_document_helper.rb b/app/helpers/admin/new_document_helper.rb index 269ed894ca71..29a46e3148be 100644 --- a/app/helpers/admin/new_document_helper.rb +++ b/app/helpers/admin/new_document_helper.rb @@ -10,6 +10,7 @@ module Admin::NewDocumentHelper CaseStudy, StatisticalDataSet, CallForEvidence, + EditionableTopicalEvent, WorldwideOrganisation, LandingPage, ].freeze @@ -43,6 +44,7 @@ def hint_text(new_document_type) publication: "Use this for standalone government documents, white papers, strategy documents, and reports.", speech: "Use this for speeches by ministers or other named spokespeople, and ministerial statements to Parliament.", statistical_data_set: "Use this for data that you publish monthly or more often without analysis.", + editionable_topical_event: "Use this to create new Topical Events", worldwide_organisation: "Use this to create a new worldwide organisation page. Do not create a worldwide organisation unless you have permission from your managing editor or GOV.UK department lead.", landing_page: "EXPERIMENTAL Use this to create landing pages.", } diff --git a/app/helpers/admin/republishing_helper.rb b/app/helpers/admin/republishing_helper.rb index 37efc58275c1..d089aa530dcc 100644 --- a/app/helpers/admin/republishing_helper.rb +++ b/app/helpers/admin/republishing_helper.rb @@ -89,6 +89,7 @@ def republishable_content_types CorporateInformationPage DetailedGuide DocumentCollection + EditionableTopicalEvent WorldwideOrganisation FatalityNotice LandingPage diff --git a/app/models/editionable_topical_event.rb b/app/models/editionable_topical_event.rb new file mode 100644 index 000000000000..55ca636c0fd0 --- /dev/null +++ b/app/models/editionable_topical_event.rb @@ -0,0 +1,5 @@ +class EditionableTopicalEvent < Edition + def display_type_key + "editionable_topical_event" + end +end diff --git a/app/views/admin/editionable_topical_events/_form.html.erb b/app/views/admin/editionable_topical_events/_form.html.erb new file mode 100644 index 000000000000..73a60388c91d --- /dev/null +++ b/app/views/admin/editionable_topical_events/_form.html.erb @@ -0,0 +1,3 @@ +<%= standard_edition_form(edition) do |form| %> + +<% end %> diff --git a/config/routes.rb b/config/routes.rb index f737b5061c5e..4aaf1b90afdb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -163,6 +163,8 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) end resources :operational_fields, except: [:show] + resources :editionable_topical_events, path: "editionable-topical-events", except: [:index] + resources :topical_events, path: "topical-events" do resource :topical_event_about_pages, path: "about" resources :topical_event_featurings, path: "featurings" do diff --git a/lib/whitehall/authority/enforcer.rb b/lib/whitehall/authority/enforcer.rb index 9f4fc43a8b51..228bab97468c 100644 --- a/lib/whitehall/authority/enforcer.rb +++ b/lib/whitehall/authority/enforcer.rb @@ -48,5 +48,6 @@ def find_ruleset_for_instance_or_closest_ancestor(subject) "Organisation" => Rules::OrganisationRules, "Government" => Rules::GovernmentRules, "StatisticsAnnouncement" => Rules::StatisticsAnnouncementRules, + "EditionableTopicalEvent" => Rules::EditionableTopicalEventRules, }.freeze end diff --git a/lib/whitehall/authority/rules/editionable_topical_event_rules.rb b/lib/whitehall/authority/rules/editionable_topical_event_rules.rb new file mode 100644 index 000000000000..b5a07b79a97c --- /dev/null +++ b/lib/whitehall/authority/rules/editionable_topical_event_rules.rb @@ -0,0 +1,7 @@ +module Whitehall::Authority::Rules + EditionableTopicalEventRules = Struct.new(:actor, :subject) do + def can?(_action) + Flipflop.editionable_topical_events? + end + end +end diff --git a/test/factories/editionable_topical_events.rb b/test/factories/editionable_topical_events.rb new file mode 100644 index 000000000000..dd97c89bb1e0 --- /dev/null +++ b/test/factories/editionable_topical_events.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :editionable_topical_event, class: EditionableTopicalEvent, parent: :edition do + title { "editionable-topical-event-title" } + end + + factory :draft_editionable_topical_event, parent: :editionable_topical_event, traits: [:draft] +end diff --git a/test/functional/admin/editionable_topical_events_controller_test.rb b/test/functional/admin/editionable_topical_events_controller_test.rb new file mode 100644 index 000000000000..806c41cc300a --- /dev/null +++ b/test/functional/admin/editionable_topical_events_controller_test.rb @@ -0,0 +1,22 @@ +require "test_helper" + +class Admin::EditionableTopicalEventsControllerTest < ActionController::TestCase + setup do + feature_flags.switch! :editionable_topical_events, true + login_as :writer + end + + should_be_an_admin_controller + + # should_allow_creating_of :editionable_topical_event + # should_allow_editing_of :editionable_topical_event + + test "actions are forbidden when the editionable_topical_events feature flag is disabled" do + feature_flags.switch! :editionable_topical_events, false + topical_event = create(:editionable_topical_event) + + get :show, params: { id: topical_event.id } + + assert_response :forbidden + end +end diff --git a/test/functional/admin/new_document_controller_test.rb b/test/functional/admin/new_document_controller_test.rb index 217626851e82..6f332ab564e4 100644 --- a/test/functional/admin/new_document_controller_test.rb +++ b/test/functional/admin/new_document_controller_test.rb @@ -84,6 +84,22 @@ class Admin::NewDocumentControllerTest < ActionController::TestCase assert_equal flash[:alert], "Please select a new document option" end + view_test "GET #index renders Topical Event Edition when the editionable_topical_events feature flag is enabled" do + feature_flags.switch! :editionable_topical_events, true + + get :index + + assert_select ".govuk-radios__item input[type=radio][name=new_document_options][value=editionable_topical_event]", count: 1 + end + + view_test "GET #index does not render Topical Event Edition when the editionable_topical_events feature flag is not enabled" do + feature_flags.switch! :editionable_topical_events, false + + get :index + + refute_select ".govuk-radios__item input[type=radio][name=new_document_options][value=editionable_topical_event]" + end + private def radio_button_values @@ -106,6 +122,7 @@ def redirect_options "publication": new_admin_publication_path, "speech": new_admin_speech_path, "statistical_data_set": new_admin_statistical_data_set_path, + "editionable_topical_event": new_admin_editionable_topical_event_path, "worldwide_organisation": new_admin_worldwide_organisation_path, } end