Skip to content

Commit

Permalink
Add basics for editionable topical events
Browse files Browse the repository at this point in the history
Topical Events aren't currently editionable and I'd very much like them to be
  • Loading branch information
JonathanHallam committed Dec 9, 2024
1 parent 594dbe5 commit c6671bd
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Admin::EditionableTopicalEventsController < Admin::EditionsController
private

def edition_class
EditionableTopicalEvent
end
end
1 change: 1 addition & 0 deletions app/controllers/admin/new_document_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/admin/new_document_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Admin::NewDocumentHelper
CaseStudy,
StatisticalDataSet,
CallForEvidence,
EditionableTopicalEvent,
WorldwideOrganisation,
LandingPage,
].freeze
Expand Down Expand Up @@ -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.",
}
Expand Down
5 changes: 5 additions & 0 deletions app/models/editionable_topical_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class EditionableTopicalEvent < Edition
def display_type_key
"editionable_topical_event"
end
end
13 changes: 13 additions & 0 deletions app/views/admin/edtionable_topical_events/_form.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/whitehall/authority/enforcer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Whitehall::Authority::Rules
EditionableTopicalEventRules = Struct.new(:actor, :subject) do
def can?(_action)
Flipflop.editionable_topical_events?
end
end
end
7 changes: 7 additions & 0 deletions test/factories/editionable_topical_events.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions test/functional/admin/editionable_topical_event_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions test/functional/admin/new_document_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c6671bd

Please sign in to comment.