Skip to content

Commit

Permalink
Do not publish about us Corporate Information Pages for Worldwide Orgs
Browse files Browse the repository at this point in the history
We don't show the "about us" Corporate Information Pages related to Worldwide
Organisations anywhere except as the body of the Worldwide Organisation
itself.

To prevent these appearing as separate pages, we want to avoid publishing them
altogether.

This:
- Prevents publishing is the Corporate Information Page is an about page
  associated with a Worldwide Organisation
- Prevents the republishing of parent "about us" Corporate Information Page
  when a child is published (Corporate Information Pages can have related
  Corporate Information Pages).
  • Loading branch information
jkempster34 committed Jun 14, 2023
1 parent 9efe70b commit 40c2e4d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/corporate_information_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def republish_owning_organisation_to_publishing_api
end

def republish_about_page_to_publishing_api
return if worldwide_organisation.present?

about_us = owning_organisation&.about_us
return unless about_us

Expand All @@ -50,6 +52,10 @@ def reindex_organisation_in_search_index
owning_organisation.update_in_search_index
end

def publish_to_publishing_api?
!(worldwide_organisation.present? && about_page?)
end

def body_required?
!about_page?
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/edition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def attachables
[]
end

def publish_to_publishing_api?
true
end

def skip_main_validation?
FROZEN_STATES.include?(state)
end
Expand Down
2 changes: 2 additions & 0 deletions app/services/edition_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def notify!
end

def update_publishing_api!
return unless edition.publish_to_publishing_api?

ServiceListeners::PublishingApiPusher
.new(edition.reload)
.push(event: verb, options:)
Expand Down
15 changes: 15 additions & 0 deletions test/integration/publishing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ class PublishingTest < ActiveSupport::TestCase
assert_all_requested(requests)
end

test "When a Worldwide CorporateInformationPage about us page is published, it does not get published with the Publishing API" do
worldwide_organisation = create(:worldwide_organisation)
corporate_information_page = create(
:corporate_information_page,
organisation: nil, worldwide_organisation:,
corporate_information_page_type: CorporateInformationPageType::AboutUs
)
presenter = PublishingApiPresenters.presenter_for(corporate_information_page)

perform_force_publishing_for(corporate_information_page)

assert_not_requested(stub_publishing_api_put_content(presenter.content_id, presenter.content))
assert_not_requested(stub_publishing_api_publish(presenter.content_id, locale: "en", update_type: nil))
end

test "When a translated edition is published, all translations are published with the Publishing API" do
french_requests = I18n.with_locale :fr do
@draft_edition.title = "French title"
Expand Down
19 changes: 19 additions & 0 deletions test/unit/corporate_information_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,25 @@ def self.should_be_invalid_without(type, attribute_name)
other_page.touch
end

test "does not republish the 'About Us' CIP if another CIP is saved when owning organisation is a `WorldwideOrganisation`" do
worldwide_organisation = create(:worldwide_organisation)
about_us = create(
:corporate_information_page,
:published,
worldwide_organisation:,
organisation: nil,
corporate_information_page_type_id: CorporateInformationPageType::AboutUs.id,
)
other_page = create(
:corporate_information_page,
:published,
worldwide_organisation:,
organisation: nil,
)
PublishingApiDocumentRepublishingWorker.expects(:perform_async_in_queue).with("bulk_republishing", about_us.document_id, true).never
other_page.touch
end

test "does not republish the 'About Us' CIP if it is saved" do
org = create(:organisation, govuk_status: "live")
about_us = create(
Expand Down
34 changes: 34 additions & 0 deletions test/unit/models/corporate_information_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,38 @@ class CorporateInformationPageTest < ActiveSupport::TestCase

corporate_information_page.update!(body: "new body")
end

test "#publishes_to_publishing_api? is true when owning organisation is an `Organisation`" do
organisation = create(:organisation)
corporate_information_page = create(
:corporate_information_page,
organisation:,
worldwide_organisation: nil,
corporate_information_page_type: CorporateInformationPageType::AboutUs,
)

assert corporate_information_page.publish_to_publishing_api?
end

test "#publishes_to_publishing_api? is true when owning organisation is an `WorldwideOrganisation` and is not about page" do
worldwide_organisation = create(:worldwide_organisation)
corporate_information_page = create(
:corporate_information_page,
organisation: nil, worldwide_organisation:,
corporate_information_page_type: CorporateInformationPageType::TermsOfReference
)

assert corporate_information_page.publish_to_publishing_api?
end

test "#publishes_to_publishing_api? is false when owning organisation is an `WorldwideOrganisation` and is an about page" do
worldwide_organisation = create(:worldwide_organisation)
corporate_information_page = create(
:corporate_information_page,
organisation: nil, worldwide_organisation:,
corporate_information_page_type: CorporateInformationPageType::AboutUs
)

assert_not corporate_information_page.publish_to_publishing_api?
end
end

0 comments on commit 40c2e4d

Please sign in to comment.