diff --git a/app/controllers/admin/republishing_controller.rb b/app/controllers/admin/republishing_controller.rb index 1ef312ad9c4..7aeaafa6be6 100644 --- a/app/controllers/admin/republishing_controller.rb +++ b/app/controllers/admin/republishing_controller.rb @@ -2,38 +2,42 @@ class Admin::RepublishingController < Admin::BaseController before_action :enforce_permissions! def index - @republishable_documents = republishable_documents + @republishable_pages = republishable_pages end - def republish_past_prime_ministers_index - PresentPageToPublishingApiWorker.perform_async("PublishingApi::HistoricalAccountsIndexPresenter") - flash[:notice] = "'Past Prime Ministers' page has been scheduled for republishing" - redirect_to(admin_republishing_index_path) + def confirm_page + page_to_republish = republishable_pages.find { |page| page[:slug] == params[:page_slug] } + + return render "admin/errors/not_found", status: :not_found unless page_to_republish + + @title = page_to_republish[:title] + @republishing_path = admin_republishing_page_republish_path(page_to_republish[:slug]) end - def confirm - republishable_document = republishable_documents.find { |document| document[:slug] == params[:document_slug] } + def republish_page + page_to_republish = republishable_pages.find { |page| page[:slug] == params[:page_slug] } - return render "admin/errors/not_found", status: :not_found unless republishable_document + return render "admin/errors/not_found", status: :not_found unless page_to_republish - @document_title = republishable_document[:title] - @republishing_path = republishable_document[:republishing_path] + PresentPageToPublishingApiWorker.perform_async(page_to_republish[:presenter]) + flash[:notice] = "'#{page_to_republish[:title]}' page has been scheduled for republishing" + redirect_to(admin_republishing_index_path) end private def enforce_permissions! - enforce_permission!(:administer, :republish_documents) + enforce_permission!(:administer, :republish_content) end - def republishable_documents + def republishable_pages historical_accounts_index_presenter = PublishingApi::HistoricalAccountsIndexPresenter.new [{ title: historical_accounts_index_presenter.content[:title], public_path: historical_accounts_index_presenter.base_path, - republishing_path: admin_republishing_republish_past_prime_ministers_path, slug: historical_accounts_index_presenter.base_path.split("/").last, + presenter: "PublishingApi::HistoricalAccountsIndexPresenter", }] end end diff --git a/app/views/admin/republishing/confirm.html.erb b/app/views/admin/republishing/confirm_page.html.erb similarity index 77% rename from app/views/admin/republishing/confirm.html.erb rename to app/views/admin/republishing/confirm_page.html.erb index e66ee20b703..91f6e905918 100644 --- a/app/views/admin/republishing/confirm.html.erb +++ b/app/views/admin/republishing/confirm_page.html.erb @@ -1,5 +1,5 @@ -<% content_for :page_title, "Republish '#{@document_title}'" %> -<% content_for :title, "Are you sure you want to republish '#{@document_title}'?" %> +<% content_for :page_title, "Republish '#{@title}'" %> +<% content_for :title, "Are you sure you want to republish '#{@title}'?" %> <% content_for :title_margin_bottom, 6 %>
diff --git a/app/views/admin/republishing/index.html.erb b/app/views/admin/republishing/index.html.erb index 765e87ab64b..de816ed0065 100644 --- a/app/views/admin/republishing/index.html.erb +++ b/app/views/admin/republishing/index.html.erb @@ -1,5 +1,5 @@ -<% content_for :page_title, "Republish documents" %> -<% content_for :title, "Republish documents" %> +<% content_for :page_title, "Republish content" %> +<% content_for :title, "Republish content" %> <% content_for :title_margin_bottom, 6 %>
@@ -15,27 +15,27 @@

The following actions will allow you to schedule the republishing of content that was originally published in this application. Any linked editions will also be republished through dependency resolution. - Try to pick the document type most focused to the scope of what you need to republish to avoid unnecessary server load. + Try to pick the republishing task most focused to the scope of what you need to republish to avoid unnecessary server load.

