Skip to content

Commit

Permalink
WIP Add UI for republishing docs w/ pre-pub ed w/ HTML
Browse files Browse the repository at this point in the history
Add UI for republishing all documents with pre-publication editions with
HTML attachments
  • Loading branch information
yndajas committed May 30, 2024
1 parent 7e1ae28 commit d81003f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/helpers/admin/republishing_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def bulk_content_type_metadata
confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents-with-pre-publication-editions"),
republish_method: -> { BulkRepublisher.new.republish_all_documents_with_pre_publication_editions },
},
all_documents_with_pre_publication_editions_with_html_attachments: {
id: "all-documents-with-pre-publication-editions-with-html-attachments",
name: "all documents with pre-publication editions with HTML attachments",
republishing_path: admin_bulk_republishing_all_republish_path("all-documents-with-pre-publication-editions-with-html-attachments"),
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_published_organisation_about_us_pages: {
id: "all-published-organisation-about-us-pages",
name: "all published 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 @@ -11,6 +11,7 @@ class RepublishingEvent < ApplicationRecord
enum :bulk_content_type, %i[
all_documents
all_documents_with_pre_publication_editions
all_documents_with_pre_publication_editions_with_html_attachments
all_published_organisation_about_us_pages
]
end
11 changes: 11 additions & 0 deletions app/services/bulk_republisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ def republish_all_documents_with_pre_publication_editions
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", edition.document.id, true)
end
end

def republish_all_documents_with_pre_publication_editions_with_html_attachments
document_ids = Edition
.in_pre_publication_state
.where(id: HtmlAttachment.where(attachable_type: "Edition").select(:attachable_id))
.pluck(:document_id)

document_ids.each do |document_id|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document_id, true)
end
end
end
42 changes: 42 additions & 0 deletions test/unit/app/services/bulk_republisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,46 @@ class BulkRepublisherTest < ActiveSupport::TestCase
BulkRepublisher.new.republish_all_documents_with_pre_publication_editions
end
end

describe "#republish_all_documents_with_pre_publication_editions_with_html_attachments" do
test "queues all documents with pre-publication editions with HTML attachments for republishing" do
queue_sequence = sequence("queue")

2.times do
draft_edition = build(:draft_edition)
document_with_pre_publication_edition_with_html_attachment = create(:document, editions: [build(:published_edition), draft_edition])
create(:html_attachment, attachable_type: "Edition", attachable_id: draft_edition.id)

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

BulkRepublisher.new.republish_all_documents_with_pre_publication_editions_with_html_attachments
end

test "doesn't queue documents for republishing if the editions with HTML attachments aren't pre-publication editions" do
document = create(:document, editions: [build(:published_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)
.never

BulkRepublisher.new.republish_all_documents_with_pre_publication_editions_with_html_attachments
end

test "doesn't queue documents republishing when there are pre-publication 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_pre_publication_editions_with_html_attachments
end
end
end

0 comments on commit d81003f

Please sign in to comment.