diff --git a/app/commands/v2/patch_link_set.rb b/app/commands/v2/patch_link_set.rb index d8d1348a4..dcc2e10e3 100644 --- a/app/commands/v2/patch_link_set.rb +++ b/app/commands/v2/patch_link_set.rb @@ -4,7 +4,7 @@ class PatchLinkSet < BaseCommand def call raise_unless_links_hash_is_provided check_bulk_publishing_present - validate_schema + validate_schema if validate_schema? link_set = LinkSet.find_or_create_locked(content_id:) check_version_and_raise_if_conflicting(link_set, previous_version_number) @@ -140,6 +140,12 @@ def downstream_live(content_id, locale, orphaned_content_ids, update_dependencie ) end + def validate_schema? + return true unless payload.key?(:validate_schema) + + payload[:validate_schema] + end + def validate_schema # We allow setting links before the document actually exists. # This means we blindly accept anything regardless of what the schema says. diff --git a/docs/api.md b/docs/api.md index c1a925eb1..463fb0d0f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -155,7 +155,7 @@ presented edition and [warnings](#warnings). - `update_type` *(optional)* - Accepts: "major", "minor", "republish" - It is acceptable to send a "minor" update for the first ever draft -- `bulk_publishing` *(optional, default: false)* +- `bulk_publishing` *(required)* - Set this to true when making multiple requests. Publishing API will use a lower priority queue to avoid delays to standard publishing activity. @@ -464,7 +464,7 @@ it wants to defer to a reusable piece of content, such as an email address. - [`content_id`](model.md#content_id) - Identifies the target document for the reusable piece of content - + ### Query parameters - `order` *(optional, default: "unique_pageviews")* @@ -476,7 +476,7 @@ it wants to defer to a reusable piece of content, such as an email address. ## `GET /v2/content/:content_id/host-content/:host_content_id` -Returns metadata for a single item of content with ID `:host_content_id` that has an embedded reference to +Returns metadata for a single item of content with ID `:host_content_id` that has an embedded reference to the target `:content_id`. ### Path parameters @@ -525,10 +525,14 @@ in the request is preserved. } } ``` +- `bulk_publishing` *(required)* + - Set this to true when making multiple requests. Publishing API will use a lower priority queue to avoid delays to standard publishing activity. - `previous_version` *(optional, recommended)* - Used to ensure that we are updating the current version of the link set. -- `bulk_publishing` *(optional, default: false)* - - Set this to true when making multiple requests. Publishing API will use a lower priority queue to avoid delays to standard publishing activity. +- `validate_schema` *(optional, default: true)* + - Set to false to skip validation of links against the content schema for + the current payload. After changing a document's document type, allows + for removal of links of types unsupported. ### State changes diff --git a/spec/commands/v2/patch_link_set_spec.rb b/spec/commands/v2/patch_link_set_spec.rb index 048ab5ae8..1ddb03b34 100644 --- a/spec/commands/v2/patch_link_set_spec.rb +++ b/spec/commands/v2/patch_link_set_spec.rb @@ -501,5 +501,34 @@ end end + context "when an edition exists for the content_id" do + before do + create( + :edition, + document: create(:document, content_id:), + base_path: "/some-path", + title: "Some Title", + ) + end + + context "when called with validate: false in the payload" do + before { payload[:validate_schema] = false } + + it "skips validation" do + expect_any_instance_of(described_class).not_to receive(:validate_schema) + + described_class.call(payload) + end + end + + context "when called without :validate in the payload" do + it "validates the payload against the schema" do + expect_any_instance_of(described_class).to receive(:validate_schema) + + described_class.call(payload) + end + end + end + it_behaves_like TransactionalCommand end