Skip to content

Commit

Permalink
Use edition links for worldwide organisation people
Browse files Browse the repository at this point in the history
We are switching worldwide organisations to use edition links which do
not support multi-level link expanstion.

Therefore we need to switch the rendering code to use the new link
fields that have been added, in the absence of multi-level links.

This change adds support for edition links, but also retains
compatibility with non-edition links. This will allow us to deploy the
frontend changes in advance of republishing the content items,
preventing any downtime of these pages. The code for backward
compatibility will be removed once the content items have all been
republished with edition links.
  • Loading branch information
brucebolt committed Jan 22, 2024
1 parent 046dccf commit c3b86d9
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 6 deletions.
36 changes: 32 additions & 4 deletions app/presenters/worldwide_organisation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ def person_in_primary_role
return unless content_item["links"]["primary_role_person"]

person = content_item.dig("links", "primary_role_person").first
current_roles = person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") }
current_roles = if person.dig("links", "role_appointments")
person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") } # To be removed once switched to edition links
else
roles_for_person(person["content_id"])
end

{
name: person["title"],
href: person["web_url"],
image_url: person["details"]["image"]["url"],
image_alt: person["details"]["image"]["alt_text"],
description: organisation_roles_for(current_roles),
description: person.dig("links", "role_appointments") ? organisation_roles_for(current_roles) : presented_title_for_roles(current_roles), # Call to `organisation_roles_for` to be removed once switched to edition links
}
end

Expand All @@ -66,12 +70,16 @@ def people_in_non_primary_roles
return [] unless people.any?

people.map do |person|
current_roles = person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") }
current_roles = if person.dig("links", "role_appointments")
person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") } # To be removed once switched to edition links
else
roles_for_person(person["content_id"])
end

{
name: person["title"],
href: person["web_url"],
description: organisation_roles_for(current_roles),
description: person.dig("links", "role_appointments") ? organisation_roles_for(current_roles) : presented_title_for_roles(current_roles), # Call to `organisation_roles_for` to be removed once switched to edition links
}
end
end
Expand Down Expand Up @@ -128,6 +136,12 @@ def sponsoring_organisations

private

def presented_title_for_roles(roles)
roles
.map { |role| role["title"] }
.compact.join(", ")
end

def organisation_roles_for(current_appointments)
current_appointments
.map { |role_appointment| role_appointment.dig("links", "role").first }
Expand All @@ -140,6 +154,20 @@ def organisation_role_ids
content_item.dig("links", "roles")&.map { |role| role["content_id"] } || []
end

def roles_for_person(person_content_id)
content_item
.dig("details", "people_role_associations")
.select { |people_role_association| people_role_association["person_content_id"] == person_content_id }
.first["role_appointments"]
.pluck("role_content_id")
.map { |role_content_id|
content_item.dig("links", "roles").select do |role|
role["content_id"] == role_content_id
end
}
.flatten
end

def world_locations
content_item.dig("links", "world_locations") || []
end
Expand Down
108 changes: 106 additions & 2 deletions test/presenters/worldwide_organisation_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,125 @@ def schema_name
"worldwide_organisation"
end

test "description of primary_role_person should have spaces between roles" do
test "description of primary_role_person should have spaces between roles with non-edition links" do
presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "primary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }, { "content_id" => "2" }] } })
assert_equal "Example Role 1, Example Role 2", presenter.person_in_primary_role[:description]
end

test "description of primary_role_person should have spaces between roles with edition links" do
presenter = create_presenter(WorldwideOrganisationPresenter, content_item: {
"details" => { "people_role_associations" => [
{
"person_content_id" => "person_1",
"role_appointments" => [
{
"role_appointment_content_id" => "role_apppointment_1",
"role_content_id" => "role_1",
},
{
"role_appointment_content_id" => "role_apppointment_2",
"role_content_id" => "role_2",
},
],
},
] },
"links" => {
"primary_role_person" => [
{
"content_id" => "person_1",
"details" => { "image" => {} },
"links" => {},
},
],
"role_appointments" => [
{
"content_id" => "role_apppointment_1",
"details" => { "current" => true },
"links" => {},
},
{
"content_id" => "role_apppointment_2",
"details" => { "current" => true },
"links" => {},
},
],
"roles" => [
{
"content_id" => "role_1",
"title" => "Example Role 1",
},
{
"content_id" => "role_2",
"title" => "Example Role 2",
},
],
},
})
assert_equal "Example Role 1, Example Role 2", presenter.person_in_primary_role[:description]
end

test "description of primary_role_person should only show roles that are associated with the organisation" do
presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "primary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }] } })
assert_equal "Example Role 1", presenter.person_in_primary_role[:description]
end

test "description of people_in_non_primary_roles should have spaces between roles" do
test "description of people_in_non_primary_roles should have spaces between roles with non-edition links" do
presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "secondary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }, { "content_id" => "2" }] } })
assert_equal "Example Role 1, Example Role 2", presenter.people_in_non_primary_roles.first[:description]
end

test "description of people_in_non_primary_roles should have spaces between roles with edition links" do
presenter = create_presenter(WorldwideOrganisationPresenter, content_item: {
"details" => { "people_role_associations" => [
{
"person_content_id" => "person_1",
"role_appointments" => [
{
"role_appointment_content_id" => "role_apppointment_1",
"role_content_id" => "role_1",
},
{
"role_appointment_content_id" => "role_apppointment_2",
"role_content_id" => "role_2",
},
],
},
] },
"links" => {
"secondary_role_person" => [
{
"content_id" => "person_1",
"details" => { "image" => {} },
"links" => {},
},
],
"role_appointments" => [
{
"content_id" => "role_apppointment_1",
"details" => { "current" => true },
"links" => {},
},
{
"content_id" => "role_apppointment_2",
"details" => { "current" => true },
"links" => {},
},
],
"roles" => [
{
"content_id" => "role_1",
"title" => "Example Role 1",
},
{
"content_id" => "role_2",
"title" => "Example Role 2",
},
],
},
})
assert_equal "Example Role 1, Example Role 2", presenter.people_in_non_primary_roles.first[:description]
end

test "description of people_in_non_primary_roles should only show roles that are associated with the organisation" do
presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "secondary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }] } })
assert_equal "Example Role 1", presenter.people_in_non_primary_roles.first[:description]
Expand Down

0 comments on commit c3b86d9

Please sign in to comment.