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 bulk republishing all documents #9091

Merged
merged 2 commits into from
May 30, 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 @@ -3,6 +3,13 @@ module Admin::RepublishingHelper

def bulk_content_type_metadata
@bulk_content_type_metadata ||= {
all_documents: {
id: "all-documents",
name: "all documents",
republishing_path: admin_bulk_republishing_all_republish_path("all-documents"),
confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents"),
republish_method: -> { BulkRepublisher.new.republish_all_documents },
},
all_organisation_about_us_pages: {
id: "all-organisation-about-us-pages",
name: "all organisation 'About Us' pages",
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 @@ -9,6 +9,7 @@ class RepublishingEvent < ApplicationRecord
validates :bulk_content_type, presence: true, if: -> { bulk }

enum :bulk_content_type, %i[
all_documents
all_organisation_about_us_pages
]
end
6 changes: 6 additions & 0 deletions app/services/bulk_republisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ def republish_all_organisation_about_us_pages
)
end
end

def republish_all_documents
Document.find_each do |document|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document.id, true)
end
end
end
7 changes: 6 additions & 1 deletion features/bulk-republishing-content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ Feature: Bulk republishing content
Background:
Given I am a GDS admin

Scenario: Republish all documents
Given Documents exist
When I request a bulk republishing of all documents
Then I can see that all documents have been queued for republishing

Scenario: Republish all Organisation "About Us" pages
Given Published Organisation "About Us" pages exist
Given Organisation "About Us" pages exist
When I request a bulk republishing of the Organisation "About Us" pages
Then I can see the Organisation "About Us" pages have been queued for republishing
17 changes: 16 additions & 1 deletion features/step_definitions/bulk_republishing_content_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
Given(/^Published Organisation "About Us" pages exist$/) do
Given(/^Documents exist$/) do
2.times { create(:document) }
end

When(/^I request a bulk republishing of all documents$/) do
visit admin_republishing_index_path
find("#all-documents").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 have been queued for republishing$/) do
expect(page).to have_selector(".gem-c-success-alert", text: "All documents have been queued for republishing")
end

Given(/^Organisation "About Us" pages exist$/) do
2.times { create(:about_corporate_information_page) }
end

Expand Down
3 changes: 2 additions & 1 deletion test/functional/admin/republishing_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
assert_select ".govuk-table:nth-of-type(2) .govuk-table__body .govuk-table__row:nth-child(3) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/role/find']", text: "Republish a role"
assert_select ".govuk-table:nth-of-type(2) .govuk-table__body .govuk-table__row:nth-child(4) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/document/find']", text: "Republish a document"

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-organisation-about-us-pages/confirm']", text: "Republish all organisation 'About Us' pages"
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-organisation-about-us-pages/confirm']", text: "Republish all organisation 'About Us' pages"

assert_response :ok
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/app/helpers/admin/republishing_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class Admin::RepublishingHelperTest < ActionView::TestCase
end

test "#republishing_index_bulk_republishing_rows capitalises the first letter of the bulk content type" do
assert_equal @first_row.first[:text], "All organisation 'About Us' pages"
assert_equal @first_row.first[:text], "All documents"
end

test "#republishing_index_bulk_republishing_rows creates a link to the specific bulk republishing confirmation page" do
expected_link = '<a id="all-organisation-about-us-pages" class="govuk-link" href="/government/admin/republishing/bulk/all-organisation-about-us-pages/confirm">Republish <span class="govuk-visually-hidden">all organisation \'About Us\' pages</span></a>'
expected_link = '<a id="all-documents" class="govuk-link" href="/government/admin/republishing/bulk/all-documents/confirm">Republish <span class="govuk-visually-hidden">all documents</span></a>'
assert_equal @first_row[1][:text], expected_link
end
end
17 changes: 17 additions & 0 deletions test/unit/app/services/bulk_republisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,21 @@ class BulkRepublisherTest < ActiveSupport::TestCase
BulkRepublisher.new.republish_all_organisation_about_us_pages
end
end

describe "#republish_all_documents" do
test "queues all documents for republishing" do
queue_sequence = sequence("queue")

2.times do
document = create(:document)

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", document.id, true)
.in_sequence(queue_sequence)
end

BulkRepublisher.new.republish_all_documents
end
end
end