From e6a080afa2e6cbd6abded0d82b2c0ca11cf54859 Mon Sep 17 00:00:00 2001 From: Bruce Bolt Date: Mon, 22 Jan 2024 12:11:04 +0000 Subject: [PATCH] Use edition links for worldwide organisation people 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. --- .../worldwide_organisation_presenter.rb | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/presenters/worldwide_organisation_presenter.rb b/app/presenters/worldwide_organisation_presenter.rb index b7f98fd07f..959529d331 100644 --- a/app/presenters/worldwide_organisation_presenter.rb +++ b/app/presenters/worldwide_organisation_presenter.rb @@ -48,14 +48,14 @@ 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 = roles_for_person(person["content_id"]) { 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: presented_title_for_roles(current_roles), } end @@ -66,12 +66,12 @@ 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 = roles_for_person(person["content_id"]) { name: person["title"], href: person["web_url"], - description: organisation_roles_for(current_roles), + description: presented_title_for_roles(current_roles), } end end @@ -128,16 +128,24 @@ def sponsoring_organisations private - def organisation_roles_for(current_appointments) - current_appointments - .map { |role_appointment| role_appointment.dig("links", "role").first } - .select { |role| organisation_role_ids.include?(role["content_id"]) } + def presented_title_for_roles(roles) + roles .map { |role| role["title"] } .compact.join(", ") end - def organisation_role_ids - content_item.dig("links", "roles")&.map { |role| role["content_id"] } || [] + 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