diff --git a/app/controllers/support/cases/confirm_organisation_controller.rb b/app/controllers/support/cases/confirm_organisation_controller.rb
index 2e9489a23..a7aac55d0 100644
--- a/app/controllers/support/cases/confirm_organisation_controller.rb
+++ b/app/controllers/support/cases/confirm_organisation_controller.rb
@@ -20,7 +20,12 @@ def update
private
def get_organisation
- type = params[:type] == Support::EstablishmentGroup.name ? Support::EstablishmentGroup : Support::Organisation
+ type =
+ case params[:type]
+ when "Support::Organisation" then Support::Organisation
+ when "Support::EstablishmentGroup" then Support::EstablishmentGroup
+ when "LocalAuthority" then LocalAuthority
+ end
type.find(params[:id])
end
end
diff --git a/app/controllers/support/cases/school_details/participating_schools_controller.rb b/app/controllers/support/cases/school_details/participating_schools_controller.rb
index d01451a40..f4ab28fb1 100644
--- a/app/controllers/support/cases/school_details/participating_schools_controller.rb
+++ b/app/controllers/support/cases/school_details/participating_schools_controller.rb
@@ -4,7 +4,7 @@ module SchoolDetails
class ParticipatingSchoolsController < Cases::ApplicationController
def show
@back_url = support_case_school_details_path
- @participating_schools = @current_case.participating_schools.map { |s| Support::OrganisationPresenter.new(s) }
+ @participating_schools = @current_case.participating_schools.includes([:local_authority]).map { |s| Support::OrganisationPresenter.new(s) }
end
def edit
diff --git a/app/controllers/support/concerns/filter_parameters.rb b/app/controllers/support/concerns/filter_parameters.rb
index 6697a8766..6380f9f8c 100644
--- a/app/controllers/support/concerns/filter_parameters.rb
+++ b/app/controllers/support/concerns/filter_parameters.rb
@@ -45,6 +45,7 @@ def permitted_params
:level,
:sort_by,
:sort_order,
+ :exact_match,
{
category: [],
agent: [],
diff --git a/app/controllers/support/establishments_controller.rb b/app/controllers/support/establishments_controller.rb
index 8d02cc3ef..1ee8a058a 100644
--- a/app/controllers/support/establishments_controller.rb
+++ b/app/controllers/support/establishments_controller.rb
@@ -3,7 +3,7 @@ class EstablishmentsController < ::ApplicationController
def index
respond_to do |format|
format.json do
- render json: EstablishmentSearch.omnisearch(params[:q]).as_json
+ render json: EstablishmentSearch.omnisearch(params[:q]).as_json(methods: %i[autocomplete_template])
end
end
end
diff --git a/app/helpers/school_picker_helper.rb b/app/helpers/school_picker_helper.rb
index a4be27d91..36bed26e5 100644
--- a/app/helpers/school_picker_helper.rb
+++ b/app/helpers/school_picker_helper.rb
@@ -18,7 +18,7 @@ def show_school_picker_phase_filters?(organisations)
end
def show_school_picker_la_filters?(organisations)
- organisations.pluck(:local_authority).uniq.length > 1
+ organisations.map(&:local_authority).uniq.length > 1
end
def show_school_picker_filters?(organisations)
diff --git a/app/helpers/support/case_helper.rb b/app/helpers/support/case_helper.rb
index d1283bb8f..16fa499f1 100644
--- a/app/helpers/support/case_helper.rb
+++ b/app/helpers/support/case_helper.rb
@@ -1,7 +1,7 @@
module Support
module CaseHelper
def other_cases_by_case_org_path(case_organisation, back_to:)
- support_case_search_index_path(search_case_form: { search_term: case_organisation.name, state: Support::Case.states.keys.excluding("closed") }, back_to:)
+ support_case_search_index_path(search_case_form: { search_term: case_organisation.name, state: Support::Case.states.keys.excluding("closed"), exact_match: true }, back_to:)
end
def other_cases_by_case_org_exist?(case_organisation)
diff --git a/app/models/case_request/school_pickable.rb b/app/models/case_request/school_pickable.rb
index c7d020415..a18d69d4f 100644
--- a/app/models/case_request/school_pickable.rb
+++ b/app/models/case_request/school_pickable.rb
@@ -19,7 +19,7 @@ def selected_schools
end
def eligible_for_school_picker?
- return false unless organisation.is_a?(Support::EstablishmentGroup)
+ return false unless organisation.class.in?([Support::EstablishmentGroup, LocalAuthority])
organisation.eligible_for_school_picker?
end
diff --git a/app/models/case_request/school_picker.rb b/app/models/case_request/school_picker.rb
index 7921a9b62..8527a1293 100644
--- a/app/models/case_request/school_picker.rb
+++ b/app/models/case_request/school_picker.rb
@@ -1,5 +1,6 @@
class CaseRequest::SchoolPicker
include ActiveModel::Model
+ include CaseRequest::SchoolPicker::Presentable
attr_accessor(
:case_request,
diff --git a/app/models/case_request/school_picker/presentable.rb b/app/models/case_request/school_picker/presentable.rb
new file mode 100644
index 000000000..129cbcce3
--- /dev/null
+++ b/app/models/case_request/school_picker/presentable.rb
@@ -0,0 +1,10 @@
+module CaseRequest::SchoolPicker::Presentable
+ extend ActiveSupport::Concern
+
+ def organisation_type
+ case case_request.organisation_type
+ when "Support::EstablishmentGroup" then "academy trust or federation"
+ when "LocalAuthority" then "local authority"
+ end
+ end
+end
diff --git a/app/models/local_authority.rb b/app/models/local_authority.rb
index 4fc0ce24e..6e5378c56 100644
--- a/app/models/local_authority.rb
+++ b/app/models/local_authority.rb
@@ -3,4 +3,8 @@ class LocalAuthority < ApplicationRecord
validates :la_code, uniqueness: true
validates :name, uniqueness: true
+
+ def eligible_for_school_picker?
+ organisations.count > 1
+ end
end
diff --git a/app/models/support/case/filtering.rb b/app/models/support/case/filtering.rb
index d061f4a01..b3b14062d 100644
--- a/app/models/support/case/filtering.rb
+++ b/app/models/support/case/filtering.rb
@@ -16,6 +16,7 @@ class Support::Case::Filtering
attribute :legacy_stage, default: -> { [] }
attribute :sort_by
attribute :sort_order
+ attribute :exact_match, default: -> { false }
validates :search_term,
presence: true,
@@ -48,7 +49,7 @@ def filters
level: Support::Concerns::ScopeFilter.new(level, scope: :by_level),
procurement_stage: Support::Concerns::ScopeFilter.new(procurement_stage, scope: :by_procurement_stage),
has_org: Support::Concerns::ScopeFilter.new(ActiveModel::Type::Boolean.new.cast(has_org), scope: :by_has_org, multiple: false),
- search_term: Support::Concerns::ScopeFilter.new(search_term, scope: :by_search_term, multiple: false),
+ search_term: Support::Concerns::ScopeFilterForSearch.new(search_term, exact_match: ActiveModel::Type::Boolean.new.cast(exact_match)),
legacy_stage: Support::Concerns::ScopeFilter.new(legacy_stage, scope: :by_legacy_stage),
}
end
diff --git a/app/models/support/case/searchable.rb b/app/models/support/case/searchable.rb
index 86806745d..6d4fe9163 100644
--- a/app/models/support/case/searchable.rb
+++ b/app/models/support/case/searchable.rb
@@ -4,6 +4,6 @@ module Support::Case::Searchable
included do
has_many :support_case_searches, class_name: "Support::CaseSearch"
- scope :by_search_term, ->(terms) { joins(:support_case_searches).merge(Support::CaseSearch.find_a_case(terms)) }
+ scope :by_search_term, ->(terms, exact_match: false) { joins(:support_case_searches).merge(Support::CaseSearch.find_a_case(terms, exact_match:)) }
end
end
diff --git a/app/models/support/case_search.rb b/app/models/support/case_search.rb
index 5a5fab268..d1a518283 100644
--- a/app/models/support/case_search.rb
+++ b/app/models/support/case_search.rb
@@ -6,17 +6,20 @@ class CaseSearch < ApplicationRecord
find_a_case(query).limit(30)
}
- scope :find_a_case, lambda { |query|
+ scope :find_a_case, lambda { |query, exact_match: false|
+ comp = exact_match ? "=" : "LIKE"
+ query_str = exact_match ? query.downcase : "#{query.downcase}%"
+
sql = <<-SQL
- lower(organisation_name) LIKE :q OR
- lower(case_email) LIKE :q OR
- lower(organisation_urn) LIKE :q OR
- lower(agent_first_name) LIKE :q OR
- lower(agent_last_name) LIKE :q
+ lower(organisation_name) #{comp} :q OR
+ lower(case_email) #{comp} :q OR
+ lower(organisation_urn) #{comp} :q OR
+ lower(agent_first_name) #{comp} :q OR
+ lower(agent_last_name) #{comp} :q
SQL
where("case_ref = ?", sprintf("%06d", query.to_i))
- .or(where(sql, q: "#{query.downcase}%"))
+ .or(where(sql, q: query_str))
.order("case_ref DESC")
}
end
diff --git a/app/models/support/concerns/scope_filter_for_search.rb b/app/models/support/concerns/scope_filter_for_search.rb
new file mode 100644
index 000000000..f8da5c2b1
--- /dev/null
+++ b/app/models/support/concerns/scope_filter_for_search.rb
@@ -0,0 +1,20 @@
+class Support::Concerns::ScopeFilterForSearch
+ def initialize(value, exact_match: false)
+ @value = value
+ @exact_match = exact_match
+ end
+
+ def filter(records)
+ return records unless entered?
+
+ records.send(:by_search_term, value, exact_match:)
+ end
+
+ def entered?
+ value.present?
+ end
+
+private
+
+ attr_reader :value, :exact_match
+end
diff --git a/app/models/support/establishment_search.rb b/app/models/support/establishment_search.rb
index edfd20e6f..1949827a6 100644
--- a/app/models/support/establishment_search.rb
+++ b/app/models/support/establishment_search.rb
@@ -1,9 +1,12 @@
module Support
class EstablishmentSearch < ApplicationRecord
+ include Presentable
+
scope :omnisearch, lambda { |query|
sql = <<-SQL
urn LIKE :q OR
ukprn LIKE :q OR
+ code LIKE :q OR
lower(name) LIKE lower(:q) OR
lower(postcode) LIKE lower(:q)
SQL
diff --git a/app/models/support/establishment_search/presentable.rb b/app/models/support/establishment_search/presentable.rb
new file mode 100644
index 000000000..30911bf20
--- /dev/null
+++ b/app/models/support/establishment_search/presentable.rb
@@ -0,0 +1,16 @@
+module Support::EstablishmentSearch::Presentable
+ extend ActiveSupport::Concern
+
+ def autocomplete_template
+ ApplicationController.render(partial: "support/establishment_search/#{source.underscore}/autocomplete_template", locals: autocomplete_template_vars)
+ end
+
+private
+
+ def autocomplete_template_vars
+ case source
+ when "LocalAuthority" then { name:, establishment_type:, code: }
+ else { name:, postcode:, establishment_type:, urn:, ukprn: }
+ end
+ end
+end
diff --git a/app/presenters/local_authority_presenter.rb b/app/presenters/local_authority_presenter.rb
new file mode 100644
index 000000000..0e5a1ab35
--- /dev/null
+++ b/app/presenters/local_authority_presenter.rb
@@ -0,0 +1,7 @@
+class LocalAuthorityPresenter < SimpleDelegator
+ def establishment_type_name
+ "Local authority"
+ end
+
+ def gias_url = nil
+end
diff --git a/app/presenters/support/organisation_presenter.rb b/app/presenters/support/organisation_presenter.rb
index bb30fb6b9..345030fcb 100644
--- a/app/presenters/support/organisation_presenter.rb
+++ b/app/presenters/support/organisation_presenter.rb
@@ -21,7 +21,7 @@ def postcode
def local_authority
return I18n.t("generic.not_provided") unless super
- super["name"]
+ super.name
end
# @return [String]
diff --git a/app/views/components/_new_case_request_components.html.erb b/app/views/components/_new_case_request_components.html.erb
index 0af83caca..fafaf1ee7 100644
--- a/app/views/components/_new_case_request_components.html.erb
+++ b/app/views/components/_new_case_request_components.html.erb
@@ -7,7 +7,7 @@
label_class: "govuk-hint",
element_id: "school-urn-autocomplete",
element_name: "case_request[organisation_name]",
- template_suggestion: "{{name}}, {{postcode}}
{{establishment_type}}
URN: {{urn}} - UKPRN: {{ukprn}}",
+ template_suggestion: "{{autocomplete_template}}",
value_field: :name,
default_value: form.object.organisation&.name,
hidden_fields: {
diff --git a/app/views/engagement/case_requests/school_pickers/edit.html.erb b/app/views/engagement/case_requests/school_pickers/edit.html.erb
index d4cb5ed97..3139b1e1f 100644
--- a/app/views/engagement/case_requests/school_pickers/edit.html.erb
+++ b/app/views/engagement/case_requests/school_pickers/edit.html.erb
@@ -1,4 +1,4 @@
-
<%= I18n.t("support.case_hub_migration.school_picker.title") %>
+<%= I18n.t("support.case_hub_migration.school_picker.title", organisation_type: @school_picker.organisation_type) %>
<%= render "components/school_picker/school_picker",
results_model: @school_picker,
diff --git a/app/views/engagement/case_requests/show.html.erb b/app/views/engagement/case_requests/show.html.erb
index f2a0f1085..e557edbf9 100644
--- a/app/views/engagement/case_requests/show.html.erb
+++ b/app/views/engagement/case_requests/show.html.erb
@@ -17,21 +17,23 @@
<%= @case_request.organisation.name %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
-
-
- <%= I18n.t("support.case_hub_migration.label.school_postcode") %>
-
-
- <%= @case_request.organisation.postcode %>
-
-
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
-
-
+ <% if @case_request.organisation.respond_to?(:postcode) %>
+
+
+ <%= I18n.t("support.case_hub_migration.label.school_postcode") %>
+
+
+ <%= @case_request.organisation.postcode %>
+
+
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
+
+
+ <% end %>
<% if @case_request.organisation.respond_to?(:urn) %>
@@ -42,7 +44,7 @@
<%= @case_request.organisation.urn %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
<% end %>
@@ -56,22 +58,38 @@
<%= @case_request.organisation.uid %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
<% end %>
-
-
- <%= I18n.t("support.case_hub_migration.label.school_ukprn") %>
-
-
- <%= @case_request.organisation.ukprn %>
-
-
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
-
-
+ <% if @case_request.organisation.respond_to?(:la_code) %>
+
+
+ <%= I18n.t("support.case_hub_migration.label.la_code") %>
+
+
+ <%= @case_request.organisation.la_code %>
+
+
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
+
+
+ <% end %>
+
+ <% if @case_request.organisation.respond_to?(:ukprn) %>
+
+
+ <%= I18n.t("support.case_hub_migration.label.school_ukprn") %>
+
+
+ <%= @case_request.organisation.ukprn %>
+
+
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
+
+
+ <% end %>
<% if @case_request.multischool? %>
@@ -82,7 +100,7 @@
<%= I18n.t("support.case_hub_migration.label.school_number", selected: @case_request.school_urns.count, total: @case_request.organisation.organisations.length ) %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_school_picker_path(source: :change_link), class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_school_picker_path(source: :change_link), no_visited_state: true %>
<% end %>
@@ -101,7 +119,7 @@
<%= @case_request.full_name %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
@@ -113,7 +131,7 @@
<%= @case_request.email %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
@@ -125,7 +143,7 @@
<%= @case_request.phone_number %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
@@ -137,7 +155,7 @@
<%= @case_request.extension_number %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
@@ -156,7 +174,7 @@
<%= if @case_request.discovery_method == Support::Case::discovery_methods[:other] && !@case_request.discovery_method_other_text.empty? then "- #{@case_request.discovery_method_other_text}" end %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
@@ -175,7 +193,7 @@
<%= @case_request.type %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
@@ -188,7 +206,7 @@
<%= @case_request.category.title %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
<% else %>
@@ -200,7 +218,7 @@
<%= @case_request.query.title %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
<% end %>
@@ -219,7 +237,7 @@
<%= simple_format(@case_request.request_text, class: "govuk-body") %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
@@ -237,7 +255,7 @@
<%= number_to_currency(@case_request.procurement_amount, unit: "£", precision: 2) %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
<% if @case_request.is_energy_or_services? %>
@@ -249,7 +267,7 @@
<%= @case_request.contract_start_date_formatted || I18n.t("faf.check_answers.not_known") %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_contract_start_date_path(@case_request, source: :change_link), class: "govuk-link", id: "edit-contract-start-date", "aria-label": I18n.t("faf.check_answers.aria.change_contract_start_date") %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_contract_start_date_path(@case_request, source: :change_link), class: "govuk-link", id: "edit-contract-start-date", "aria-label": I18n.t("faf.check_answers.aria.change_contract_start_date") %>
<% end %>
@@ -262,7 +280,7 @@
<%= @case_request.same_supplier_used_formatted %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_same_supplier_path(@case_request, source: :change_link), class: "govuk-link", id: "edit-same-supplier", "aria-label": I18n.t("faf.check_answers.aria.change_same_supplier_used") %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_same_supplier_path(@case_request, source: :change_link), class: "govuk-link", id: "edit-same-supplier", "aria-label": I18n.t("faf.check_answers.aria.change_same_supplier_used") %>
<% end %>
@@ -280,7 +298,7 @@
<%= f.filename %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, no_visited_state: true %>
<% end %>
diff --git a/app/views/support/case_requests/school_pickers/edit.html.erb b/app/views/support/case_requests/school_pickers/edit.html.erb
index 1eab73a7d..e57352c4e 100644
--- a/app/views/support/case_requests/school_pickers/edit.html.erb
+++ b/app/views/support/case_requests/school_pickers/edit.html.erb
@@ -1,4 +1,4 @@
-<%= I18n.t("support.case_hub_migration.school_picker.title") %>
+<%= I18n.t("support.case_hub_migration.school_picker.title", organisation_type: @school_picker.organisation_type) %>
<%= render "components/school_picker/school_picker",
results_model: @school_picker,
diff --git a/app/views/support/case_requests/show.html.erb b/app/views/support/case_requests/show.html.erb
index 20ac7a3e9..2aa525dce 100644
--- a/app/views/support/case_requests/show.html.erb
+++ b/app/views/support/case_requests/show.html.erb
@@ -17,21 +17,23 @@
<%= @case_request.organisation&.name || "No organisation selected" %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
-
-
- <%= I18n.t("support.case_hub_migration.label.school_postcode") %>
-
-
- <%= @case_request.organisation&.postcode %>
-
-
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
-
-
+ <% if @case_request.organisation.respond_to?(:postcode) %>
+
+
+ <%= I18n.t("support.case_hub_migration.label.school_postcode") %>
+
+
+ <%= @case_request.organisation.postcode %>
+
+
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
+
+
+ <% end %>
<% if @case_request.organisation.respond_to?(:urn) %>
@@ -42,7 +44,7 @@
<%= @case_request.organisation.urn %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
<% end %>
@@ -56,22 +58,38 @@
<%= @case_request.organisation.uid %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
<% end %>
-
-
- <%= I18n.t("support.case_hub_migration.label.school_ukprn") %>
-
-
- <%= @case_request.organisation&.ukprn %>
-
-
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
-
-
+ <% if @case_request.organisation.respond_to?(:la_code) %>
+
+
+ <%= I18n.t("support.case_hub_migration.label.la_code") %>
+
+
+ <%= @case_request.organisation.la_code %>
+
+
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
+
+
+ <% end %>
+
+ <% if @case_request.organisation.respond_to?(:ukprn) %>
+
+
+ <%= I18n.t("support.case_hub_migration.label.school_ukprn") %>
+
+
+ <%= @case_request.organisation.ukprn %>
+
+
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
+
+
+ <% end %>
<% if @case_request.multischool? %>
@@ -82,7 +100,7 @@
<%= I18n.t("support.case_hub_migration.label.school_number", selected: @case_request.school_urns.count, total: @case_request.organisation.organisations.length ) %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_school_picker_path(source: :change_link), class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_school_picker_path(source: :change_link), no_visited_state: true %>
<% end %>
@@ -101,7 +119,7 @@
<%= @case_request.full_name %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -113,7 +131,7 @@
<%= @case_request.email %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -125,7 +143,7 @@
<%= @case_request.phone_number %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -137,7 +155,7 @@
<%= @case_request.extension_number %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -156,7 +174,7 @@
<%= if @case_request.discovery_method == Support::Case::discovery_methods[:other] && !@case_request.discovery_method_other_text.empty? then "- #{@case_request.discovery_method_other_text}" end %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -174,7 +192,7 @@
<%= I18n.t("support.case.label.source.#{@case_request.source}") %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -194,7 +212,7 @@
<%= @case_request.type %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -207,7 +225,7 @@
<%= @case_request.category&.title %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
<% else %>
@@ -219,7 +237,7 @@
<%= @case_request.query&.title %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
<% end %>
@@ -238,7 +256,7 @@
<%= simple_format(@case_request.request_text, class: "govuk-body") %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
@@ -256,7 +274,7 @@
<%= number_to_currency(@case_request.procurement_amount, unit: "£", precision: 2) %>
- <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
+ <%= govuk_link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, no_visited_state: true %>
diff --git a/app/views/support/cases/organisations/edit.html.erb b/app/views/support/cases/organisations/edit.html.erb
index d99f4e546..3ffdd7e8e 100644
--- a/app/views/support/cases/organisations/edit.html.erb
+++ b/app/views/support/cases/organisations/edit.html.erb
@@ -7,7 +7,7 @@
label_class: "govuk-!-font-weight-bold govuk-!-font-size-36 govuk-!-margin-bottom-5",
element_id: "organisation-autocomplete",
element_name: "case_organisation_form[organisation_name]",
- template_suggestion: "{{name}}, {{postcode}}
{{establishment_type}}
URN: {{urn}} - UKPRN: {{ukprn}}",
+ template_suggestion: "{{autocomplete_template}}",
value_field: :name,
hidden_fields: {
'case_organisation_form[organisation_id]' => :id,
diff --git a/app/views/support/cases/school_details/show.html.erb b/app/views/support/cases/school_details/show.html.erb
index e7b10ac07..5f4f3a12d 100644
--- a/app/views/support/cases/school_details/show.html.erb
+++ b/app/views/support/cases/school_details/show.html.erb
@@ -103,12 +103,14 @@
<% if @current_case.organisation.present? %>
- -
- <%= govuk_link_to @current_case.organisation_gias_label,
- @current_case.organisation_gias_url,
- target: "_blank", rel: "noreferrer noopener"
- %>
-
+ <% if @current_case.organisation_gias_url.present? %>
+ -
+ <%= govuk_link_to @current_case.organisation_gias_label,
+ @current_case.organisation_gias_url,
+ target: "_blank", rel: "noreferrer noopener"
+ %>
+
+ <% end %>
<% if other_cases_by_case_org_exist?(@current_case.organisation) %>
-
<%= govuk_link_to I18n.t("support.case.label.view_all_cases"), other_cases_by_case_org_path(@current_case.organisation, back_to: url_b64(support_case_path(@current_case, back_to: params[:back_to]))), no_visited_state: true, "target" => "_top" %>
diff --git a/app/views/support/establishment_search/local_authority/_autocomplete_template.html.erb b/app/views/support/establishment_search/local_authority/_autocomplete_template.html.erb
new file mode 100644
index 000000000..4971db69c
--- /dev/null
+++ b/app/views/support/establishment_search/local_authority/_autocomplete_template.html.erb
@@ -0,0 +1 @@
+<%= name %>
<%= establishment_type %>
Code: <%= code %>
diff --git a/app/views/support/establishment_search/support/establishment_group/_autocomplete_template.html.erb b/app/views/support/establishment_search/support/establishment_group/_autocomplete_template.html.erb
new file mode 100644
index 000000000..7510f09fb
--- /dev/null
+++ b/app/views/support/establishment_search/support/establishment_group/_autocomplete_template.html.erb
@@ -0,0 +1 @@
+<%= name %>, <%= postcode %>
<%= establishment_type %>
URN: <%= urn %> - UKPRN: <%= ukprn %>
diff --git a/app/views/support/establishment_search/support/organisation/_autocomplete_template.html.erb b/app/views/support/establishment_search/support/organisation/_autocomplete_template.html.erb
new file mode 100644
index 000000000..7510f09fb
--- /dev/null
+++ b/app/views/support/establishment_search/support/organisation/_autocomplete_template.html.erb
@@ -0,0 +1 @@
+<%= name %>, <%= postcode %>
<%= establishment_type %>
URN: <%= urn %> - UKPRN: <%= ukprn %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8d70386da..d577769ea 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -82,6 +82,7 @@ en:
selected: "of %{total} schools selected from %{group_name}"
phases:
no_phase: No phase
+ nursery: Nursery
primary: Primary
middle: Middle
secondary: Secondary
@@ -1181,6 +1182,7 @@ en:
change: change
view_group_information: View group information (opens in a new tab)
view_school_information: View school information (opens in a new tab)
+ view_local_authority_information: View local authority information (opens in a new tab)
list:
all_cases: All cases
my_cases: My cases
@@ -1335,7 +1337,7 @@ en:
subtitle: General advice about a frameworks
case_hub_migration:
school_picker:
- title: Which schools in the academy trust or federation will be involved in this procurement?
+ title: Which schools in the %{organisation_type} will be involved in this procurement?
edit:
header: Check your answers before creating a new case
label:
@@ -1370,6 +1372,7 @@ en:
hub_case_ref_hint: We will use the existing Hub identification number to link the existing case data to a new case number
hub_notes: Hub notes / comments %{optional}
hub_notes_hint: Enter a summary of the query from the Hub case
+ la_code: Organisation code
last_name: Contact last name
message: Message
name: Contact name
diff --git a/db/migrate/20240320102856_create_local_authorities.rb b/db/migrate/20240328151056_create_local_authorities.rb
similarity index 100%
rename from db/migrate/20240320102856_create_local_authorities.rb
rename to db/migrate/20240328151056_create_local_authorities.rb
diff --git a/db/migrate/20240328151130_seed_local_authorities.rb b/db/migrate/20240328151130_seed_local_authorities.rb
new file mode 100644
index 000000000..2b3d20434
--- /dev/null
+++ b/db/migrate/20240328151130_seed_local_authorities.rb
@@ -0,0 +1,21 @@
+class SeedLocalAuthorities < ActiveRecord::Migration[7.1]
+ def change
+ reversible do |direction|
+ direction.up do
+ Support::Organisation.find_each do |organisation|
+ local_authority = LocalAuthority.find_or_initialize_by(la_code: organisation.local_authority_legacy["code"]) do |la|
+ la.name = organisation.local_authority_legacy["name"]
+ la.save!
+ end
+
+ organisation.update!(local_authority:)
+ end
+ end
+
+ direction.down do
+ Support::Organisation.update_all(local_authority: nil)
+ LocalAuthority.destroy_all
+ end
+ end
+ end
+end
diff --git a/db/migrate/20240328151240_update_support_case_data_to_version_9.rb b/db/migrate/20240328151240_update_support_case_data_to_version_9.rb
new file mode 100644
index 000000000..de967e1df
--- /dev/null
+++ b/db/migrate/20240328151240_update_support_case_data_to_version_9.rb
@@ -0,0 +1,5 @@
+class UpdateSupportCaseDataToVersion9 < ActiveRecord::Migration[7.1]
+ def change
+ update_view :support_case_data, version: 9, revert_to_version: 8
+ end
+end
diff --git a/db/migrate/20240328151344_update_support_establishment_searches_to_version_3.rb b/db/migrate/20240328151344_update_support_establishment_searches_to_version_3.rb
new file mode 100644
index 000000000..75bc32a2d
--- /dev/null
+++ b/db/migrate/20240328151344_update_support_establishment_searches_to_version_3.rb
@@ -0,0 +1,5 @@
+class UpdateSupportEstablishmentSearchesToVersion3 < ActiveRecord::Migration[7.1]
+ def change
+ replace_view :support_establishment_searches, version: 3, revert_to_version: 2
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 412fedc6b..26a7088b7 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.1].define(version: 2024_03_28_145304) do
+ActiveRecord::Schema[7.1].define(version: 2024_03_28_151344) do
create_sequence "evaluation_refs"
create_sequence "framework_refs"
@@ -1049,7 +1049,8 @@
organisations.urn,
organisations.ukprn,
etypes.name AS establishment_type,
- 'Support::Organisation'::text AS source
+ 'Support::Organisation'::text AS source,
+ NULL::text AS code
FROM (support_organisations organisations
JOIN support_establishment_types etypes ON ((etypes.id = organisations.establishment_type_id)))
WHERE (organisations.status <> 2)
@@ -1060,10 +1061,21 @@
NULL::character varying AS urn,
egroups.ukprn,
egtypes.name AS establishment_type,
- 'Support::EstablishmentGroup'::text AS source
+ 'Support::EstablishmentGroup'::text AS source,
+ NULL::text AS code
FROM (support_establishment_groups egroups
JOIN support_establishment_group_types egtypes ON ((egtypes.id = egroups.establishment_group_type_id)))
- WHERE (egroups.status <> 2);
+ WHERE (egroups.status <> 2)
+ UNION ALL
+ SELECT local_authorities.id,
+ local_authorities.name,
+ NULL::text AS postcode,
+ NULL::character varying AS urn,
+ NULL::character varying AS ukprn,
+ 'Local authority'::character varying AS establishment_type,
+ 'LocalAuthority'::text AS source,
+ local_authorities.la_code AS code
+ FROM local_authorities;
SQL
create_view "support_case_searches", sql_definition: <<-SQL
SELECT sc.id AS case_id,
@@ -1263,8 +1275,8 @@
LEFT JOIN ( SELECT organisations.id,
organisations.name,
organisations.rsc_region,
- (organisations.local_authority_legacy ->> 'name'::text) AS local_authority_name,
- (organisations.local_authority_legacy ->> 'code'::text) AS local_authority_code,
+ local_authorities.name AS local_authority_name,
+ local_authorities.la_code AS local_authority_code,
organisations.gor_name,
organisations.urn,
organisations.ukprn,
@@ -1274,14 +1286,15 @@
organisations.phase,
etypes.name AS establishment_type,
'Support::Organisation'::text AS source
- FROM (support_organisations organisations
+ FROM ((support_organisations organisations
JOIN support_establishment_types etypes ON ((etypes.id = organisations.establishment_type_id)))
- UNION ALL
+ JOIN local_authorities ON ((local_authorities.id = organisations.local_authority_id)))
+ UNION ALL
SELECT egroups.id,
egroups.name,
NULL::character varying AS rsc_region,
- NULL::text AS local_authority_name,
- NULL::text AS local_authority_code,
+ NULL::character varying AS local_authority_name,
+ NULL::character varying AS local_authority_code,
NULL::character varying AS gor_name,
NULL::character varying AS urn,
egroups.ukprn,
diff --git a/db/views/support_case_data_v09.sql b/db/views/support_case_data_v09.sql
new file mode 100644
index 000000000..14e36b3ed
--- /dev/null
+++ b/db/views/support_case_data_v09.sql
@@ -0,0 +1,215 @@
+SELECT
+ sc.id AS case_id,
+ sc.ref AS case_ref,
+ sc.created_at AS created_at,
+ sc.created_at::DATE AS created_date,
+ TO_CHAR(sc.created_at::DATE, 'yyyy') AS created_year,
+ TO_CHAR(sc.created_at::DATE, 'mm') AS created_month,
+ (CASE
+ WHEN (DATE_PART('month', sc.created_at)) >= 4 THEN concat('FY', TO_CHAR(sc.created_at::DATE, 'yy'), '/', TO_CHAR((sc.created_at + interval '1 year')::DATE, 'yy'))
+ WHEN (DATE_PART('month', sc.created_at)) < 4 THEN concat('FY', TO_CHAR((sc.created_at - interval '1 year')::DATE, 'yy'), '/', TO_CHAR(sc.created_at::DATE, 'yy'))
+ END) as created_financial_year,
+ GREATEST(sc.updated_at, si.created_at) AS last_modified_at,
+ GREATEST(sc.updated_at, si.created_at)::DATE AS last_modified_date,
+ TO_CHAR(GREATEST(sc.updated_at, si.created_at)::DATE, 'yyyy') AS last_modified_year,
+ TO_CHAR(GREATEST(sc.updated_at, si.created_at)::DATE, 'mm') AS last_modified_month,
+ first_resolved.created_at::DATE as first_resolved_date,
+ last_resolved.created_at::DATE as last_resolved_date,
+ sc.source AS case_source,
+ sc.creation_source AS case_creation_source,
+ sc.state AS case_state,
+ sc.closure_reason AS case_closure_reason,
+ cat.title AS sub_category_title,
+ sc.other_category AS category_other,
+ stc.tower_name AS tower_name,
+ concat(sa.first_name, ' ', sa.last_name) AS agent_name,
+ sc.savings_actual AS savings_actual,
+ sc.savings_actual_method AS savings_actual_method,
+ sc.savings_estimate AS savings_estimate,
+ sc.savings_estimate_method AS savings_estimate_method,
+ sc.savings_status AS savings_status,
+ sc.support_level AS case_support_level,
+ sc.value AS case_value,
+ sc.with_school AS with_school_flag,
+ sc.next_key_date AS next_key_date,
+ sc.next_key_date_description AS next_key_date_description,
+ sc.email AS organisation_contact_email,
+ se.name AS organisation_name,
+ se.urn AS organisation_urn,
+ se.ukprn AS organisation_ukprn,
+ se.rsc_region AS organisation_rsc_region,
+ se.local_authority_name AS organisation_local_authority_name,
+ se.local_authority_code AS organisation_local_authority_code,
+ se.gor_name AS gor_name,
+ se.uid AS organisation_uid,
+ se.phase AS organisation_phase,
+ se.organisation_status AS organisation_status,
+ se.egroup_status AS establishment_group_status,
+ se.establishment_type AS establishment_type,
+ ARRAY_LENGTH(fr.school_urns, 1) AS request_num_schools,
+ REPLACE(TRIM(fr.school_urns::TEXT, '{}"'),',',', ') AS request_school_urns,
+ ARRAY_LENGTH(cr.school_urns, 1) AS case_num_schools,
+ REPLACE(TRIM(cr.school_urns::TEXT, '{}"'),',',', ') AS case_school_urns,
+ sf.name AS framework_name,
+ sp.reason_for_route_to_market AS reason_for_route_to_market,
+ sp.required_agreement_type AS required_agreement_type,
+ sp.route_to_market AS route_to_market,
+ sp.stage AS procurement_stage_old,
+ sps.stage AS procurement_stage,
+ sps.key AS procurement_stage_key,
+ sp.started_at AS procurement_started_at,
+ sp.ended_at AS procurement_ended_at,
+ ec.started_at AS previous_contract_started_at,
+ ec.ended_at AS previous_contract_ended_at,
+ ec.duration as previous_contract_duration,
+ ec.spend AS previous_contract_spend,
+ ec.supplier AS previous_contract_supplier,
+ nc.started_at AS new_contract_started_at,
+ nc.ended_at AS new_contract_ended_at,
+ nc.duration as new_contract_duration,
+ nc.spend AS new_contract_spend,
+ nc.supplier AS new_contract_supplier,
+ ps.created_at AS participation_survey_date,
+ es.created_at AS exit_survey_date,
+ sir.referrer AS referrer
+FROM
+ support_cases sc
+LEFT JOIN (
+ SELECT
+ sa.id,
+ sa.first_name,
+ sa.last_name
+ FROM support_agents sa
+) AS sa
+ON sc.agent_id = sa.id
+LEFT JOIN (
+ SELECT
+ stc.id,
+ stc.procurement_id,
+ stc.tower_name
+ FROM support_tower_cases stc
+) as stc
+ON sc.procurement_id = stc.procurement_id
+LEFT JOIN
+ support_activity_log_items first_resolved
+ON first_resolved.id =
+(
+ SELECT id
+ FROM support_activity_log_items first_resolved
+ WHERE sc.id::TEXT = first_resolved.support_case_id AND first_resolved.action = 'resolve_case'
+ ORDER BY first_resolved.created_at ASC
+ LIMIT 1
+)
+LEFT JOIN
+ support_activity_log_items last_resolved
+ON last_resolved.id =
+(
+ SELECT id
+ FROM support_activity_log_items last_resolved
+ WHERE sc.id::TEXT = last_resolved.support_case_id AND last_resolved.action = 'resolve_case'
+ ORDER BY last_resolved.created_at DESC
+ LIMIT 1
+)
+LEFT JOIN (
+ SELECT
+ fr.id,
+ fr.support_case_id,
+ fr.school_urns
+ FROM framework_requests fr
+) as fr
+ON sc.id = fr.support_case_id
+LEFT JOIN (
+ SELECT
+ cr.id,
+ cr.support_case_id,
+ cr.school_urns
+ FROM case_requests cr
+) as cr
+ON sc.id = cr.support_case_id
+LEFT JOIN
+ support_interactions si
+ON si.id =
+ (
+ SELECT id
+ FROM support_interactions i
+ WHERE i.case_id = sc.id
+ ORDER BY i.created_at ASC
+ LIMIT 1
+ )
+LEFT JOIN (
+ SELECT
+ organisations.id,
+ organisations.name,
+ organisations.rsc_region,
+ local_authorities.name as local_authority_name,
+ local_authorities.la_code as local_authority_code,
+ organisations.gor_name as gor_name,
+ organisations.urn,
+ organisations.ukprn,
+ organisations.status as organisation_status,
+ null as egroup_status,
+ null as uid,
+ organisations.phase,
+ etypes.name as establishment_type,
+ 'Support::Organisation' as source
+ FROM support_organisations organisations
+ JOIN support_establishment_types etypes
+ ON etypes.id = organisations.establishment_type_id
+ JOIN local_authorities
+ ON local_authorities.id = organisations.local_authority_id
+ UNION ALL
+ SELECT
+ egroups.id,
+ egroups.name,
+ null as rsc_region,
+ null as local_authority_name,
+ null as local_authority_code,
+ null as gor_name,
+ null as urn,
+ egroups.ukprn,
+ null as organisation_status,
+ egroups.status as egroup_status,
+ egroups.uid,
+ null as phase,
+ egtypes.name as establishment_type,
+ 'Support::EstablishmentGroup' as source
+ FROM support_establishment_groups egroups
+ JOIN support_establishment_group_types egtypes
+ ON egtypes.id = egroups.establishment_group_type_id
+ ) AS se
+ON sc.organisation_id = se.id AND sc.organisation_type = se.source
+LEFT JOIN support_categories cat
+ ON sc.category_id = cat.id
+LEFT JOIN support_procurements sp
+ ON sc.procurement_id = sp.id
+LEFT JOIN support_procurement_stages sps
+ ON sc.procurement_stage_id = sps.id
+LEFT JOIN support_frameworks sf
+ ON sp.framework_id = sf.id
+LEFT JOIN support_contracts ec
+ ON sc.existing_contract_id = ec.id
+LEFT JOIN support_contracts nc
+ ON sc.new_contract_id = nc.id
+LEFT JOIN (
+ SELECT si.created_at,
+ si.case_id
+ FROM support_interactions si
+ WHERE si.event_type = 3
+ AND si.additional_data ->>'email_template' = 'fd89b69e-7ff9-4b73-b4c4-d8c1d7b93779'
+ ) AS ps
+ ON si.case_id = ps.case_id
+LEFT JOIN (
+ SELECT si.created_at,
+ si.case_id
+ FROM support_interactions si
+ WHERE si.event_type = 3
+ AND si.additional_data ->>'email_template' = '134bc268-2c6b-4b74-b6f4-4a58e22d6c8b'
+ ) AS es
+ ON si.case_id = es.case_id
+LEFT JOIN (
+ SELECT si.additional_data ->>'referrer' AS referrer,
+ si.case_id
+ FROM support_interactions si
+ WHERE si.event_type = 8
+ ) AS sir
+ ON si.case_id = sir.case_id;
diff --git a/db/views/support_establishment_searches_v03.sql b/db/views/support_establishment_searches_v03.sql
new file mode 100644
index 000000000..002948105
--- /dev/null
+++ b/db/views/support_establishment_searches_v03.sql
@@ -0,0 +1,38 @@
+SELECT
+organisations.id,
+organisations.name,
+organisations.address->>'postcode' as postcode,
+organisations.urn,
+organisations.ukprn,
+etypes.name as establishment_type,
+'Support::Organisation' as source,
+NULL as code
+FROM support_organisations organisations
+JOIN support_establishment_types etypes
+ ON etypes.id = organisations.establishment_type_id
+WHERE organisations.status != 2
+UNION ALL
+SELECT
+egroups.id,
+egroups.name,
+egroups.address->>'postcode' as postcode,
+null as urn,
+egroups.ukprn,
+egtypes.name as establishment_type,
+'Support::EstablishmentGroup' as source,
+NULL as code
+FROM support_establishment_groups egroups
+JOIN support_establishment_group_types egtypes
+ ON egtypes.id = egroups.establishment_group_type_id
+WHERE egroups.status != 2
+UNION ALL
+SELECT
+local_authorities.id,
+local_authorities.name,
+NULL AS postcode,
+NULL AS urn,
+NULL AS ukprn,
+'Local authority' AS establishment_type,
+'LocalAuthority' as source,
+local_authorities.la_code AS code
+FROM local_authorities
diff --git a/spec/factories/case_request.rb b/spec/factories/case_request.rb
new file mode 100644
index 000000000..5f1bda54d
--- /dev/null
+++ b/spec/factories/case_request.rb
@@ -0,0 +1,17 @@
+FactoryBot.define do
+ factory :case_request do
+ first_name { Faker::Name.first_name }
+ last_name { Faker::Name.last_name }
+ email { Faker::Internet.email }
+ source { :digital }
+ discovery_method { 0 }
+ procurement_amount { 10 }
+ association :category, factory: :support_category
+
+ before(:create) do
+ parent = create(:support_category, title: "Or")
+ create(:support_category, title: "Other (General)", parent:)
+ create(:support_query, title: "Other")
+ end
+ end
+end
diff --git a/spec/factories/local_authority.rb b/spec/factories/local_authority.rb
new file mode 100644
index 000000000..5804a29e6
--- /dev/null
+++ b/spec/factories/local_authority.rb
@@ -0,0 +1,6 @@
+FactoryBot.define do
+ factory :local_authority, class: "LocalAuthority" do
+ la_code { Faker::Number.unique.number(digits: 3).to_s }
+ name { Faker::Address.unique.city }
+ end
+end
diff --git a/spec/factories/support/organisation.rb b/spec/factories/support/organisation.rb
index 4d98a0cde..130d4d614 100644
--- a/spec/factories/support/organisation.rb
+++ b/spec/factories/support/organisation.rb
@@ -4,7 +4,7 @@
sequence(:name) { |n| "School ##{n}" }
address { {} }
contact { { "role": "Head Teacher", "title": "Ms", "last_name": "Teacher", "first_name": "Head" } }
- local_authority { { "code": 202, "name": "Camden" } }
+ local_authority_legacy { { "code": 202, "name": "Camden" } }
phase { (0..7).to_a.sample }
gender { (0..3).to_a.sample }
@@ -12,6 +12,7 @@
association :establishment_type,
factory: :support_establishment_type
+ association :local_authority, factory: :local_authority
trait :with_address do
address { { "town": "London", "county": "", "street": "St James's Passage", "locality": "Duke's Place", "postcode": "EC3A 5DE" } }
diff --git a/spec/features/engagement/create_case_spec.rb b/spec/features/engagement/create_case_spec.rb
index 120888a18..4f0f4f3eb 100644
--- a/spec/features/engagement/create_case_spec.rb
+++ b/spec/features/engagement/create_case_spec.rb
@@ -8,7 +8,7 @@
create(:support_category, :with_sub_category)
create(:support_category, title: "EnergyCat", parent: Support::Category.find_by(title: "Energy"))
create(:request_for_help_category, title: "EnergyCat", slug: "energy-cat", support_category: Support::Category.find_by(title: "EnergyCat"), flow: :energy)
- create(:support_organisation, name: "Hillside School", urn: "000001", local_authority: { "code": "001", "name": "Timbuktoo" })
+ create(:support_organisation, name: "Hillside School", urn: "000001", local_authority: create(:local_authority, la_code: "001", name: "Timbuktoo"))
visit "/engagement/cases"
click_button "Create a new case"
@@ -77,6 +77,34 @@
end
end
+ context "when selecting a local authority" do
+ let(:local_authority) { create(:local_authority, name: "Camden") }
+
+ before do
+ create_list(:support_organisation, 3, local_authority:)
+ select_organisation "Camden"
+ valid_form_data_without_organisation
+ click_on "Save and continue"
+ end
+
+ it "navigates to the same supplier question when more than one school is chosen and saves answers" do
+ check "School #1"
+ check "School #2"
+ click_on "Save"
+ expect(page).to have_text "Do all the schools currently use the same supplier?"
+
+ choose "Yes"
+ click_on "Save"
+ expect(page).to have_text "Same supplier used"
+ expect(page).to have_text "2 of 3 schools"
+
+ click_on "Create case"
+ expect(Support::Case.last.organisation).to eq(local_authority)
+ expect(Support::Case.last.participating_schools.pluck(:name)).to match_array(["School #1", "School #2"])
+ expect(CaseRequest.last.same_supplier_used).to eq("yes")
+ end
+ end
+
context "when selecting an energy or services category" do
before do
choose "Procurement" # request type
diff --git a/spec/features/support/create_case_spec.rb b/spec/features/support/create_case_spec.rb
index 5d3befeab..c0a0d8bad 100644
--- a/spec/features/support/create_case_spec.rb
+++ b/spec/features/support/create_case_spec.rb
@@ -57,6 +57,17 @@
end
end
+ context "when selecting a local authority" do
+ it "sets the local authority as the case organisation" do
+ local_authority = create(:local_authority, name: "Camden")
+ select_organisation "Camden"
+ valid_form_data_without_organisation
+ click_on "Save and continue"
+ click_on "Create case"
+ expect(Support::Case.last.organisation).to eq(local_authority)
+ end
+ end
+
it "allows case to be created" do
complete_valid_form
diff --git a/spec/helpers/support/case_helper_spec.rb b/spec/helpers/support/case_helper_spec.rb
index 96f710315..39c3e2ce4 100644
--- a/spec/helpers/support/case_helper_spec.rb
+++ b/spec/helpers/support/case_helper_spec.rb
@@ -10,6 +10,7 @@
search_case_form: {
search_term: organisation.name,
state: %w[initial opened resolved on_hold pipeline no_response],
+ exact_match: true,
},
}
end
diff --git a/spec/models/case_request/school_picker/presentable_spec.rb b/spec/models/case_request/school_picker/presentable_spec.rb
new file mode 100644
index 000000000..bd6764b44
--- /dev/null
+++ b/spec/models/case_request/school_picker/presentable_spec.rb
@@ -0,0 +1,25 @@
+require "rails_helper"
+
+describe CaseRequest::SchoolPicker::Presentable do
+ describe "#organisation_type" do
+ subject(:presentable) { CaseRequest::SchoolPicker.new(case_request:) }
+
+ let(:case_request) { create(:case_request, organisation:) }
+
+ context "when the organisation is an establishment group" do
+ let(:organisation) { create(:support_establishment_group) }
+
+ it "returns 'academy trust or federation'" do
+ expect(presentable.organisation_type).to eq("academy trust or federation")
+ end
+ end
+
+ context "when the organisation is a local authority" do
+ let(:organisation) { create(:local_authority) }
+
+ it "returns 'local authority'" do
+ expect(presentable.organisation_type).to eq("local authority")
+ end
+ end
+ end
+end
diff --git a/spec/models/local_authority_spec.rb b/spec/models/local_authority_spec.rb
new file mode 100644
index 000000000..b4a515c9a
--- /dev/null
+++ b/spec/models/local_authority_spec.rb
@@ -0,0 +1,27 @@
+require "rails_helper"
+
+describe LocalAuthority, type: :model do
+ describe "#eligible_for_school_picker?" do
+ let(:local_authority) { create(:local_authority) }
+
+ context "when a local authority has more than one school" do
+ before do
+ create_list(:support_organisation, 3, local_authority:)
+ end
+
+ it "returns true" do
+ expect(local_authority.eligible_for_school_picker?).to eq(true)
+ end
+ end
+
+ context "when a local authority has one school or less" do
+ before do
+ create(:support_organisation, local_authority:)
+ end
+
+ it "returns false" do
+ expect(local_authority.eligible_for_school_picker?).to eq(false)
+ end
+ end
+ end
+end
diff --git a/spec/models/support/case_search_spec.rb b/spec/models/support/case_search_spec.rb
index 9b877fec3..7f5ab67e1 100644
--- a/spec/models/support/case_search_spec.rb
+++ b/spec/models/support/case_search_spec.rb
@@ -26,4 +26,25 @@
expect(results.pluck(:case_ref)).to match_array(%w[000001 000002])
end
end
+
+ context "when searching by organisation name (exact match)" do
+ let(:search_term) { "Camden" }
+
+ before do
+ school = create(:support_organisation, name: "Camden Primary School")
+ group = create(:support_establishment_group, name: "Camden Academy Trust")
+ local_authority = create(:local_authority, name: "Camden")
+
+ create(:support_case, ref: "000001", organisation: school)
+ create(:support_case, ref: "000002", organisation: group)
+ create(:support_case, ref: "000003", organisation: local_authority)
+ create(:support_case, ref: "000004", organisation: local_authority)
+ end
+
+ it "finds the relevant cases" do
+ results = described_class.find_a_case(search_term, exact_match: true)
+ expect(results.count).to eq(2)
+ expect(results.pluck(:case_ref)).to match_array(%w[000003 000004])
+ end
+ end
end
diff --git a/spec/models/support/establishment_search/presentable_spec.rb b/spec/models/support/establishment_search/presentable_spec.rb
new file mode 100644
index 000000000..e786ddf5c
--- /dev/null
+++ b/spec/models/support/establishment_search/presentable_spec.rb
@@ -0,0 +1,32 @@
+require "rails_helper"
+
+describe Support::EstablishmentSearch::Presentable do
+ subject(:presentable) { Support::EstablishmentSearch }
+
+ let!(:school) { create(:support_organisation, :with_address, name: "Test Primary School", urn: "1", ukprn: "123", establishment_type: create(:support_establishment_type, name: "Community school")) }
+ let!(:group) { create(:support_establishment_group, :with_address, name: "Test MAT", uid: "2", ukprn: "456", establishment_group_type: create(:support_establishment_group_type, name: "Multi-academy Trust")) }
+ let!(:local_authority) { create(:local_authority, name: "Camden", la_code: "3") }
+
+ describe "#autocomplete_template" do
+ context "when the search result is a school" do
+ it "returns the correct autocomplete template" do
+ search_result = presentable.omnisearch(school.urn).to_a.first
+ expect(search_result.autocomplete_template).to eq("Test Primary School, EC3A 5DE
Community school
URN: 1 - UKPRN: 123\n")
+ end
+ end
+
+ context "when the search result is a group" do
+ it "returns the correct autocomplete template" do
+ search_result = presentable.omnisearch(group.name).to_a.first
+ expect(search_result.autocomplete_template).to eq("Test MAT, EC1M 6HR
Multi-academy Trust
URN: - UKPRN: 456\n")
+ end
+ end
+
+ context "when the search result is a local authority" do
+ it "returns the correct autocomplete template" do
+ search_result = presentable.omnisearch(local_authority.name).to_a.first
+ expect(search_result.autocomplete_template).to eq("Camden
Local authority
Code: 3\n")
+ end
+ end
+ end
+end
diff --git a/spec/presenters/support/organisation_presenter_spec.rb b/spec/presenters/support/organisation_presenter_spec.rb
index 671e3371d..71315c141 100644
--- a/spec/presenters/support/organisation_presenter_spec.rb
+++ b/spec/presenters/support/organisation_presenter_spec.rb
@@ -22,7 +22,7 @@
end
context "with local authority defined" do
- let(:organisation) { create(:support_organisation, local_authority: { "code": 1, "name": "Authority" }) }
+ let(:organisation) { create(:support_organisation, local_authority: create(:local_authority, la_code: "1", name: "Authority")) }
describe "#local_authority" do
it "returns the local authority name" do
@@ -32,7 +32,7 @@
end
context "with no local authority defined" do
- let(:organisation) { create(:support_organisation, local_authority: nil) }
+ let(:organisation) { build(:support_organisation, local_authority: nil) }
describe "#local_authority" do
it "returns 'not provided'" do
diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb
index d65be9c97..4f5512857 100644
--- a/spec/support/database_cleaner.rb
+++ b/spec/support/database_cleaner.rb
@@ -20,5 +20,6 @@
config.append_after do
DatabaseCleaner.clean
FactoryBot.reload
+ Faker::UniqueGenerator.clear
end
end
diff --git a/spec/support/shared/user_with_many_orgs.rb b/spec/support/shared/user_with_many_orgs.rb
index ddd44ae1b..ee927813b 100644
--- a/spec/support/shared/user_with_many_orgs.rb
+++ b/spec/support/shared/user_with_many_orgs.rb
@@ -11,11 +11,14 @@
# TODO: let!
before do
+ local_authority = create(:local_authority, name: "Camden")
+
create(:support_organisation, :with_address,
urn: "100253",
name: "Specialist School for Testing",
establishment_type: foundation,
- trust_code: "2314")
+ trust_code: "2314",
+ local_authority:)
create(:support_organisation, :with_address,
urn: "100254",
@@ -24,7 +27,8 @@
number: "334",
ukprn: "4346",
establishment_type: community,
- trust_code: "2314")
+ trust_code: "2314",
+ local_authority:)
create(:support_establishment_group, :with_address,
uid: "2314",