From c6671bd75678afb070dbfb99b5ff4db781806178 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 Topical Events aren't currently editionable and I'd very much like them to be --- .../editionable_topical_events_controller.rb | 7 ++++++ .../admin/new_document_controller.rb | 1 + app/helpers/admin/new_document_helper.rb | 2 ++ app/models/editionable_topical_event.rb | 5 +++++ .../edtionable_topical_events/_form.html.erb | 13 +++++++++++ config/routes.rb | 2 ++ lib/whitehall/authority/enforcer.rb | 1 + .../rules/editionable_topical_event_rules.rb | 7 ++++++ test/factories/editionable_topical_events.rb | 7 ++++++ ...itionable_topical_event_controller_test.rb | 22 +++++++++++++++++++ .../admin/new_document_controller_test.rb | 17 ++++++++++++++ 11 files changed, 84 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/edtionable_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_event_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 00000000000..429b12daa1e --- /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 c38d98d3b2c..fdd0ed1d9db 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 269ed894ca7..29a46e3148b 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/models/editionable_topical_event.rb b/app/models/editionable_topical_event.rb new file mode 100644 index 00000000000..55ca636c0fd --- /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/edtionable_topical_events/_form.html.erb b/app/views/admin/edtionable_topical_events/_form.html.erb new file mode 100644 index 00000000000..68973cf4df1 --- /dev/null +++ b/app/views/admin/edtionable_topical_events/_form.html.erb @@ -0,0 +1,13 @@ +<%= form_with model: topical_event, url: [:admin, topical_event], multipart: true do |form| %> + <%= render "govuk_publishing_components/components/input", { + label: { + text: "Name (required)", + heading_size: "l", + }, + value: topical_event.name, + name: "topical_event[name]", + id: "topical_event_name", + error_items: errors_for(topical_event.errors, :name), + } %> + +<% end %> diff --git a/config/routes.rb b/config/routes.rb index f737b5061c5..4aaf1b90afd 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 9f4fc43a8b5..228bab97468 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 00000000000..b5a07b79a97 --- /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 00000000000..dd97c89bb1e --- /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_event_controller_test.rb b/test/functional/admin/editionable_topical_event_controller_test.rb new file mode 100644 index 00000000000..5ea3e520946 --- /dev/null +++ b/test/functional/admin/editionable_topical_event_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 217626851e8..6f332ab564e 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