From 1258da8bcfcb4c8617e879c52f8d32bfc4f3d0ec Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Tue, 2 Jan 2024 09:47:58 +0000 Subject: [PATCH 1/6] Add title method to worldwide organisation The new editionable worldwide organisation model uses the `title` method instead of `name`. This adds `title` to the legacy worldwide organisation model so that views and helpers etc. can be compatible with both model types. --- app/models/worldwide_organisation.rb | 1 + test/unit/app/models/worldwide_organisation_test.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/models/worldwide_organisation.rb b/app/models/worldwide_organisation.rb index 00c9478bf45..10e334da20e 100644 --- a/app/models/worldwide_organisation.rb +++ b/app/models/worldwide_organisation.rb @@ -32,6 +32,7 @@ class WorldwideOrganisation < ApplicationRecord translates :name alias_method :original_main_office, :main_office + alias_method :title, :name validates_with SafeHtmlValidator validates :name, presence: true diff --git a/test/unit/app/models/worldwide_organisation_test.rb b/test/unit/app/models/worldwide_organisation_test.rb index 715085c2aae..a933320abd7 100644 --- a/test/unit/app/models/worldwide_organisation_test.rb +++ b/test/unit/app/models/worldwide_organisation_test.rb @@ -382,4 +382,10 @@ class WorldwideOrganisationTest < ActiveSupport::TestCase organisation.update!(name: "new name") end + + test "#title returns the name of the organisation" do + organisation = create(:worldwide_organisation) + + assert_equal organisation.name, organisation.title + end end From ea7f1bfa7206e99566c398915882c90bf30f0484 Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Thu, 28 Dec 2023 16:54:42 +0000 Subject: [PATCH 2/6] Use the `worldwide_organisation` document type We don't need a new document type here, we can use the existing one. --- .../editionable_worldwide_organisation_presenter.rb | 2 +- .../editionable_worldwide_organisation_presenter_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb b/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb index 5780bb88687..c5dfb8761bd 100644 --- a/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb +++ b/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb @@ -25,7 +25,7 @@ def content crest: "single-identity", }, }, - document_type: item.class.name.underscore, + document_type: "worldwide_organisation", public_updated_at: item.updated_at, rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND, schema_name: "worldwide_organisation", diff --git a/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb b/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb index ae734453b11..b82aaec22f1 100644 --- a/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb @@ -14,7 +14,7 @@ def present(...) base_path: public_path, title: worldwide_org.title, schema_name: "worldwide_organisation", - document_type: "editionable_worldwide_organisation", + document_type: "worldwide_organisation", locale: "en", publishing_app: Whitehall::PublishingApp::WHITEHALL, rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND, From 0f279bf6b6fdad527469d28afaae12b559da4f0f Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Fri, 29 Dec 2023 11:59:01 +0000 Subject: [PATCH 3/6] Add logo formatted name to editions This is required for editionable worldwide organisations. --- app/controllers/admin/editions_controller.rb | 1 + .../20231228163205_add_logo_formatted_name_to_editions.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20231228163205_add_logo_formatted_name_to_editions.rb diff --git a/app/controllers/admin/editions_controller.rb b/app/controllers/admin/editions_controller.rb index 0a35150a30d..61bbea33cd2 100644 --- a/app/controllers/admin/editions_controller.rb +++ b/app/controllers/admin/editions_controller.rb @@ -228,6 +228,7 @@ def permitted_edition_attributes :read_consultation_principles, :all_nation_applicability, :speaker_radios, + :logo_formatted_name, { all_nation_applicability: [], secondary_specialist_sector_tags: [], diff --git a/db/migrate/20231228163205_add_logo_formatted_name_to_editions.rb b/db/migrate/20231228163205_add_logo_formatted_name_to_editions.rb new file mode 100644 index 00000000000..01e2b4ead81 --- /dev/null +++ b/db/migrate/20231228163205_add_logo_formatted_name_to_editions.rb @@ -0,0 +1,5 @@ +class AddLogoFormattedNameToEditions < ActiveRecord::Migration[7.0] + def change + add_column :editions, :logo_formatted_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 7c7d379de34..caa771d0ce7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_12_19_154010) do +ActiveRecord::Schema[7.0].define(version: 2023_12_28_163205) do create_table "assets", charset: "utf8mb3", force: :cascade do |t| t.string "asset_manager_id", null: false t.string "variant", null: false @@ -395,6 +395,7 @@ t.string "auth_bypass_id", null: false t.string "mapped_specialist_topic_content_id" t.string "taxonomy_topic_email_override" + t.string "logo_formatted_name" t.index ["alternative_format_provider_id"], name: "index_editions_on_alternative_format_provider_id" t.index ["closing_at"], name: "index_editions_on_closing_at" t.index ["document_id"], name: "index_editions_on_document_id" From 730e9d17e3804fa376e975779af6951d9a4dae3a Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Tue, 2 Jan 2024 09:51:44 +0000 Subject: [PATCH 4/6] Present logo formatted title for worldwide organisations These have been broken for some time. They remained broken when the rendering of these pages was moved to Government Frontend. Presenting these correctly will allow us to fix them on the frontend and restore their proper functionality. --- app/helpers/organisation_helper.rb | 8 ++++++++ .../worldwide_organisation_presenter.rb | 4 +++- .../worldwide_organisation_presenter_test.rb | 20 ++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/helpers/organisation_helper.rb b/app/helpers/organisation_helper.rb index 987b4aefa2e..e729703e097 100644 --- a/app/helpers/organisation_helper.rb +++ b/app/helpers/organisation_helper.rb @@ -15,6 +15,14 @@ def organisation_logo_name(organisation, stacked: true) end end + def worldwide_organisation_logo_name(organisation) + if I18n.locale == :en && organisation.logo_formatted_name.present? + format_with_html_line_breaks(ERB::Util.html_escape(organisation.logo_formatted_name)) + else + organisation.title + end + end + def organisation_type_name(organisation) ActiveSupport::Inflector.singularize(organisation.organisation_type.name.downcase) end diff --git a/app/presenters/publishing_api/worldwide_organisation_presenter.rb b/app/presenters/publishing_api/worldwide_organisation_presenter.rb index 50711ca8f9f..ebf99f81fff 100644 --- a/app/presenters/publishing_api/worldwide_organisation_presenter.rb +++ b/app/presenters/publishing_api/worldwide_organisation_presenter.rb @@ -2,6 +2,8 @@ module PublishingApi class WorldwideOrganisationPresenter include Rails.application.routes.url_helpers include ActionView::Helpers::UrlHelper + include ApplicationHelper + include OrganisationHelper attr_accessor :item, :update_type, :state @@ -26,7 +28,7 @@ def content body:, logo: { crest: "single-identity", - formatted_title: item.logo_formatted_name, + formatted_title: worldwide_organisation_logo_name(item), }, ordered_corporate_information_pages:, secondary_corporate_information_pages:, diff --git a/test/unit/app/presenters/publishing_api/worldwide_organisation_presenter_test.rb b/test/unit/app/presenters/publishing_api/worldwide_organisation_presenter_test.rb index 98e87d30a78..bf7f6cdd6a9 100644 --- a/test/unit/app/presenters/publishing_api/worldwide_organisation_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/worldwide_organisation_presenter_test.rb @@ -43,7 +43,7 @@ def present(...) body: "

