From e35ec8aadbd93ae210c860fefbe36b332689fddb Mon Sep 17 00:00:00 2001 From: Bruce Bolt Date: Mon, 22 Jan 2024 16:36:04 +0000 Subject: [PATCH] Remove code for rendering non-edition links for worldwide organisations In https://github.com/alphagov/government-frontend/pull/3055, we added support for edition links associated with worldwide organisations. This change included backward compatibility for worldwide organisations without edition links. Once the worldwide organisations have all been republished without non-edition links, we no longer need the backward compatibility here. This also simplifies the code slightly, as the content item now only contains roles that are relevant to the worldwide organisation, rather than needing to filter them on the frontend. --- .../worldwide_organisation_presenter.rb | 40 +++---------------- .../worldwide_organisation_presenter_test.rb | 24 +---------- 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/app/presenters/worldwide_organisation_presenter.rb b/app/presenters/worldwide_organisation_presenter.rb index c8b2134e8..1f27b60a2 100644 --- a/app/presenters/worldwide_organisation_presenter.rb +++ b/app/presenters/worldwide_organisation_presenter.rb @@ -48,18 +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 = if person.dig("links", "role_appointments") - person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") } # To be removed once switched to edition links - else - roles_for_person(person["content_id"]) - end + 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: person.dig("links", "role_appointments") ? organisation_roles_for(current_roles) : presented_title_for_roles(current_roles), # Call to `organisation_roles_for` to be removed once switched to edition links + description: presented_title_for_roles(current_roles), } end @@ -70,16 +66,12 @@ def people_in_non_primary_roles return [] unless people.any? people.map do |person| - current_roles = if person.dig("links", "role_appointments") - person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") } # To be removed once switched to edition links - else - roles_for_person(person["content_id"]) - end + current_roles = roles_for_person(person["content_id"]) { name: person["title"], href: person["web_url"], - description: person.dig("links", "role_appointments") ? organisation_roles_for(current_roles) : presented_title_for_roles(current_roles), # Call to `organisation_roles_for` to be removed once switched to edition links + description: presented_title_for_roles(current_roles), } end end @@ -87,11 +79,7 @@ def people_in_non_primary_roles def main_office return unless (office_item = content_item.dig("links", "main_office")&.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 + office_contact_item = contact_for_office(office_item["content_id"]) return unless office_contact_item WorldwideOffice.new( @@ -107,11 +95,7 @@ def home_page_offices return [] unless content_item.dig("links", "home_page_offices") content_item.dig("links", "home_page_offices").map { |office| - 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 + contact = contact_for_office(office["content_id"]) next unless contact WorldwideOrganisation::LinkedContactPresenter.new(contact) @@ -165,18 +149,6 @@ def presented_title_for_roles(roles) .compact.join(", ") end - 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"]) } - .map { |role| role["title"] } - .compact.join(", ") - end - - def organisation_role_ids - content_item.dig("links", "roles")&.map { |role| role["content_id"] } || [] - end - def roles_for_person(person_content_id) content_item .dig("details", "people_role_associations") diff --git a/test/presenters/worldwide_organisation_presenter_test.rb b/test/presenters/worldwide_organisation_presenter_test.rb index 17054d897..cad961b01 100644 --- a/test/presenters/worldwide_organisation_presenter_test.rb +++ b/test/presenters/worldwide_organisation_presenter_test.rb @@ -5,12 +5,7 @@ def schema_name "worldwide_organisation" end - test "description of primary_role_person should have spaces between roles with non-edition links" do - presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "primary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }, { "content_id" => "2" }] } }) - assert_equal "Example Role 1, Example Role 2", presenter.person_in_primary_role[:description] - end - - test "description of primary_role_person should have spaces between roles with edition links" do + test "description of primary_role_person should have spaces between roles" do presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "details" => { "people_role_associations" => [ { @@ -62,17 +57,7 @@ def schema_name assert_equal "Example Role 1, Example Role 2", presenter.person_in_primary_role[:description] end - test "description of primary_role_person should only show roles that are associated with the organisation" do - presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "primary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }] } }) - assert_equal "Example Role 1", presenter.person_in_primary_role[:description] - end - - test "description of people_in_non_primary_roles should have spaces between roles with non-edition links" do - presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "secondary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }, { "content_id" => "2" }] } }) - assert_equal "Example Role 1, Example Role 2", presenter.people_in_non_primary_roles.first[:description] - end - - test "description of people_in_non_primary_roles should have spaces between roles with edition links" do + test "description of people_in_non_primary_roles should have spaces between roles" do presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "details" => { "people_role_associations" => [ { @@ -124,11 +109,6 @@ def schema_name assert_equal "Example Role 1, Example Role 2", presenter.people_in_non_primary_roles.first[:description] end - test "description of people_in_non_primary_roles should only show roles that are associated with the organisation" do - presenter = create_presenter(WorldwideOrganisationPresenter, content_item: { "links" => { "secondary_role_person" => [{ "details" => { "image" => {} }, "links" => { "role_appointments" => [{ "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "1", "title" => "Example Role 1" }] } }, { "details" => { "current" => true }, "links" => { "role" => [{ "content_id" => "2", "title" => "Example Role 2" }] } }] } }], "roles" => [{ "content_id" => "1" }] } }) - assert_equal "Example Role 1", presenter.people_in_non_primary_roles.first[:description] - end - test "#title returns the title" do assert_equal schema_item["title"], presented_item.title end