Skip to content

Commit

Permalink
Merge pull request #3057 from alphagov/remove-wworg-non-edition-links
Browse files Browse the repository at this point in the history
Remove code for rendering non-edition links for worldwide organisations
  • Loading branch information
brucebolt authored Jan 30, 2024
2 parents 93adc09 + e35ec8a commit 232596f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 56 deletions.
40 changes: 6 additions & 34 deletions app/presenters/worldwide_organisation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -70,28 +66,20 @@ 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

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(
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
24 changes: 2 additions & 22 deletions test/presenters/worldwide_organisation_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => [
{
Expand Down Expand Up @@ -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" => [
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 232596f

Please sign in to comment.