Skip to content

Commit ef6aa6a

Browse files
committed
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.
1 parent c3b86d9 commit ef6aa6a

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

app/presenters/worldwide_organisation_presenter.rb

+25-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ def people_in_non_primary_roles
8686

8787
def main_office
8888
return unless (office_item = content_item.dig("links", "main_office")&.first)
89-
return unless (office_contact_item = office_item.dig("links", "contact")&.first)
89+
90+
office_contact_item = if office_item.dig("links", "contact")
91+
office_item.dig("links", "contact")&.first # To be removed once switched to edition links
92+
else
93+
contact_for_office(office_item["content_id"])
94+
end
95+
return unless office_contact_item
9096

9197
WorldwideOffice.new(
9298
contact: WorldwideOrganisation::LinkedContactPresenter.new(office_contact_item),
@@ -101,7 +107,12 @@ def home_page_offices
101107
return [] unless content_item.dig("links", "home_page_offices")
102108

103109
content_item.dig("links", "home_page_offices").map { |office|
104-
next unless (contact = office.dig("links", "contact")&.first)
110+
contact = if office.dig("links", "contact")
111+
office.dig("links", "contact")&.first # To be removed once switched to edition links
112+
else
113+
contact_for_office(office["content_id"])
114+
end
115+
next unless contact
105116

106117
WorldwideOrganisation::LinkedContactPresenter.new(contact)
107118
}.compact
@@ -136,6 +147,18 @@ def sponsoring_organisations
136147

137148
private
138149

150+
def contact_for_office(office_content_id)
151+
contact_mapping = content_item.dig("details", "office_contact_associations").select { |office_contact_association|
152+
office_contact_association["office_content_id"] == office_content_id
153+
}.first
154+
155+
return unless contact_mapping
156+
157+
content_item.dig("links", "contacts").select { |contact|
158+
contact["content_id"] == contact_mapping["contact_content_id"]
159+
}.first
160+
end
161+
139162
def presented_title_for_roles(roles)
140163
roles
141164
.map { |role| role["title"] }

0 commit comments

Comments
 (0)