Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use edition links for worldwide organisations #8734

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ def content
crest: "single-identity",
formatted_title: worldwide_organisation_logo_name(item),
},
office_contact_associations:,
people_role_associations:,
social_media_links:,
world_location_names:,
},
document_type:,
links: edition_links,
public_updated_at: item.updated_at,
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND,
schema_name: "worldwide_organisation",
Expand All @@ -41,12 +44,14 @@ def content
content.merge!(PayloadBuilder::AnalyticsIdentifier.for(item))
end

def links
def edition_links
{
contacts:,
office_staff:,
main_office:,
home_page_offices:,
primary_role_person:,
role_appointments: item.roles.map(&:current_role_appointment)&.compact&.map(&:content_id),
roles: item.roles.map(&:content_id),
secondary_role_person:,
sponsoring_organisations: item.organisations.map(&:content_id),
Expand All @@ -58,6 +63,19 @@ def document_type
"worldwide_organisation"
end

def links
{
home_page_offices: [],
main_office: [],
office_staff: [],
primary_role_person: [],
roles: [],
secondary_role_person: [],
sponsoring_organisations: [],
world_locations: [],
}
end

private

def body
Expand All @@ -80,6 +98,36 @@ def home_page_offices
item.home_page_offices.map(&:content_id)
end

def contacts
[item.main_office&.contact&.content_id] + item.home_page_offices&.map(&:contact)&.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 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 primary_role_person
return [] unless item.primary_role

Expand Down
59 changes: 56 additions & 3 deletions app/presenters/publishing_api/worldwide_organisation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ 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:,
},
document_type: item.class.name.underscore,
links: edition_links,
public_updated_at: item.updated_at,
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND,
schema_name: "worldwide_organisation",
Expand All @@ -44,17 +47,33 @@ def content
content.merge!(PayloadBuilder::AnalyticsIdentifier.for(item))
end

def links
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

def links
{
corporate_information_pages: [],
main_office: [],
home_page_offices: [],
primary_role_person: [],
secondary_role_person: [],
office_staff: [],
sponsoring_organisations: [],
world_locations: [],
roles: [],
}
end

Expand All @@ -76,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 @@ -88,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 @@ -104,14 +138,33 @@ 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?

item.corporate_information_pages.map(&:content_id)
item.corporate_information_pages.published.map(&:content_id)
end

def ordered_corporate_information_pages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ def present(...)
crest: "single-identity",
formatted_title: "Editionable<br/>worldwide<br/>organisation<br/>title",
},
office_contact_associations: [
{
office_content_id: worldwide_org.reload.offices.first.content_id,
contact_content_id: worldwide_org.reload.offices.first.contact.content_id,
},
],
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,
},
],
},
],
social_media_links: [
{
href: worldwide_org.social_media_accounts.first.url,
Expand All @@ -56,25 +82,41 @@ def present(...)
},
],
},
links: {
contacts: [
worldwide_org.reload.offices.first.contact.content_id,
],
main_office: [
worldwide_org.reload.offices.first.content_id,
],
home_page_offices: [],
office_staff: worldwide_org.office_staff_roles.map(&:current_person).map(&:content_id),
primary_role_person: [
ambassador.content_id,
],
role_appointments: [
ambassador.roles.first.current_role_appointment.content_id, deputy_head_of_mission.roles.first.current_role_appointment.content_id
],
roles: worldwide_org.roles.map(&:content_id),
secondary_role_person: [
deputy_head_of_mission.content_id,
],
sponsoring_organisations: worldwide_org.organisations.map(&:content_id),
world_locations: worldwide_org.world_locations.map(&:content_id),
},
analytics_identifier: "WO123",
update_type: "major",
}

expected_links = {
main_office: [
worldwide_org.reload.offices.first.content_id,
],
main_office: [],
home_page_offices: [],
office_staff: worldwide_org.office_staff_roles.map(&:current_person).map(&:content_id),
primary_role_person: [
ambassador.content_id,
],
roles: worldwide_org.roles.map(&:content_id),
secondary_role_person: [
deputy_head_of_mission.content_id,
],
sponsoring_organisations: worldwide_org.organisations.map(&:content_id),
world_locations: worldwide_org.world_locations.map(&:content_id),
primary_role_person: [],
secondary_role_person: [],
office_staff: [],
sponsoring_organisations: [],
world_locations: [],
roles: [],
}

presented_item = present(worldwide_org)
Expand Down
Loading
Loading