Skip to content

Commit

Permalink
Don’t create edition in Publishing API initially
Browse files Browse the repository at this point in the history
In #9509 we decided to create
draft editions in Publishing API as soon as they were created at our
end on the assumption that we’d need the content block to be in the
draft content store for previewing to work.

However, we’ve since discovered that if a user creates a Document with
an initial draft that they do not publish, this gets deleted by the
`DeleteDraftContentBlocksWorker` without deleting the draft in
Publishing API. This causes a discrepancy between the Content Block
Manager and Publishing API.

Additionally, the way we handle previews doesn’t involve the draft
content store at all, so instead of making the job to delete drafts
more complex, we remove the call the `create_draft_edition` altogether
and wait until the end of the journey to send the block to Publishing
API
  • Loading branch information
pezholio committed Nov 29, 2024
1 parent c96225d commit d98cedc
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,6 @@ def schedule_with_rollback
end
end

def create_draft_edition(schema)
raise ArgumentError, "Local database changes not given" unless block_given?

ActiveRecord::Base.transaction do
content_block_edition = yield
content_id = content_block_edition.document.content_id
content_id_alias = content_block_edition.document.content_id_alias
organisation_id = content_block_edition.lead_organisation.content_id

create_publishing_api_edition(
content_id:,
content_id_alias:,
schema_id: schema.id,
title: content_block_edition.title,
instructions_to_publishers: content_block_edition.instructions_to_publishers,
details: content_block_edition.details.to_h,
links: {
primary_publishing_organisation: [
organisation_id,
],
},
)
end
end

def update_content_block_document(new_content_block_edition:, update_document_params:)
# Updates to a Document should never change its block type
update_document_params.delete(:block_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ def initialize(schema)
end

def call(edition_params, document_id: nil)
create_draft_edition(@schema) do
@new_edition = build_edition(edition_params, document_id)
@new_edition.assign_attributes(edition_params)
@new_edition.save!
@new_edition
end
@new_edition = build_edition(edition_params, document_id)
@new_edition.assign_attributes(edition_params)
@new_edition.save!
@new_edition
end

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ class ContentBlockManager::CreateEditionServiceTest < ActiveSupport::TestCase
assert_equal new_edition.lead_organisation.id, organisation.id
end

it "sends the content block to the Publishing API as a draft" do
assert_draft_created_in_publishing_api(content_id:, content_id_alias: new_title.parameterize) do
ContentBlockManager::CreateEditionService.new(schema).call(edition_params)
end
end

describe "when a document id is provided" do
let(:document) { create(:content_block_document, :email_address) }
let!(:previous_edition) { create(:content_block_edition, :email_address, document:) }
Expand All @@ -80,35 +74,6 @@ class ContentBlockManager::CreateEditionServiceTest < ActiveSupport::TestCase
assert_equal new_edition.document_id, document.id
assert_equal new_edition.lead_organisation.id, organisation.id
end

it "sends the content block to the Publishing API as a draft" do
assert_draft_created_in_publishing_api(content_id: document.content_id, content_id_alias: document.content_id_alias) do
ContentBlockManager::CreateEditionService.new(schema).call(edition_params, document_id: document.id)
end
end
end
end
end

def assert_draft_created_in_publishing_api(content_id:, content_id_alias:, &block)
Services.publishing_api.expects(:put_content).with(
content_id,
{
schema_name: schema.id,
document_type: schema.id,
publishing_app: Whitehall::PublishingApp::WHITEHALL,
title: new_title,
content_id_alias:,
details: edition_params[:details],
instructions_to_publishers: edition_params[:instructions_to_publishers],
links: {
primary_publishing_organisation: [
organisation.content_id,
],
},
update_type: "major",
},
)

block.call
end

0 comments on commit d98cedc

Please sign in to comment.