<%= render "govuk_publishing_components/components/table", { head: [ { - text: "Document", + text: "Page", }, { text: "Action", }, ], - rows: @republishable_documents.map do |document| + rows: @republishable_pages.map do |page| [ { - text: link_to(document[:title], Plek.website_root + document[:public_path], class:"govuk-link"), + text: link_to(page[:title], Plek.website_root + page[:public_path], class:"govuk-link"), }, { - text: link_to(sanitize("Republish #{tag.span('\'' + document[:title] + '\' page', class: 'govuk-visually-hidden')}"), - admin_confirm_republishing_path(document[:slug]), - id: "republish-past-prime-ministers-index", + text: link_to(sanitize("Republish #{tag.span('\'' + page[:title] + '\' page', class: 'govuk-visually-hidden')}"), + admin_republishing_page_confirm_path(page[:slug]), + id: "republish-" + page[:slug], class: "govuk-link", ), }, diff --git a/config/routes.rb b/config/routes.rb index bde763abc4b..1d7dc1a699c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,9 +22,13 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) resources :users, only: %i[index show edit update] - get "republishing" => "republishing#index", as: :republishing_index - get "republishing/:document_slug/confirm" => "republishing#confirm", as: :confirm_republishing - post "republishing/republish-past-prime-ministers" => "republishing#republish_past_prime_ministers_index" + scope :republishing do + root to: "republishing#index", as: :republishing_index, via: :get + scope :page do + get "/:page_slug/confirm" => "republishing#confirm_page", as: :republishing_page_confirm + post "/:page_slug/republish" => "republishing#republish_page", as: :republishing_page_republish + end + end resources :documents, only: [] do resources :review_reminders, only: %i[new create edit update] diff --git a/features/step_definitions/republishing_published_documents_steps.rb.rb b/features/step_definitions/republishing_published_documents_steps.rb.rb index 7f6f4c9fe78..9df82a6ab55 100644 --- a/features/step_definitions/republishing_published_documents_steps.rb.rb +++ b/features/step_definitions/republishing_published_documents_steps.rb.rb @@ -4,7 +4,7 @@ When(/^I request a republish of the "Past prime ministers" page$/) do visit admin_republishing_index_path - find("#republish-past-prime-ministers-index").click + find("#republish-past-prime-ministers").click click_button("Confirm republishing") end diff --git a/lib/whitehall/authority/rules/miscellaneous_rules.rb b/lib/whitehall/authority/rules/miscellaneous_rules.rb index cf114b330da..bf97b4eeb48 100644 --- a/lib/whitehall/authority/rules/miscellaneous_rules.rb +++ b/lib/whitehall/authority/rules/miscellaneous_rules.rb @@ -8,7 +8,7 @@ def can?(action) end end - def can_for_republish_documents?(_action) + def can_for_republish_content?(_action) actor.gds_admin? end diff --git a/test/functional/admin/republishing_controller_test.rb b/test/functional/admin/republishing_controller_test.rb index e305fb56dd5..ef76f2d6c97 100644 --- a/test/functional/admin/republishing_controller_test.rb +++ b/test/functional/admin/republishing_controller_test.rb @@ -8,11 +8,11 @@ class Admin::RepublishingControllerTest < ActionController::TestCase should_be_an_admin_controller - view_test "GDS Admin users should be able to acess the GET :index and see links to republishable documents" do + view_test "GDS Admin users should be able to acess the GET :index and see links to republishable content" do get :index assert_select ".govuk-table__cell:nth-child(1) a[href='https://www.test.gov.uk/government/history/past-prime-ministers']", text: "Past Prime Ministers" - assert_select ".govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/past-prime-ministers/confirm']", text: "Republish 'Past Prime Ministers' page" + assert_select ".govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/page/past-prime-ministers/confirm']", text: "Republish 'Past Prime Ministers' page" assert_response :ok end @@ -23,38 +23,45 @@ class Admin::RepublishingControllerTest < ActionController::TestCase assert_response :forbidden end - test "GDS Admin users should be able to access GET :confirm with a republishable document slug" do - get :confirm, params: { document_slug: "past-prime-ministers" } + test "GDS Admin users should be able to access GET :confirm_page with a republishable page slug" do + get :confirm_page, params: { page_slug: "past-prime-ministers" } assert_response :ok end - test "GDS Admin users should see a 404 page when trying to republish a document with an unregistered document slug" do - get :confirm, params: { document_slug: "not-republishable" } + test "GDS Admin users should see a 404 page when trying to GET :confirm_page with an unregistered page slug" do + get :confirm_page, params: { page_slug: "not-republishable" } assert_response :not_found end - test "Non-GDS Admin users should not be able to access GET :confirm" do + test "Non-GDS Admin users should not be able to access GET :confirm_page" do login_as :writer - get :confirm, params: { document_slug: "past-prime-ministers" } + get :confirm_page, params: { page_slug: "past-prime-ministers" } assert_response :forbidden end - test "GDS Admin users should be able to trigger the PresentPageToPublishingWorker job with the HistoricalAccountsIndexPresenter" do + test "GDS Admin users should be able to access POST :republish_page with a republishable page slug" do PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HistoricalAccountsIndexPresenter").once - post :republish_past_prime_ministers_index + post :republish_page, params: { page_slug: "past-prime-ministers" } assert_redirected_to admin_republishing_index_path assert_equal "'Past Prime Ministers' page has been scheduled for republishing", flash[:notice] end - test "Non-GDS Admin users should not be able to republish the page" do + test "GDS Admin users should see a 404 page when trying to POST :republish_page with an unregistered page slug" do + PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HistoricalAccountsIndexPresenter").never + + get :republish_page, params: { page_slug: "not-republishable" } + assert_response :not_found + end + + test "Non-GDS Admin users should not be able to access POST :republish_page" do PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HistoricalAccountsIndexPresenter").never login_as :writer - post :republish_past_prime_ministers_index + post :republish_page, params: { page_slug: "past-prime-ministers" } assert_response :forbidden end end