Skip to content

Commit

Permalink
Flatten edition links for Worldwide Organisations
Browse files Browse the repository at this point in the history
As edition links do not support multi-level or recursive link expansion,
we need to explicitly include all the sub-links that we require to
render this page.
  • Loading branch information
brucebolt committed Jan 30, 2024
1 parent 494d69e commit 35e5891
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def content
crest: "single-identity",
formatted_title: worldwide_organisation_logo_name(item),
},
office_contact_associations:,
ordered_corporate_information_pages:,
people_role_associations:,
secondary_corporate_information_pages:,
social_media_links:,
world_location_names:,
Expand All @@ -47,15 +49,17 @@ def content

def edition_links
{
contacts:,
corporate_information_pages:,
main_office:,
home_page_offices:,
primary_role_person:,
roles:,
role_appointments:,
secondary_role_person:,
office_staff:,
sponsoring_organisations:,
world_locations:,
roles:,
}
end

Expand Down Expand Up @@ -91,6 +95,10 @@ def about_us
end
end

def contacts
[item.main_office&.contact&.content_id] + item.home_page_offices&.map(&:contact)&.map(&:content_id)
end

def main_office
return [] unless item.main_office

Expand All @@ -103,6 +111,17 @@ def home_page_offices
item.home_page_offices.map(&:content_id)
end

def office_contact_associations
offices = [item.main_office] + item.home_page_offices

offices.compact.map do |office|
{
office_content_id: office.content_id,
contact_content_id: office.contact.content_id,
}
end
end

def primary_role_person
return [] unless item.primary_role

Expand All @@ -119,10 +138,29 @@ def office_staff
item.office_staff_roles.map(&:current_person).map(&:content_id)
end

def role_appointments
item.roles&.distinct&.map(&:current_role_appointment)&.compact&.map(&:content_id)
end

def roles
item.roles.distinct.pluck(:content_id)
end

def people_role_associations
people = [item.primary_role&.current_person] + [item.secondary_role&.current_person] + item.office_staff_roles.map(&:current_person)
people.compact.map do |person|
{
person_content_id: person.content_id,
role_appointments: person.role_appointments&.map do |role_appointment|
{
role_appointment_content_id: role_appointment.content_id,
role_content_id: role_appointment.role.content_id,
}
end,
}
end
end

def corporate_information_pages
return [] unless item.corporate_information_pages.any?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def present(...)
crest: "single-identity",
formatted_title: "Locationia<br/>Embassy",
},
office_contact_associations: [
{
office_content_id: worldwide_org.reload.offices.first.content_id,
contact_content_id: worldwide_org.reload.offices.first.contact.content_id,
},
],
ordered_corporate_information_pages: [
{
content_id: worldwide_org.corporate_information_pages[1].content_id,
Expand All @@ -55,6 +61,26 @@ def present(...)
title: "Working for Locationia Embassy",
},
],
people_role_associations: [
{
person_content_id: ambassador.content_id,
role_appointments: [
{
role_appointment_content_id: ambassador.roles.first.current_role_appointment.content_id,
role_content_id: ambassador.roles.first.current_role_appointment.role.content_id,
},
],
},
{
person_content_id: deputy_head_of_mission.content_id,
role_appointments: [
{
role_appointment_content_id: deputy_head_of_mission.roles.first.current_role_appointment.content_id,
role_content_id: deputy_head_of_mission.roles.first.current_role_appointment.role.content_id,
},
],
},
],
secondary_corporate_information_pages: "Read about the types of information we routinely publish in our <a class=\"govuk-link\" href=\"/world/organisations/locationia-embassy/about/publication-scheme\">Publication scheme</a>. Find out about our commitment to <a class=\"govuk-link\" href=\"/world/organisations/locationia-embassy/about/welsh-language-scheme\">publishing in Welsh</a>. Our <a class=\"govuk-link\" href=\"/world/organisations/locationia-embassy/about/personal-information-charter\">Personal information charter</a> explains how we treat your personal information.",
social_media_links: [
{
Expand All @@ -71,6 +97,9 @@ def present(...)
],
},
links: {
contacts: [
worldwide_org.reload.offices.first.contact.content_id,
],
corporate_information_pages: [
worldwide_org.corporate_information_pages[0].content_id,
worldwide_org.corporate_information_pages[1].content_id,
Expand Down Expand Up @@ -99,6 +128,9 @@ def present(...)
roles: [
ambassador.roles.first.content_id, deputy_head_of_mission.roles.first.content_id
],
role_appointments: [
ambassador.roles.first.current_role_appointment.content_id, deputy_head_of_mission.roles.first.current_role_appointment.content_id
],
},
analytics_identifier: "WO123",
update_type: "major",
Expand Down

0 comments on commit 35e5891

Please sign in to comment.