Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create editionable topical events #9714

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion 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 All @@ -19,7 +20,7 @@ def new_document_type_list
.select { |edition_type| can?(:create, edition_type) }
.map do |edition_type|
title_value = edition_type.name.underscore
title_label = title_value.humanize
title_label = title_value.gsub("editionable_", "").humanize
{
value: title_value,
text: title_label,
Expand All @@ -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
1 change: 1 addition & 0 deletions app/helpers/admin/republishing_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def republishable_content_types
CorporateInformationPage
DetailedGuide
DocumentCollection
EditionableTopicalEvent
WorldwideOrganisation
FatalityNotice
LandingPage
Expand Down
9 changes: 9 additions & 0 deletions app/models/editionable_topical_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class EditionableTopicalEvent < Edition
def display_type_key
"editionable_topical_event"
end

def self.format_name
"topical event"
end
end
3 changes: 3 additions & 0 deletions app/views/admin/editionable_topical_events/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= standard_edition_form(edition) do |form| %>

<% end %>
1 change: 1 addition & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
feature :govspeak_visual_editor, description: "Enables a visual editor for Govspeak fields", default: false
feature :override_government, description: "Enables GDS Editors and Admins to override the government associated with a document", default: false
feature :show_link_to_content_block_manager, description: "Shows link to Content Block Manager from Whitehall editor", default: Whitehall.integration_or_staging?
feature :editionable_topical_events, description: "Enables edtionable topical events", default: false
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
2 changes: 1 addition & 1 deletion features/support/document_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def begin_drafting_document(options)
create(:organisation) if Organisation.count.zero?
visit admin_root_path
find("li.app-c-sub-navigation__list-item a", text: "New document").click
page.choose(options[:type].humanize)
page.choose(options[:type].gsub("editionable_", "").humanize)
click_button("Next")

if options[:locale]
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
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
Loading