Skip to content

Commit

Permalink
Merge pull request #9675 from alphagov/content-modelling/750-dont-cre…
Browse files Browse the repository at this point in the history
…ate-drafts-in-publishing-api-on-initial-save

Don’t create edition in Publishing API initially
  • Loading branch information
pezholio authored Dec 4, 2024
2 parents c728b04 + d98cedc commit bd116fa
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 bd116fa

Please sign in to comment.