From fcc7bcb5895970992a95a4d50c7fc196a4381f57 Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Fri, 31 May 2024 14:28:26 +0100 Subject: [PATCH] Add UI for republishing docs w/ public ed w/ HTML Add UI for republishing all documents with publicly-visible editions with HTML attachments --- app/helpers/admin/republishing_helper.rb | 7 ++++ app/models/republishing_event.rb | 1 + app/services/bulk_republisher.rb | 9 ++++ features/bulk-republishing-content.feature | 5 +++ .../bulk_republishing_content_steps.rb | 18 ++++++++ .../admin/republishing_controller_test.rb | 3 +- .../app/services/bulk_republisher_test.rb | 42 +++++++++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) diff --git a/app/helpers/admin/republishing_helper.rb b/app/helpers/admin/republishing_helper.rb index 4516f9f2246..8ce6860f56c 100644 --- a/app/helpers/admin/republishing_helper.rb +++ b/app/helpers/admin/republishing_helper.rb @@ -24,6 +24,13 @@ def bulk_content_type_metadata confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents-with-pre-publication-editions-with-html-attachments"), republish_method: -> { BulkRepublisher.new.republish_all_documents_with_pre_publication_editions_with_html_attachments }, }, + all_documents_with_publicly_visible_editions_with_html_attachments: { + id: "all-documents-with-publicly-visible-editions-with-html-attachments", + name: "all documents with publicly-visible editions with HTML attachments", + republishing_path: admin_bulk_republishing_all_republish_path("all-documents-with-publicly-visible-editions-with-html-attachments"), + confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents-with-publicly-visible-editions-with-html-attachments"), + republish_method: -> { BulkRepublisher.new.republish_all_documents_with_publicly_visible_editions_with_html_attachments }, + }, all_published_organisation_about_us_pages: { id: "all-published-organisation-about-us-pages", name: "all published organisation 'About us' pages", diff --git a/app/models/republishing_event.rb b/app/models/republishing_event.rb index c3ea1b0c6e0..3db8f6c3137 100644 --- a/app/models/republishing_event.rb +++ b/app/models/republishing_event.rb @@ -12,6 +12,7 @@ class RepublishingEvent < ApplicationRecord all_documents all_documents_with_pre_publication_editions all_documents_with_pre_publication_editions_with_html_attachments + all_documents_with_publicly_visible_editions_with_html_attachments all_published_organisation_about_us_pages ] end diff --git a/app/services/bulk_republisher.rb b/app/services/bulk_republisher.rb index d4132f54bbd..7b0050d484e 100644 --- a/app/services/bulk_republisher.rb +++ b/app/services/bulk_republisher.rb @@ -23,6 +23,15 @@ def republish_all_documents_with_pre_publication_editions_with_html_attachments republish_by_document_ids(document_ids) end + def republish_all_documents_with_publicly_visible_editions_with_html_attachments + document_ids = Edition + .publicly_visible + .where(id: HtmlAttachment.where(attachable_type: "Edition").select(:attachable_id)) + .pluck(:document_id) + + republish_by_document_ids(document_ids) + end + private def republish_by_document_ids(document_ids) diff --git a/features/bulk-republishing-content.feature b/features/bulk-republishing-content.feature index 6a4544313c4..bfcfe1b5ce0 100644 --- a/features/bulk-republishing-content.feature +++ b/features/bulk-republishing-content.feature @@ -21,6 +21,11 @@ Feature: Bulk republishing content When I request a bulk republishing of all documents with pre-publication editions with HTML attachments Then I can see that all documents with pre-publication editions with HTML attachments have been queued for republishing + Scenario: Republish all documents with publicly-visible editions with HTML attachments + Given Documents with publicly-visible editions with HTML attachments exist + When I request a bulk republishing of all documents with publicly-visible editions with HTML attachments + Then I can see that all documents with publicly-visible editions with HTML attachments have been queued for republishing + Scenario: Republish all published Organisation "About us" pages Given Published organisation "About us" pages exist When I request a bulk republishing of all published organisation "About us" pages diff --git a/features/step_definitions/bulk_republishing_content_steps.rb b/features/step_definitions/bulk_republishing_content_steps.rb index 8d691ef0fac..e7489a2bf06 100644 --- a/features/step_definitions/bulk_republishing_content_steps.rb +++ b/features/step_definitions/bulk_republishing_content_steps.rb @@ -47,6 +47,24 @@ expect(page).to have_selector(".gem-c-success-alert", text: "All documents with pre-publication editions with HTML attachments have been queued for republishing") end +Given(/^Documents with publicly-visible editions with HTML attachments exist$/) do + 2.times do + document = create(:document, editions: [build(:published_edition), build(:draft_edition)]) + create(:html_attachment, attachable_type: "Edition", attachable_id: document.live_edition.id) + end +end + +When(/^I request a bulk republishing of all documents with publicly-visible editions with HTML attachments$/) do + visit admin_republishing_index_path + find("#all-documents-with-publicly-visible-editions-with-html-attachments").click + fill_in "What is the reason for republishing?", with: "It needs republishing" + click_button("Confirm republishing") +end + +Then(/^I can see that all documents with publicly-visible editions with HTML attachments have been queued for republishing$/) do + expect(page).to have_selector(".gem-c-success-alert", text: "All documents with publicly-visible editions with HTML attachments have been queued for republishing") +end + Given(/^Published organisation "About us" pages exist$/) do 2.times { create(:about_corporate_information_page) } end diff --git a/test/functional/admin/republishing_controller_test.rb b/test/functional/admin/republishing_controller_test.rb index a66622b44be..a0e2ff052c3 100644 --- a/test/functional/admin/republishing_controller_test.rb +++ b/test/functional/admin/republishing_controller_test.rb @@ -22,7 +22,8 @@ class Admin::RepublishingControllerTest < ActionController::TestCase assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-documents/confirm']", text: "Republish all documents" assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(2) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-documents-with-pre-publication-editions/confirm']", text: "Republish all documents with pre-publication editions" assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(3) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-documents-with-pre-publication-editions-with-html-attachments/confirm']", text: "Republish all documents with pre-publication editions with HTML attachments" - assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(4) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-published-organisation-about-us-pages/confirm']", text: "Republish all published organisation 'About us' pages" + assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(4) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-documents-with-publicly-visible-editions-with-html-attachments/confirm']", text: "Republish all documents with publicly-visible editions with HTML attachments" + assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(5) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-published-organisation-about-us-pages/confirm']", text: "Republish all published organisation 'About us' pages" assert_response :ok end diff --git a/test/unit/app/services/bulk_republisher_test.rb b/test/unit/app/services/bulk_republisher_test.rb index e5e74da5afb..6a0f064a80e 100644 --- a/test/unit/app/services/bulk_republisher_test.rb +++ b/test/unit/app/services/bulk_republisher_test.rb @@ -117,4 +117,46 @@ class BulkRepublisherTest < ActiveSupport::TestCase BulkRepublisher.new.republish_all_documents_with_pre_publication_editions_with_html_attachments end end + + describe "#republish_all_documents_with_publicly_visible_editions_with_html_attachments" do + test "queues all documents with publicly-visible editions with HTML attachments for republishing" do + queue_sequence = sequence("queue") + + 2.times do + document = create(:document, editions: [build(:published_edition), build(:draft_edition)]) + create(:html_attachment, attachable_type: "Edition", attachable_id: document.live_edition.id) + + PublishingApiDocumentRepublishingWorker + .expects(:perform_async_in_queue) + .with("bulk_republishing", document.id, true) + .in_sequence(queue_sequence) + end + + BulkRepublisher.new.republish_all_documents_with_publicly_visible_editions_with_html_attachments + end + + test "doesn't queue documents for republishing if the editions with HTML attachments aren't publicly-visible editions" do + draft_edition = build(:draft_edition) + document = create(:document, editions: [draft_edition]) + create(:html_attachment, attachable_type: "Edition", attachable_id: draft_edition.id) + + PublishingApiDocumentRepublishingWorker + .expects(:perform_async_in_queue) + .with("bulk_republishing", document.id, true) + .never + + BulkRepublisher.new.republish_all_documents_with_publicly_visible_editions_with_html_attachments + end + + test "doesn't queue documents republishing when there are publicly-visible editions but none have HTML attachments" do + document = create(:document, editions: [build(:published_edition), build(:draft_edition)]) + + PublishingApiDocumentRepublishingWorker + .expects(:perform_async_in_queue) + .with("bulk_republishing", document.id, true) + .never + + BulkRepublisher.new.republish_all_documents_with_publicly_visible_editions_with_html_attachments + end + end end