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

Add UI for republishing all documents with publicly-visible editions with attachments #9099

Merged
merged 2 commits into from
Jun 3, 2024
Merged
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
7 changes: 7 additions & 0 deletions app/helpers/admin/republishing_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_attachments: {
id: "all-documents-with-publicly-visible-editions-with-attachments",
name: "all documents with publicly-visible editions with attachments",
republishing_path: admin_bulk_republishing_all_republish_path("all-documents-with-publicly-visible-editions-with-attachments"),
confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents-with-publicly-visible-editions-with-attachments"),
republish_method: -> { BulkRepublisher.new.republish_all_documents_with_publicly_visible_editions_with_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",
Expand Down
1 change: 1 addition & 0 deletions app/models/republishing_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_attachments
all_documents_with_publicly_visible_editions_with_html_attachments
all_published_organisation_about_us_pages
]
Expand Down
9 changes: 9 additions & 0 deletions app/services/bulk_republisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_attachments
document_ids = Edition
.publicly_visible
.where(id: Attachment.where(attachable_type: "Edition").select(:attachable_id))
.pluck(:document_id)

republish_by_document_ids(document_ids)
end

def republish_all_documents_with_publicly_visible_editions_with_html_attachments
document_ids = Edition
.publicly_visible
Expand Down
5 changes: 5 additions & 0 deletions features/bulk-republishing-content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 attachments
Given Documents with publicly-visible editions with attachments exist
When I request a bulk republishing of all documents with publicly-visible editions with attachments
Then I can see that all documents with publicly-visible editions with 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
Expand Down
18 changes: 18 additions & 0 deletions features/step_definitions/bulk_republishing_content_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 attachments exist$/) do
2.times do
document = create(:document, editions: [build(:published_edition), build(:draft_edition)])
create(: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 attachments$/) do
visit admin_republishing_index_path
find("#all-documents-with-publicly-visible-editions-with-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 attachments have been queued for republishing$/) do
expect(page).to have_selector(".gem-c-success-alert", text: "All documents with publicly-visible editions with 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)])
Expand Down
5 changes: 3 additions & 2 deletions test/functional/admin/republishing_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ 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-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_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-attachments/confirm']", text: "Republish all documents with publicly-visible editions with 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-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(6) .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
Expand Down
98 changes: 70 additions & 28 deletions test/unit/app/services/bulk_republisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,6 @@
class BulkRepublisherTest < ActiveSupport::TestCase
extend Minitest::Spec::DSL

describe "#republish_all_published_organisation_about_us_pages" do
test "queues all published organisation 'About us' pages for republishing" do
queue_sequence = sequence("queue")

2.times do
about_us_page = create(:about_corporate_information_page)

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", about_us_page.document_id, true)
.in_sequence(queue_sequence)
end

BulkRepublisher.new.republish_all_published_organisation_about_us_pages
end

test "doesn't queue draft organisation 'About us' pages for republishing" do
about_us_page = create(:draft_about_corporate_information_page)

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", about_us_page.document_id, true)
.never

BulkRepublisher.new.republish_all_published_organisation_about_us_pages
end
end

describe "#republish_all_documents" do
test "queues all documents for republishing" do
queue_sequence = sequence("queue")
Expand Down Expand Up @@ -118,6 +90,48 @@ class BulkRepublisherTest < ActiveSupport::TestCase
end
end

describe "#republish_all_documents_with_publicly_visible_editions_with_attachments" do
test "queues all documents with publicly-visible editions with attachments for republishing" do
queue_sequence = sequence("queue")

2.times do
document = create(:document, editions: [build(:published_edition), build(:draft_edition)])
create(: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_attachments
end

test "doesn't queue documents for republishing if the editions with attachments aren't publicly-visible editions" do
draft_edition = build(:draft_edition)
document = create(:document, editions: [draft_edition])
create(: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_attachments
end

test "doesn't queue documents republishing when there are publicly-visible editions but none have 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_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")
Expand Down Expand Up @@ -159,4 +173,32 @@ class BulkRepublisherTest < ActiveSupport::TestCase
BulkRepublisher.new.republish_all_documents_with_publicly_visible_editions_with_html_attachments
end
end

describe "#republish_all_published_organisation_about_us_pages" do
test "queues all published organisation 'About us' pages for republishing" do
queue_sequence = sequence("queue")

2.times do
about_us_page = create(:about_corporate_information_page)

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", about_us_page.document_id, true)
.in_sequence(queue_sequence)
end

BulkRepublisher.new.republish_all_published_organisation_about_us_pages
end

test "doesn't queue draft organisation 'About us' pages for republishing" do
about_us_page = create(:draft_about_corporate_information_page)

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", about_us_page.document_id, true)
.never

BulkRepublisher.new.republish_all_published_organisation_about_us_pages
end
end
end