Some stuff

\n
", logo: { crest: "single-identity", - formatted_title: "Locationia\nEmbassy", + formatted_title: "Locationia
Embassy", }, ordered_corporate_information_pages: [ { @@ -159,4 +159,22 @@ def present(...) ], presented_item.content[:routes] end end + + test "uses the title for the formatted_title when the locale is not en" do + I18n.with_locale(:it) do + worldwide_org = create(:worldwide_organisation, name: "Consolato Generale Britannico Milano") + + presented_item = present(worldwide_org) + + assert_equal "Consolato Generale Britannico Milano", presented_item.content.dig(:details, :logo, :formatted_title) + end + end + + test "uses the title for the formatted_title when the the logo_formatted_name is absent" do + worldwide_org = create(:worldwide_organisation) + + presented_item = present(worldwide_org) + + assert_equal worldwide_org.name, presented_item.content.dig(:details, :logo, :formatted_title) + end end From a77c94bd0f87808ea9b20af07d721731bec40100 Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Tue, 2 Jan 2024 09:52:13 +0000 Subject: [PATCH 5/6] Present logo formatted name for editionable worldwide organisations The presenter isn't currently valid against the schema because it's missing the logo formatted name. --- ...onable_worldwide_organisation_presenter.rb | 3 +++ .../editionable_worldwide_organisations.rb | 3 ++- ...e_worldwide_organisation_presenter_test.rb | 23 ++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb b/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb index c5dfb8761bd..bc692892967 100644 --- a/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb +++ b/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb @@ -2,6 +2,8 @@ module PublishingApi class EditionableWorldwideOrganisationPresenter include Rails.application.routes.url_helpers include ActionView::Helpers::UrlHelper + include ApplicationHelper + include OrganisationHelper attr_accessor :item, :update_type, :state @@ -23,6 +25,7 @@ def content details: { logo: { crest: "single-identity", + formatted_title: worldwide_organisation_logo_name(item), }, }, document_type: "worldwide_organisation", diff --git a/test/factories/editionable_worldwide_organisations.rb b/test/factories/editionable_worldwide_organisations.rb index 89d7b371bc2..04caa4e0846 100644 --- a/test/factories/editionable_worldwide_organisations.rb +++ b/test/factories/editionable_worldwide_organisations.rb @@ -1,6 +1,7 @@ FactoryBot.define do factory :editionable_worldwide_organisation, class: EditionableWorldwideOrganisation, parent: :edition_with_organisations do - title { "editionable-worldwide-organisation-title" } + title { "Editionable worldwide organisation title" } + logo_formatted_name { title.to_s.split.join("\n") } after :build do |news_article, evaluator| if evaluator.world_locations.empty? diff --git a/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb b/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb index b82aaec22f1..43f1b4b99e3 100644 --- a/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb @@ -24,6 +24,7 @@ def present(...) details: { logo: { crest: "single-identity", + formatted_title: "Editionable
worldwide
organisation
title", }, }, update_type: "major", @@ -41,11 +42,27 @@ def present(...) assert_equal "major", presented_item.update_type assert_equal worldwide_org.content_id, presented_item.content_id - # TODO: uncomment the below assertion when the editionable_worldwide_organisation model is - # finished and all content can be added to this presenter. - # assert_valid_against_publisher_schema(presented_item.content, "worldwide_organisation") + assert_valid_against_publisher_schema(presented_item.content, "worldwide_organisation") assert_equal expected_links, presented_item.links assert_valid_against_links_schema({ links: presented_item.links }, "worldwide_organisation") end + + test "uses the title for the formatted_title when the locale is not en" do + I18n.with_locale(:it) do + worldwide_org = create(:editionable_worldwide_organisation, title: "Consolato Generale Britannico Milano") + + presented_item = present(worldwide_org) + + assert_equal "Consolato Generale Britannico Milano", presented_item.content.dig(:details, :logo, :formatted_title) + end + end + + test "uses the title for the formatted_title when the the logo_formatted_name is absent" do + worldwide_org = create(:editionable_worldwide_organisation, logo_formatted_name: nil) + + presented_item = present(worldwide_org) + + assert_equal "Editionable worldwide organisation title", presented_item.content.dig(:details, :logo, :formatted_title) + end end From b56a787573d38ec9594ba5640184a31e24a628fa Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Fri, 29 Dec 2023 12:56:39 +0000 Subject: [PATCH 6/6] Add logo formatted name textarea for editionable worldwide organisations This allows users to add a logo formatted name for the new editionable worldwide organisations. --- .../_form.html.erb | 12 ++++++++++++ features/editionable-worldwide-organisations.feature | 2 ++ .../editionable_worldwide_organisation_steps.rb | 2 ++ features/support/document_helper.rb | 1 + 4 files changed, 17 insertions(+) diff --git a/app/views/admin/editionable_worldwide_organisations/_form.html.erb b/app/views/admin/editionable_worldwide_organisations/_form.html.erb index fc0a3cfa263..e17700b233a 100644 --- a/app/views/admin/editionable_worldwide_organisations/_form.html.erb +++ b/app/views/admin/editionable_worldwide_organisations/_form.html.erb @@ -1,4 +1,16 @@ <%= standard_edition_form(edition) do |form| %> + <%= render "govuk_publishing_components/components/textarea", { + label: { + text: "Logo formatted name", + heading_size: "l", + }, + name: "edition[logo_formatted_name]", + id: "edition_logo_formatted_name", + value: edition.logo_formatted_name, + error_items: errors_for(edition.errors, :logo_formatted_name), + rows: 4, + } %> + <%= render "govuk_publishing_components/components/fieldset", { legend_text: "Associations", heading_level: 2, diff --git a/features/editionable-worldwide-organisations.feature b/features/editionable-worldwide-organisations.feature index 38e8e0f7241..d5670547300 100644 --- a/features/editionable-worldwide-organisations.feature +++ b/features/editionable-worldwide-organisations.feature @@ -8,9 +8,11 @@ Feature: Editionable worldwide organisations When I draft a new worldwide organisation "Test Worldwide Organisation" assigned to world location "United Kingdom" Then the worldwide organisation "Test Worldwide Organisation" should have been created And I should see it has been assigned to the "United Kingdom" world location + And I should see the editionable worldwide organisation "Test Worldwide Organisation" in the list of draft documents Scenario Outline: Assigning a role to a worldwide organisation Given a role "Prime Minister" exists When I draft a new worldwide organisation "Test Worldwide Organisation" assigned to world location "United Kingdom" And I edit the worldwide organisation "Test Worldwide Organisation" adding the role of "Prime Minister" Then I should see the "Prime Minister" role has been assigned to the worldwide organisation "Test Worldwide Organisation" + diff --git a/features/step_definitions/editionable_worldwide_organisation_steps.rb b/features/step_definitions/editionable_worldwide_organisation_steps.rb index 37e3e3c1da0..ca2e5e6bcd5 100644 --- a/features/step_definitions/editionable_worldwide_organisation_steps.rb +++ b/features/step_definitions/editionable_worldwide_organisation_steps.rb @@ -10,7 +10,9 @@ Then(/^the worldwide organisation "([^"]*)" should have been created$/) do |title| @worldwide_organisation = EditionableWorldwideOrganisation.find_by(title:) + expect(@worldwide_organisation).to be_present + expect(@worldwide_organisation.logo_formatted_name).to eq("Logo\r\nformatted\r\nname\r\n") end And(/^I should see it has been assigned to the "([^"]*)" world location$/) do |title| diff --git a/features/support/document_helper.rb b/features/support/document_helper.rb index 4b926fa08d4..80b61e6c2b7 100644 --- a/features/support/document_helper.rb +++ b/features/support/document_helper.rb @@ -114,6 +114,7 @@ def pdf_attachment def fill_in_worldwide_organisation_fields(world_location: "United Kingdom") select world_location, from: "World locations" + fill_in "Logo formatted name", with: "Logo\r\nformatted\r\nname\r\n" end def fill_in_news_article_fields(first_published: "2010-01-01", announcement_type: "News story")