From 0793fccfa9b3c3841b5d4e51663e803d8f45283a Mon Sep 17 00:00:00 2001 From: Harriet H-W Date: Thu, 7 Nov 2024 17:28:50 +0000 Subject: [PATCH] add content id to host documents We will need this Content ID on the Content Block Manager frontend, to get preview content here https://github.com/alphagov/whitehall/pull/9640 --- app/presenters/embedded_content_presenter.rb | 1 + app/queries/get_embedded_content.rb | 2 ++ spec/integration/embedded_content_spec.rb | 1 + spec/presenters/embedded_content_presenter_spec.rb | 3 +++ spec/queries/get_embedded_content_spec.rb | 1 + 5 files changed, 8 insertions(+) diff --git a/app/presenters/embedded_content_presenter.rb b/app/presenters/embedded_content_presenter.rb index 39d12a4bd..ff2486180 100644 --- a/app/presenters/embedded_content_presenter.rb +++ b/app/presenters/embedded_content_presenter.rb @@ -33,6 +33,7 @@ def results last_edited_at: edition.last_edited_at, unique_pageviews: edition.unique_pageviews, instances: edition.instances, + host_content_id: edition.host_content_id, primary_publishing_organisation: { content_id: edition.primary_publishing_organisation_content_id, title: edition.primary_publishing_organisation_title, diff --git a/app/queries/get_embedded_content.rb b/app/queries/get_embedded_content.rb index 9c9c8a77f..7efa764d9 100644 --- a/app/queries/get_embedded_content.rb +++ b/app/queries/get_embedded_content.rb @@ -8,6 +8,7 @@ class GetEmbeddedContent :publishing_app, :last_edited_by_editor_id, :last_edited_at, + :host_content_id, :primary_publishing_organisation_content_id, :primary_publishing_organisation_title, :primary_publishing_organisation_base_path, @@ -39,6 +40,7 @@ class GetEmbeddedContent { field: TABLES[:org_editions][:title], alias: "primary_publishing_organisation_title", included_in_group?: true }, { field: TABLES[:org_editions][:base_path], alias: "primary_publishing_organisation_base_path", included_in_group?: true }, { field: TABLES[:statistics_caches][:unique_pageviews], included_in_group?: true }, + { field: TABLES[:documents][:content_id], alias: "host_content_id", included_in_group?: true }, { field: TABLES[:editions][:id].count, alias: "instances", included_in_group?: false }, ].freeze diff --git a/spec/integration/embedded_content_spec.rb b/spec/integration/embedded_content_spec.rb index 3cadbf3eb..a25f2607c 100644 --- a/spec/integration/embedded_content_spec.rb +++ b/spec/integration/embedded_content_spec.rb @@ -72,6 +72,7 @@ "last_edited_at" => last_edited_at, "unique_pageviews" => statistics_cache.unique_pageviews, "instances" => 1, + "host_content_id" => host_edition.content_id, "primary_publishing_organisation" => { "content_id" => publishing_organisation.content_id, "title" => publishing_organisation.title, diff --git a/spec/presenters/embedded_content_presenter_spec.rb b/spec/presenters/embedded_content_presenter_spec.rb index 1d2ee05cb..1060a8623 100644 --- a/spec/presenters/embedded_content_presenter_spec.rb +++ b/spec/presenters/embedded_content_presenter_spec.rb @@ -3,6 +3,7 @@ let(:organisation_edition_id) { SecureRandom.uuid } let(:target_edition_id) { SecureRandom.uuid } let(:last_edited_by_editor_id) { SecureRandom.uuid } + let(:host_content_id) { SecureRandom.uuid } let(:last_edited_at) { 2.days.ago } let(:total) { 222 } let(:total_pages) { 23 } @@ -17,6 +18,7 @@ last_edited_by_editor_id:, last_edited_at:, unique_pageviews: 123, + host_content_id:, primary_publishing_organisation_content_id: organisation_edition_id, primary_publishing_organisation_title: "bar", primary_publishing_organisation_base_path: "/bar", @@ -40,6 +42,7 @@ last_edited_at:, unique_pageviews: 123, instances: 1, + host_content_id: host_content_id, primary_publishing_organisation: { content_id: organisation_edition_id, title: "bar", diff --git a/spec/queries/get_embedded_content_spec.rb b/spec/queries/get_embedded_content_spec.rb index 8e47b8aea..cf1d8a439 100644 --- a/spec/queries/get_embedded_content_spec.rb +++ b/spec/queries/get_embedded_content_spec.rb @@ -82,6 +82,7 @@ expect(results[i].base_path).to eq(host_edition.base_path) expect(results[i].document_type).to eq(host_edition.document_type) expect(results[i].publishing_app).to eq(host_edition.publishing_app) + expect(results[i].host_content_id).to eq(host_edition.content_id) expect(results[i].primary_publishing_organisation_content_id).to eq(organisation.content_id) expect(results[i].primary_publishing_organisation_title).to eq(organisation.title) expect(results[i].primary_publishing_organisation_base_path).to eq(organisation.base_path)