-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish worldwide corporate information about pages as redirects
Worldwide corporate information about pages aren't rendered, instead they are surfaced in the body of the owning worldwide organisation. There have been various attempts to devise a strategy for these pages. Currently, they are published with the `schema_name` of `placeholder_corporate_information_page` at the path `world/organisation/:organisation_id/about/about`. Unfortunately, anywhere in Whitehall that links to the base path of these pages now 404s. Instead, we should redirect to the worldwide organisation itself. This: - Updates the base path of worldwide corporate information pages to `world/organisation/:organisation_id/about` to match the non-worldwide organisation corporate information pages. - Adds a generic presenter for a redirect. - Publishes worldwide corporate information pages as redirects. This means any worldwide corporate information about pages will now live at `world/organisation/:organisation_id/about`. When we republish these content items, Pulishing API will create additional redirect from each `world/organisation/:organisation_id/about/about` to `world/organisation/:organisation_id/about` as well.
- Loading branch information
1 parent
724baed
commit 83c047d
Showing
6 changed files
with
148 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module PublishingApi | ||
class RedirectPresenter | ||
attr_accessor :item, :update_type | ||
|
||
def initialize(item, update_type: nil) | ||
self.item = item | ||
self.update_type = update_type || "major" | ||
end | ||
|
||
delegate :content_id, to: :item | ||
|
||
def content | ||
{ | ||
title: nil, | ||
locale: I18n.locale.to_s, | ||
base_path: item.public_path(locale: I18n.locale), | ||
document_type: "redirect", | ||
schema_name: "redirect", | ||
redirects:, | ||
publishing_app: Whitehall::PublishingApp::WHITEHALL, | ||
update_type:, | ||
} | ||
end | ||
|
||
def links | ||
{} | ||
end | ||
|
||
private | ||
|
||
def redirects | ||
[{ | ||
path: item.public_path(locale: I18n.locale), | ||
type: "exact", | ||
destination: item.api_presenter_redirect_to, | ||
}] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
test/unit/app/presenters/publishing_api/redirect_presenter_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require "test_helper" | ||
|
||
class PublishingApi::RedirectPresenterTest < ActiveSupport::TestCase | ||
def present(...) | ||
PublishingApi::RedirectPresenter.new(...) | ||
end | ||
|
||
test "presents an item as a redirect to the publishing API" do | ||
item = create( | ||
:corporate_information_page, | ||
:published, | ||
organisation: nil, | ||
worldwide_organisation: create(:worldwide_organisation), | ||
corporate_information_page_type_id: CorporateInformationPageType::AboutUs.id, | ||
) | ||
|
||
expected_hash = { | ||
title: nil, | ||
locale: "en", | ||
publishing_app: "whitehall", | ||
redirects: [{ | ||
path: item.base_path, | ||
type: "exact", | ||
destination: item.api_presenter_redirect_to, | ||
}], | ||
update_type: "major", | ||
base_path: item.base_path, | ||
document_type: "redirect", | ||
schema_name: "redirect", | ||
} | ||
|
||
presented_item = present(item) | ||
|
||
assert_equal item.content_id, presented_item.content_id | ||
assert_equal expected_hash, presented_item.content | ||
assert_equal presented_item.links, {} | ||
assert_valid_against_publisher_schema(presented_item.content, "redirect") | ||
end | ||
|
||
test "presents an item as a redirect to publishing API when translated" do | ||
I18n.with_locale(:ar) do | ||
item = create( | ||
:corporate_information_page, | ||
:published, | ||
organisation: nil, | ||
worldwide_organisation: create(:worldwide_organisation), | ||
corporate_information_page_type_id: CorporateInformationPageType::AboutUs.id, | ||
) | ||
|
||
expected_hash = { | ||
title: nil, | ||
locale: "ar", | ||
publishing_app: "whitehall", | ||
redirects: [{ | ||
path: item.public_path(locale: I18n.locale), | ||
type: "exact", | ||
destination: item.api_presenter_redirect_to, | ||
}], | ||
update_type: "major", | ||
base_path: item.public_path(locale: I18n.locale), | ||
document_type: "redirect", | ||
schema_name: "redirect", | ||
} | ||
|
||
presented_item = present(item) | ||
|
||
assert_equal item.content_id, presented_item.content_id | ||
assert_equal expected_hash, presented_item.content | ||
assert_equal presented_item.links, {} | ||
assert_valid_against_publisher_schema(presented_item.content, "redirect") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters