From ef6aa6a4ea9c40d62501838c03ceb0df7f505958 Mon Sep 17 00:00:00 2001 From: Bruce Bolt Date: Mon, 22 Jan 2024 13:38:15 +0000 Subject: [PATCH] Use edition links for worldwide organisation offices 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. --- .../worldwide_organisation_presenter.rb | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/app/presenters/worldwide_organisation_presenter.rb b/app/presenters/worldwide_organisation_presenter.rb index c4296b927..c8b2134e8 100644 --- a/app/presenters/worldwide_organisation_presenter.rb +++ b/app/presenters/worldwide_organisation_presenter.rb @@ -86,7 +86,13 @@ def people_in_non_primary_roles def main_office return unless (office_item = content_item.dig("links", "main_office")&.first) - return unless (office_contact_item = office_item.dig("links", "contact")&.first) + + office_contact_item = if office_item.dig("links", "contact") + office_item.dig("links", "contact")&.first # To be removed once switched to edition links + else + contact_for_office(office_item["content_id"]) + end + return unless office_contact_item WorldwideOffice.new( contact: WorldwideOrganisation::LinkedContactPresenter.new(office_contact_item), @@ -101,7 +107,12 @@ def home_page_offices return [] unless content_item.dig("links", "home_page_offices") content_item.dig("links", "home_page_offices").map { |office| - next unless (contact = office.dig("links", "contact")&.first) + contact = if office.dig("links", "contact") + office.dig("links", "contact")&.first # To be removed once switched to edition links + else + contact_for_office(office["content_id"]) + end + next unless contact WorldwideOrganisation::LinkedContactPresenter.new(contact) }.compact @@ -136,6 +147,18 @@ def sponsoring_organisations private + def contact_for_office(office_content_id) + contact_mapping = content_item.dig("details", "office_contact_associations").select { |office_contact_association| + office_contact_association["office_content_id"] == office_content_id + }.first + + return unless contact_mapping + + content_item.dig("links", "contacts").select { |contact| + contact["content_id"] == contact_mapping["contact_content_id"] + }.first + end + def presented_title_for_roles(roles) roles .map { |role| role["title"] }