Skip to content

Commit d83dada

Browse files
Add rich text field to school profile
1 parent 972bf13 commit d83dada

File tree

8 files changed

+41
-13
lines changed

8 files changed

+41
-13
lines changed

app/models/organisation.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
require "digest"
22

33
class Organisation < ApplicationRecord
4+
self.ignored_columns += %w[description]
5+
46
before_save :update_searchable_content
57

68
include PgSearch::Model
79
extend FriendlyId
810

11+
has_rich_text :description
12+
913
SPECIAL_SCHOOL_TYPES = ["Community special school", "Foundation special school", "Non-maintained special school", "Academy special converter", "Academy special sponsor led", "Free schools special"].freeze
1014
NON_FAITH_RELIGIOUS_CHARACTER_TYPES = ["", "None", "Does not apply", "null"].freeze
1115
OUT_OF_SCOPE_DETAILED_SCHOOL_TYPES = ["Further education", "Other independent school", "Miscellaneous", "Special post 16 institution", "Other independent special school", "Higher education institutions", "Welsh establishment"].freeze
@@ -141,7 +145,7 @@ def has_ofsted_report?
141145
end
142146

143147
def profile_complete?
144-
%i[email description safeguarding_information logo photo url].all? { |attribute| send(attribute).present? }
148+
%i[email safeguarding_information logo photo url].all? { |attr| send(attr).present? } && description.body.present?
145149
end
146150

147151
def self.update_all_searchable_content!

app/views/publishers/organisations/_organisation.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
- summary_list.with_row(html_attributes: { id: "description" }) do |row|
4545
- row.with_key text: t("publishers.organisations.organisation.description.label.#{organisation.school? ? :school : :organisation}")
4646
- row.with_value do
47-
= required_profile_info(value: truncate(organisation.description, length: 130), missing_prompt: t("publishers.organisations.organisation.description.missing_prompt.#{organisation.school? ? :school : :organisation}"))
47+
= required_profile_info(value: truncate(organisation.description.to_plain_text, length: 130), missing_prompt: t("publishers.organisations.organisation.description.missing_prompt.#{organisation.school? ? :school : :organisation}"))
4848
- row.with_action text: t("buttons.change"), href: edit_publishers_organisation_description_path(organisation), classes: "govuk-link--no-visited-state", visually_hidden_text: t("publishers.organisations.organisation.description.label.#{organisation.school? ? :school : :organisation}")
4949

5050
- summary_list.with_row(html_attributes: { id: "safeguarding_information" }) do |row|

app/views/publishers/organisations/description/edit.html.slim

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
- if params["vacancy_id"]
1313
= f.hidden_field "vacancy_id", value: params["vacancy_id"]
1414

15-
= f.govuk_text_area :description,
16-
label: { text: t("helpers.label.publishers_organisation_form.description", organisation_type: organisation_type_basic(@organisation)), size: "s" },
17-
hint: { text: t("helpers.hint.publishers_organisation_form.description", organisation_type: organisation_type_basic(@organisation)) },
18-
rows: 10
15+
.govuk-form-group
16+
= f.label :description, t("helpers.label.publishers_organisation_form.description", organisation_type: organisation_type_basic(@organisation)), class: "govuk-label govuk-label--s"
17+
18+
.govuk-hint
19+
= t("helpers.hint.publishers_organisation_form.description", organisation_type: organisation_type_basic(@organisation))
1920

20-
= f.govuk_submit t("buttons.save_changes")
21+
div class="school-description-form"
22+
= f.rich_text_area :description, aria: { label: t("helpers.label.publishers_organisation_form.description"), required: true }, class: "govuk-!-margin-bottom-6"
23+
24+
noscript
25+
= f.govuk_text_area :description, rows: 10, class: "govuk-!-margin-bottom-6"
26+
27+
= f.govuk_submit t("buttons.save_changes")

config/analytics.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ shared:
242242
- id
243243
- type
244244
- name
245-
- description
246245
- safeguarding_information
247246
- urn
248247
- uid
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class MigrateSchoolDescriptionToRichText < ActiveRecord::Migration[8.0]
2+
def up
3+
Organisation.find_each do |org|
4+
old_text = org.read_attribute(:description)
5+
next if old_text.blank?
6+
7+
org.update!(description: old_text)
8+
end
9+
end
10+
11+
def down
12+
Organisation.find_each do |org|
13+
if org.description.body.present?
14+
org.update_column(:description, org.description.body.to_html)
15+
end
16+
end
17+
end
18+
end

db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2026_01_20_090246) do
13+
ActiveRecord::Schema[8.0].define(version: 2026_01_29_140738) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "btree_gist"
1616
enable_extension "citext"

spec/views/organisations/show.html.slim_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
end
7979

8080
it "displays the organisation's description" do
81-
expect(show_view).to have_content(organisation.description)
81+
expect(show_view).to have_content(organisation.description.to_plain_text)
8282
end
8383

8484
it "displays the organisation's safeguarding information" do

spec/views/publishers/organisations/preview.html.slim_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
end
1717

1818
it "displays the organisation's description" do
19-
expect(rendered).to have_content(organisation.description)
19+
expect(rendered).to have_content(organisation.description.to_plain_text)
2020
end
2121

2222
it "displays the organisation's safeguarding information" do
@@ -48,7 +48,7 @@
4848
end
4949

5050
it "displays the organisation's description" do
51-
expect(rendered).to have_content(organisation.description)
51+
expect(rendered).to have_content(organisation.description.to_plain_text)
5252
end
5353

5454
it "displays the organisation's safeguarding information" do
@@ -82,7 +82,7 @@
8282
end
8383

8484
it "displays the organisation's description" do
85-
expect(rendered).to have_content(school_one.description)
85+
expect(rendered).to have_content(school_one.description.to_plain_text)
8686
end
8787

8888
it "displays the organisation's safeguarding information" do

0 commit comments

Comments
 (0)