From e6fa00d914bf08234d3075d16b7e8f97817a1b66 Mon Sep 17 00:00:00 2001 From: Edwin Kruglov Date: Wed, 27 Sep 2023 16:00:41 +0100 Subject: [PATCH] feat(cms): ability to update participating schools Jira: PWNN-1638 --- .../cases/confirm_organisation_controller.rb | 28 +++++ .../support/cases/organisations_controller.rb | 11 +- .../participating_schools_controller.rb | 33 +++++ .../cases/school_details_controller.rb | 11 ++ .../assign_organisation_to_case.rb | 5 +- ...uest_helper.rb => school_picker_helper.rb} | 4 +- .../controllers/school_picker_controller.js | 7 +- .../school_picker_filters_controller.js | 3 +- app/models/support/case.rb | 1 + app/models/support/case/school_pickable.rb | 13 ++ app/models/support/case/school_picker.rb | 12 ++ .../support/concerns/has_organisation.rb | 6 + .../support/establishment_group_presenter.rb | 4 + .../support/organisation_presenter.rb | 4 + .../school_picker/_school_picker.html.erb | 14 +++ .../_school_picker_filters.html.erb | 10 ++ .../_school_picker_results.html.erb | 32 +++++ .../confirm_schools/_form.html.erb | 6 +- .../school_pickers/_filters.html.erb | 11 +- .../school_pickers/_form.html.erb | 33 +---- .../cases/confirm_organisation/show.html.erb | 44 +++++++ .../participating_schools/edit.html.erb | 13 ++ .../participating_schools/show.html.erb | 29 +++++ .../cases/school_details/show.html.erb | 114 ++++++++++++++++++ .../cases/show/_school_details.html.erb | 103 +--------------- config/locales/en.yml | 53 +++++--- config/routes.rb | 6 + .../cases/organisations_controller_spec.rb | 21 ++++ spec/factories/support/case_organisation.rb | 6 + .../agent_can_set_case_contact_spec.rb | 2 +- ...t_can_update_participating_schools_spec.rb | 27 +++++ .../support/case_organisation_details_spec.rb | 2 +- .../support/case_school_details_spec.rb | 2 +- spec/features/support/case_tabs_spec.rb | 2 +- 34 files changed, 498 insertions(+), 174 deletions(-) create mode 100644 app/controllers/support/cases/confirm_organisation_controller.rb create mode 100644 app/controllers/support/cases/school_details/participating_schools_controller.rb create mode 100644 app/controllers/support/cases/school_details_controller.rb rename app/helpers/{framework_request_helper.rb => school_picker_helper.rb} (87%) create mode 100644 app/models/support/case/school_pickable.rb create mode 100644 app/models/support/case/school_picker.rb create mode 100644 app/views/components/school_picker/_school_picker.html.erb create mode 100644 app/views/components/school_picker/_school_picker_filters.html.erb create mode 100644 app/views/components/school_picker/_school_picker_results.html.erb create mode 100644 app/views/support/cases/confirm_organisation/show.html.erb create mode 100644 app/views/support/cases/school_details/participating_schools/edit.html.erb create mode 100644 app/views/support/cases/school_details/participating_schools/show.html.erb create mode 100644 app/views/support/cases/school_details/show.html.erb create mode 100644 spec/controllers/support/cases/organisations_controller_spec.rb create mode 100644 spec/factories/support/case_organisation.rb create mode 100644 spec/features/support/agent_can_update_participating_schools_spec.rb diff --git a/app/controllers/support/cases/confirm_organisation_controller.rb b/app/controllers/support/cases/confirm_organisation_controller.rb new file mode 100644 index 000000000..2e9489a23 --- /dev/null +++ b/app/controllers/support/cases/confirm_organisation_controller.rb @@ -0,0 +1,28 @@ +module Support + module Cases + class ConfirmOrganisationController < Cases::ApplicationController + def show + @back_url = edit_support_case_organisation_path(current_case) + @new_organisation = get_organisation + end + + def update + organisation = get_organisation + CaseManagement::AssignOrganisationToCase.new.call( + support_case_id: current_case.id, + agent_id: current_agent.id, + organisation_id: organisation.id, + organisation_type: organisation.class.name, + ) + redirect_to support_case_path(current_case, anchor: "school-details"), notice: I18n.t("support.case_organisation.flash.updated") + end + + private + + def get_organisation + type = params[:type] == Support::EstablishmentGroup.name ? Support::EstablishmentGroup : Support::Organisation + type.find(params[:id]) + end + end + end +end diff --git a/app/controllers/support/cases/organisations_controller.rb b/app/controllers/support/cases/organisations_controller.rb index 5203a3e22..c405736de 100644 --- a/app/controllers/support/cases/organisations_controller.rb +++ b/app/controllers/support/cases/organisations_controller.rb @@ -10,9 +10,14 @@ def edit def update @case_organisation_form = CaseOrganisationForm.from_validation(validation) - if validation.success? && @case_organisation_form.assign_organisation_to_case(current_case, current_agent.id) - redirect_to support_case_path(current_case, anchor: "school-details"), - notice: I18n.t("support.case_organisation.flash.updated") + if validation.success? + if !current_case.participating_schools.empty? + redirect_to support_case_confirm_organisation_path(current_case, id: @case_organisation_form.organisation_id, type: @case_organisation_form.organisation_type) + else + @case_organisation_form.assign_organisation_to_case(current_case, current_agent.id) + redirect_to support_case_path(current_case, anchor: "school-details"), + notice: I18n.t("support.case_organisation.flash.updated") + end else render :edit 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 new file mode 100644 index 000000000..ccfa05d1d --- /dev/null +++ b/app/controllers/support/cases/school_details/participating_schools_controller.rb @@ -0,0 +1,33 @@ +module Support + module Cases + 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) } + end + + def edit + @back_url = support_case_school_details_participating_schools_path + @case_school_picker = current_case.school_picker + @group = current_case.organisation + @all_schools = @group.organisations.order(:name) + @filters = @all_schools.filtering(form_params[:filters] || {}) + @filtered_schools = @filters.results.map { |s| Support::OrganisationPresenter.new(s) } + end + + def update + @case_school_picker = current_case.school_picker(school_urns: form_params[:school_urns].compact_blank) + @case_school_picker.save! + redirect_to support_case_school_details_participating_schools_path + end + + private + + def form_params + params.fetch(:participating_schools, {}).permit(filters: params.key?(:clear) ? nil : { local_authorities: [], phases: [] }, school_urns: []) + end + end + end + end +end diff --git a/app/controllers/support/cases/school_details_controller.rb b/app/controllers/support/cases/school_details_controller.rb new file mode 100644 index 000000000..a525f1bfc --- /dev/null +++ b/app/controllers/support/cases/school_details_controller.rb @@ -0,0 +1,11 @@ +module Support + module Cases + class SchoolDetailsController < Cases::ApplicationController + private + + def current_case + @current_case ||= CasePresenter.new(super) + end + end + end +end diff --git a/app/cores/case_management/assign_organisation_to_case.rb b/app/cores/case_management/assign_organisation_to_case.rb index c5afddf22..17a3a1015 100644 --- a/app/cores/case_management/assign_organisation_to_case.rb +++ b/app/cores/case_management/assign_organisation_to_case.rb @@ -4,7 +4,10 @@ class AssignOrganisationToCase def call(support_case_id:, agent_id:, organisation_id:, organisation_type:) support_case = Support::Case.find(support_case_id) - support_case.update!(organisation_id:, organisation_type:) + support_case.case_organisations.destroy_all + support_case.organisation_id = organisation_id + support_case.organisation_type = organisation_type + support_case.save! broadcast(:case_organisation_changed, { case_id: support_case_id, agent_id:, organisation_id: }) end diff --git a/app/helpers/framework_request_helper.rb b/app/helpers/school_picker_helper.rb similarity index 87% rename from app/helpers/framework_request_helper.rb rename to app/helpers/school_picker_helper.rb index 850abc748..a4be27d91 100644 --- a/app/helpers/framework_request_helper.rb +++ b/app/helpers/school_picker_helper.rb @@ -1,4 +1,4 @@ -module FrameworkRequestHelper +module SchoolPickerHelper def school_picker_la_filter_options(organisations) CheckboxOption .from( @@ -10,7 +10,7 @@ def school_picker_la_filter_options(organisations) def school_picker_phase_filter_options(organisations) phases = organisations.pluck(:phase).uniq.map { |phase| %w[middle_primary middle_secondary].include?(phase) ? "middle" : phase }.uniq - CheckboxOption.from(I18nOption.from("faf.school_picker.phases.%%key%%", phases)) + CheckboxOption.from(I18nOption.from("components.school_picker.phases.%%key%%", phases)) end def show_school_picker_phase_filters?(organisations) diff --git a/app/javascript/controllers/school_picker_controller.js b/app/javascript/controllers/school_picker_controller.js index c3e708f9c..c5370ac56 100644 --- a/app/javascript/controllers/school_picker_controller.js +++ b/app/javascript/controllers/school_picker_controller.js @@ -7,12 +7,13 @@ export default class extends Controller { "selectAll", "schoolTableBody", ]; + static values = { scope: String }; initialize() { this.getPreviouslySelectedSchoolUrns().forEach(urn => { const input = document.createElement("input"); input.setAttribute("type", "hidden"); - input.setAttribute("name", "framework_support_form[school_urns][]"); + input.setAttribute("name", `${this.scopeValue}[school_urns][]`); input.setAttribute("value", urn); this.getForm().appendChild(input); }); @@ -58,12 +59,12 @@ export default class extends Controller { } getSchoolUrnsFromForm() { - return new FormData(this.getForm()).getAll("framework_support_form[school_urns][]").filter(urn => urn && urn !== "all"); + return new FormData(this.getForm()).getAll(`${this.scopeValue}[school_urns][]`).filter(urn => urn && urn !== "all"); } getSchoolUrnsFromParams() { const params = new URLSearchParams(window.location.search); - return params.getAll("framework_support_form[school_urns][]"); + return params.getAll(`${this.scopeValue}[school_urns][]`); } getForm() { diff --git a/app/javascript/controllers/school_picker_filters_controller.js b/app/javascript/controllers/school_picker_filters_controller.js index fa6be369c..4813b948e 100644 --- a/app/javascript/controllers/school_picker_filters_controller.js +++ b/app/javascript/controllers/school_picker_filters_controller.js @@ -4,6 +4,7 @@ import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = ["schoolUrns"] static outlets = ["school-picker"] + static values = { scope: String }; connect() { this.assignCheckboxHandlers(this.element); @@ -23,7 +24,7 @@ export default class extends Controller { this.schoolPickerOutlet.getSchoolUrns().forEach(urn => { const input = document.createElement("input"); input.setAttribute("type", "hidden"); - input.setAttribute("name", "framework_support_form[school_urns][]"); + input.setAttribute("name", `${this.scopeValue}[school_urns][]`); input.setAttribute("value", urn); this.element.appendChild(input); }); diff --git a/app/models/support/case.rb b/app/models/support/case.rb index 3a42722d4..3c0db6164 100644 --- a/app/models/support/case.rb +++ b/app/models/support/case.rb @@ -16,6 +16,7 @@ class Case < ApplicationRecord include Historyable include QuickEditable include Summarisable + include SchoolPickable belongs_to :category, class_name: "Support::Category", optional: true belongs_to :query, class_name: "Support::Query", optional: true diff --git a/app/models/support/case/school_pickable.rb b/app/models/support/case/school_pickable.rb new file mode 100644 index 000000000..04422a11f --- /dev/null +++ b/app/models/support/case/school_pickable.rb @@ -0,0 +1,13 @@ +module Support::Case::SchoolPickable + extend ActiveSupport::Concern + + def school_picker(school_urns: participating_schools.map(&:urn)) + Support::Case::SchoolPicker.new(support_case: self, school_urns:) + end + + def pick_schools(school_urns) + schools = Support::Organisation.where(urn: school_urns) + self.participating_schools = schools + save! + end +end diff --git a/app/models/support/case/school_picker.rb b/app/models/support/case/school_picker.rb new file mode 100644 index 000000000..39db3c5a2 --- /dev/null +++ b/app/models/support/case/school_picker.rb @@ -0,0 +1,12 @@ +class Support::Case::SchoolPicker + include ActiveModel::Model + + attr_accessor( + :support_case, + :school_urns, + ) + + def save! + support_case.pick_schools(school_urns) + end +end diff --git a/app/presenters/support/concerns/has_organisation.rb b/app/presenters/support/concerns/has_organisation.rb index 1bb691653..d11cb84fa 100644 --- a/app/presenters/support/concerns/has_organisation.rb +++ b/app/presenters/support/concerns/has_organisation.rb @@ -59,6 +59,12 @@ def decorated_organisation "#{organisation_type}Presenter".safe_constantize.new(organisation) end + + def eligible_for_school_picker? + return false unless organisation + + decorated_organisation.eligible_for_school_picker? + end end end end diff --git a/app/presenters/support/establishment_group_presenter.rb b/app/presenters/support/establishment_group_presenter.rb index d333e34b7..c360ccd82 100644 --- a/app/presenters/support/establishment_group_presenter.rb +++ b/app/presenters/support/establishment_group_presenter.rb @@ -52,5 +52,9 @@ def group_type def ukprn super.presence || I18n.t("generic.not_provided") end + + def eligible_for_school_picker? + (mat_or_trust? || federation?) && organisations.count > 1 + end end end diff --git a/app/presenters/support/organisation_presenter.rb b/app/presenters/support/organisation_presenter.rb index 81b816310..bb30fb6b9 100644 --- a/app/presenters/support/organisation_presenter.rb +++ b/app/presenters/support/organisation_presenter.rb @@ -55,5 +55,9 @@ def gias_label def ukprn super.presence || I18n.t("generic.not_provided") end + + def eligible_for_school_picker? + false + end end end diff --git a/app/views/components/school_picker/_school_picker.html.erb b/app/views/components/school_picker/_school_picker.html.erb new file mode 100644 index 000000000..a34ef30ae --- /dev/null +++ b/app/views/components/school_picker/_school_picker.html.erb @@ -0,0 +1,14 @@ +
+
+ <%= render "components/school_picker/school_picker_filters", model: filters_model, url: filters_url, scope: %> +
+
+ <%= form_with model: results_model, scope:, url: update_url, method: do |form| %> + <%= form.govuk_error_summary %> + + <%= render "components/school_picker/school_picker_results", form: form, scope: %> + + <%= form.submit I18n.t("generic.button.save"), class: "govuk-button", role: "button" %> + <% end %> +
+
diff --git a/app/views/components/school_picker/_school_picker_filters.html.erb b/app/views/components/school_picker/_school_picker_filters.html.erb new file mode 100644 index 000000000..cec2e70c2 --- /dev/null +++ b/app/views/components/school_picker/_school_picker_filters.html.erb @@ -0,0 +1,10 @@ +
+ <%= form_with model:, scope:, method: :get, url:, html: { "data-controller" => "school-picker-filters", "data-school-picker-filters-school-picker-outlet" => ".school-picker", "data-school-picker-filters-scope-value" => scope } do |form| %> + <%= form.submit I18n.t("components.school_picker.filters.clear"), class: "govuk-button govuk-button--secondary", name: :clear, data: { action: "school-picker-filters#setSchoolUrns" } %> + + <%= form.fields :filters, model: do |f| %> + <%= f.govuk_collection_check_boxes :phases, school_picker_phase_filter_options(@all_schools), :id, :title, small: true, legend: { text: I18n.t("components.school_picker.filters.phase"), size: "s" } if show_school_picker_phase_filters?(@all_schools) %> + <%= f.govuk_collection_check_boxes :local_authorities, school_picker_la_filter_options(@all_schools), :id, :title, small: true, legend: { text: I18n.t("components.school_picker.filters.local_authority"), size: "s" } if show_school_picker_la_filters?(@all_schools) %> + <% end %> + <% end %> +
diff --git a/app/views/components/school_picker/_school_picker_results.html.erb b/app/views/components/school_picker/_school_picker_results.html.erb new file mode 100644 index 000000000..92cb0df18 --- /dev/null +++ b/app/views/components/school_picker/_school_picker_results.html.erb @@ -0,0 +1,32 @@ +
> +

+ + <%= I18n.t("components.school_picker.table.selected", total: @all_schools.count, group_name: @group.name).html_safe %> +

+ <%= form.govuk_check_boxes_fieldset :school_urns, legend: nil do %> + + + + + + + + + + + <% @filtered_schools.each do |school| %> + + + + + + + <% end %> + +
+ <%= form.govuk_check_box :school_urns, :all, label: { text: I18n.t("components.school_picker.table.school_name").html_safe }, "data-school-picker-target": "selectAll", "data-action": "school-picker#toggleSelectAll" %> + <%= I18n.t("components.school_picker.table.address") %><%= I18n.t("components.school_picker.table.phase") %><%= I18n.t("components.school_picker.table.local_authority") %>
+ <%= form.govuk_check_box :school_urns, school.urn, label: { text: school.name }, "data-action": "school-picker#toggleSelection" %> + <%= school.formatted_address %><%= school.phase %><%= school.local_authority %>
+ <% end %> +
diff --git a/app/views/framework_requests/confirm_schools/_form.html.erb b/app/views/framework_requests/confirm_schools/_form.html.erb index 438614e75..d96513c7e 100644 --- a/app/views/framework_requests/confirm_schools/_form.html.erb +++ b/app/views/framework_requests/confirm_schools/_form.html.erb @@ -13,9 +13,9 @@ <%= I18n.t("faf.confirm_schools.table.school_name") %> - <%= I18n.t("faf.school_picker.table.address") %> - <%= I18n.t("faf.school_picker.table.phase") %> - <%= I18n.t("faf.school_picker.table.local_authority") %> + <%= I18n.t("components.school_picker.table.address") %> + <%= I18n.t("components.school_picker.table.phase") %> + <%= I18n.t("components.school_picker.table.local_authority") %> diff --git a/app/views/framework_requests/school_pickers/_filters.html.erb b/app/views/framework_requests/school_pickers/_filters.html.erb index 4ba3da0dd..978e24fa4 100644 --- a/app/views/framework_requests/school_pickers/_filters.html.erb +++ b/app/views/framework_requests/school_pickers/_filters.html.erb @@ -3,13 +3,4 @@ url = edit ? edit_framework_request_school_picker_path : school_picker_framework_requests_path %> -
- <%= form_with model: @form, scope: :framework_support_form, method: :get, url:, html: { "data-controller" => "school-picker-filters", "data-school-picker-filters-school-picker-outlet" => ".school-picker" } do |form| %> - <%= form.submit I18n.t("faf.school_picker.filters.clear"), class: "govuk-button govuk-button--secondary", name: :clear, data: { action: "school-picker-filters#setSchoolUrns" } %> - - <%= form.fields :filters, model: @form.filters do |f| %> - <%= f.govuk_collection_check_boxes :phases, school_picker_phase_filter_options(@all_schools), :id, :title, small: true, legend: { text: I18n.t("faf.school_picker.filters.phase"), size: "s" } if show_school_picker_phase_filters?(@all_schools) %> - <%= f.govuk_collection_check_boxes :local_authorities, school_picker_la_filter_options(@all_schools), :id, :title, small: true, legend: { text: I18n.t("faf.school_picker.filters.local_authority"), size: "s" } if show_school_picker_la_filters?(@all_schools) %> - <% end %> - <% end %> -
+<%= render "components/school_picker/school_picker_filters", model: @form.filters, url:, scope: :framework_support_form %> diff --git a/app/views/framework_requests/school_pickers/_form.html.erb b/app/views/framework_requests/school_pickers/_form.html.erb index 544cca942..e8b5d65b0 100644 --- a/app/views/framework_requests/school_pickers/_form.html.erb +++ b/app/views/framework_requests/school_pickers/_form.html.erb @@ -1,35 +1,4 @@ <%= render "framework_requests/common_form_fields", form: form %> <%= form.hidden_field :source %> -
-

- - <%= I18n.t("faf.school_picker.table.selected", total: @all_schools.count, group_name: @group.name).html_safe %> -

- <%= form.govuk_check_boxes_fieldset :school_urns, legend: nil do %> - - - - - - - - - - - <% @filtered_schools.each do |school| %> - - - - - - - <% end %> - -
- <%= form.govuk_check_box :school_urns, :all, label: { text: I18n.t("faf.school_picker.table.school_name").html_safe }, "data-school-picker-target": "selectAll", "data-action": "school-picker#toggleSelectAll" %> - <%= I18n.t("faf.school_picker.table.address") %><%= I18n.t("faf.school_picker.table.phase") %><%= I18n.t("faf.school_picker.table.local_authority") %>
- <%= form.govuk_check_box :school_urns, school.urn, label: { text: school.name }, "data-action": "school-picker#toggleSelection" %> - <%= school.formatted_address %><%= school.phase %><%= school.local_authority %>
- <% end %> -
+<%= render "components/school_picker/school_picker_results", form: form, scope: :framework_support_form %> diff --git a/app/views/support/cases/confirm_organisation/show.html.erb b/app/views/support/cases/confirm_organisation/show.html.erb new file mode 100644 index 000000000..64ffb3428 --- /dev/null +++ b/app/views/support/cases/confirm_organisation/show.html.erb @@ -0,0 +1,44 @@ +<%= content_for :title, I18n.t("support.case_confirm_organisation.title") %> + +
+
+

<%= I18n.t("support.case_confirm_organisation.title") %>

+

+ <%= I18n.t("support.case_confirm_organisation.body", ref: @current_case.ref) %> +

+
+
+
+ <%= I18n.t("support.case_confirm_organisation.from") %> +
+
+ <%= @current_case.organisation.name %> +
+
+
+
+ <%= I18n.t("support.case_confirm_organisation.to") %> +
+
+ <%= @new_organisation.name %> +
+
+
+ +
+ + + Warning + <%= I18n.t("support.case_confirm_organisation.warning") %> + +
+ +
+ <%= button_to I18n.t("support.generic.confirm"), support_case_confirm_organisation_path, + method: :patch, + params: { type: @new_organisation.class }, + class: "govuk-button" %> + <%= link_to "Cancel", @back_url, class: "govuk-link govuk-link--no-visited-state" %> +
+
+
diff --git a/app/views/support/cases/school_details/participating_schools/edit.html.erb b/app/views/support/cases/school_details/participating_schools/edit.html.erb new file mode 100644 index 000000000..f9dfb67d2 --- /dev/null +++ b/app/views/support/cases/school_details/participating_schools/edit.html.erb @@ -0,0 +1,13 @@ +<%= turbo_frame_tag "school-details-frame" do %> +
+ <%= link_to I18n.t("support.case.label.school_details.participating_schools.edit.back"), @back_url, class: "govuk-back-link pull-up" %> + + <%= render "components/school_picker/school_picker", + results_model: @case_school_picker, + filters_model: @filters, + scope: :participating_schools, + update_url: support_case_school_details_participating_schools_path, + filters_url: edit_support_case_school_details_participating_schools_path, + method: :patch %> +
+<% end %> diff --git a/app/views/support/cases/school_details/participating_schools/show.html.erb b/app/views/support/cases/school_details/participating_schools/show.html.erb new file mode 100644 index 000000000..8fea7e746 --- /dev/null +++ b/app/views/support/cases/school_details/participating_schools/show.html.erb @@ -0,0 +1,29 @@ +<%= turbo_frame_tag "school-details-frame" do %> +
+ <%= link_to I18n.t("support.case.label.school_details.back"), @back_url, class: "govuk-back-link pull-up" %> +

+ <%= I18n.t("support.case.label.participating_schools") %> - <%= link_to I18n.t("support.case.link.change"), edit_support_case_school_details_participating_schools_path, class: "govuk-link govuk-link--no-visited-state" %> +

+ + + + + + + + + + + + <% @participating_schools.each do |school| %> + + + + + + + <% end %> + +
<%= I18n.t("support.case.label.school_details.participating_schools.table.school_name") %><%= I18n.t("support.case.label.school_details.participating_schools.table.address") %><%= I18n.t("support.case.label.school_details.participating_schools.table.phase") %><%= I18n.t("support.case.label.school_details.participating_schools.table.local_authority") %>
<%= school.name %><%= school.formatted_address %><%= school.phase %><%= school.local_authority %>
+
+<% end %> diff --git a/app/views/support/cases/school_details/show.html.erb b/app/views/support/cases/school_details/show.html.erb new file mode 100644 index 000000000..7144cb2fc --- /dev/null +++ b/app/views/support/cases/school_details/show.html.erb @@ -0,0 +1,114 @@ +<%= turbo_frame_tag "school-details-frame" do %> +
+

+ <%= I18n.t("support.case.header.school_detail") %> +

+ +
+
+
+ <%= I18n.t("support.case.label.contact_name") %> +
+
+ <%= @current_case.full_name %> +
+
+ <% unless @current_case.closed? %> + <%= link_to "Change", edit_support_case_contact_details_path(@current_case), class: "govuk-link", target: "_top" %> + <% end %> +
+
+ +
+
+ <%= I18n.t("support.case.label.contact_phone") %> +
+
+ <%= @current_case.phone_number %> +
+
+ <% unless @current_case.closed? %> + <%= link_to "Change", edit_support_case_contact_details_path(@current_case), class: "govuk-link", target: "_top" %> + <% end %> +
+
+ +
+
+ <%= I18n.t("support.case.label.contact_extension_number") %> +
+
+ <%= @current_case.extension_number %> +
+
+ <% unless @current_case.closed? %> + <%= link_to "Change", edit_support_case_contact_details_path(@current_case), class: "govuk-link", target: "_top" %> + <% end %> +
+
+ +
+
+ <%= I18n.t("support.case.label.contact_email") %> +
+
+ <%= @current_case.email %> +
+
+ <% unless @current_case.closed? %> + <%= link_to "Change", edit_support_case_contact_details_path(@current_case), class: "govuk-link", target: "_top" %> + <% end %> +
+
+ +
+
+ <%= I18n.t("support.case.label.organisation_name") %> +
+
+ <%= @current_case.organisation_name if @current_case.organisation.present? %> +
+
+ <% unless @current_case.closed? %> + <%= link_to @current_case.organisation.present? ? "Change" : "Add", + edit_support_case_organisation_path(@current_case), class: "govuk-link", target: "_top" %> + <% end %> +
+
+ +
+
+ <%= I18n.t("support.case.label.organisation_type") %> +
+
+ <%= @current_case.organisation_type_name %> +
+
+
+
+ + <% if @current_case.eligible_for_school_picker? %> +
+
+ <%= I18n.t("support.case.label.participating_schools") %> +
+
+ <%= @current_case.participating_schools.count %> +
+
+ <%= link_to I18n.t("support.generic.view"), support_case_school_details_participating_schools_path(@current_case), class: "govuk-link" %> +
+
+ <% end %> +
+ + <% if @current_case.organisation.present? %> +

+ <%= link_to @current_case.organisation_gias_label, + @current_case.organisation_gias_url, + class: "govuk-link", target: "_blank", rel: "noreferrer noopener" + %> +

+ <% end %> +
+<% end %> diff --git a/app/views/support/cases/show/_school_details.html.erb b/app/views/support/cases/show/_school_details.html.erb index 3a345cd15..0d103edbc 100644 --- a/app/views/support/cases/show/_school_details.html.erb +++ b/app/views/support/cases/show/_school_details.html.erb @@ -1,98 +1,5 @@ -
-

- <%= I18n.t("support.case.header.school_detail") %> -

- -
-
-
- <%= I18n.t("support.case.label.contact_name") %> -
-
- <%= current_case.full_name %> -
-
- <% unless current_case.closed? %> - <%= link_to "Change", edit_support_case_contact_details_path(current_case), class: "govuk-link" %> - <% end %> -
-
- -
-
- <%= I18n.t("support.case.label.contact_phone") %> -
-
- <%= current_case.phone_number %> -
-
- <% unless current_case.closed? %> - <%= link_to "Change", edit_support_case_contact_details_path(current_case), class: "govuk-link" %> - <% end %> -
-
- -
-
- <%= I18n.t("support.case.label.contact_extension_number") %> -
-
- <%= current_case.extension_number %> -
-
- <% unless current_case.closed? %> - <%= link_to "Change", edit_support_case_contact_details_path(current_case), class: "govuk-link" %> - <% end %> -
-
- -
-
- <%= I18n.t("support.case.label.contact_email") %> -
-
- <%= current_case.email %> -
-
- <% unless current_case.closed? %> - <%= link_to "Change", edit_support_case_contact_details_path(current_case), class: "govuk-link" %> - <% end %> -
-
- -
-
- <%= I18n.t("support.case.label.organisation_name") %> -
-
- <%= current_case.organisation_name if current_case.organisation.present? %> -
-
- <% unless current_case.closed? %> - <%= link_to current_case.organisation.present? ? "Change" : "Add", - edit_support_case_organisation_path(current_case), class: "govuk-link" %> - <% end %> -
-
- -
-
- <%= I18n.t("support.case.label.organisation_type") %> -
-
- <%= current_case.organisation_type_name %> -
-
-
-
-
- - <% if current_case.organisation.present? %> -

- <%= link_to current_case.organisation_gias_label, - current_case.organisation_gias_url, - class: "govuk-link", target: "_blank", rel: "noreferrer noopener" - %> -

- <% end %> -
+<%= turbo_frame_tag "school-details-frame", src: support_case_school_details_path(@current_case) do %> +
+

Loading...

+
+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 9959e11e7..6e1660d5a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -68,6 +68,25 @@ en: destroy: You have been signed out. failure: Sign in failed unexpectedly, please try again. visitor: You must sign in. + components: + school_picker: + filters: + phase: Filter by learning stage + local_authority: Filter by local authority + clear: Clear filters + table: + school_name: School name (select all) + address: Address + phase: Phase of education + local_authority: Local authority + selected: "of %{total} schools selected from %{group_name}" + phases: + no_phase: No phase + primary: Primary + middle: Middle + secondary: Secondary + all_through: All-through + sixteen_plus: 16-plus cookies: banner: accepted: @@ -452,23 +471,6 @@ en: title: Which schools in your academy trust or federation will be involved in this procurement? caption: About your school subtitle: Select all that apply - filters: - phase: Filter by learning stage - local_authority: Filter by local authority - clear: Clear filters - table: - school_name: School name (select all) - address: Address - phase: Phase of education - local_authority: Local authority - selected: "of %{total} schools selected from %{group_name}" - phases: - no_phase: No phase - primary: Primary - middle: Middle - secondary: Secondary - all_through: All-through - sixteen_plus: 16-plus name: first_name: label: First Name @@ -943,6 +945,16 @@ en: phase: Phase of education local_authority: Local authority uploaded_files: Uploaded files + school_details: + back: Back to school details + participating_schools: + edit: + back: Back to participating schools + table: + school_name: School name + address: Address + phase: Phase of education + local_authority: Local authority sort_by: Sort by source: digital: Specify case @@ -1072,6 +1084,12 @@ en: last_updated: Last updated organisation: Organisation sub_category: Sub-category + case_confirm_organisation: + title: Confirm organisation update + body: You are about to update the organisation for case %{ref}. + from: From + to: To + warning: This will remove all existing participating schools on the case. case_contact_details: flash: updated: Contact details updated successfully @@ -1428,6 +1446,7 @@ en: "yes": "Yes" "no": "No" view: View + confirm: Confirm helpers: tag_bar: remove_tag: "Remove tag %{tag}" diff --git a/config/routes.rb b/config/routes.rb index c5ccfa9d7..eedff6740 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -200,6 +200,7 @@ resources :files, only: %i[index edit update destroy] resource :merge_emails, only: %i[new create show], path: "merge-emails" resource :organisation, only: %i[edit update] + resources :confirm_organisation, only: %i[show update] resource :contact_details, only: %i[edit update] resource :closures, only: %i[edit update] resource :savings, only: %i[edit update] @@ -233,6 +234,11 @@ end resources :email_templates, only: %i[index], constraints: ->(_request) { Flipper.enabled?(:email_templates) } resource :quick_edit, only: %i[edit update] + resource :school_details, only: %i[show] do + scope module: :school_details do + resource :participating_schools, only: %i[show edit update] + end + end resource :request, only: %i[show] do scope module: :requests do resource :participating_schools, only: %i[show] diff --git a/spec/controllers/support/cases/organisations_controller_spec.rb b/spec/controllers/support/cases/organisations_controller_spec.rb new file mode 100644 index 000000000..16439ca48 --- /dev/null +++ b/spec/controllers/support/cases/organisations_controller_spec.rb @@ -0,0 +1,21 @@ +describe Support::Cases::OrganisationsController, type: :controller do + before { agent_is_signed_in } + + describe "on update" do + context "when the case has participating schools" do + let(:establishment_group) { create(:support_establishment_group, uid: "123") } + let(:participating_school) { create(:support_organisation, trust_code: "123") } + let(:support_case) { create(:support_case, organisation: establishment_group) } + let(:organisation_new) { create(:support_organisation) } + + before do + create(:support_case_organisation, case: support_case, organisation: participating_school) + end + + it "redirects to the organisation confirmation page" do + patch(:update, params: { case_id: support_case.id, case_organisation_form: { organisation_id: organisation_new.id, organisation_type: organisation_new.class.name } }) + expect(response).to redirect_to "/support/cases/#{support_case.id}/confirm_organisation/#{organisation_new.id}?type=#{CGI.escape(organisation_new.class.name)}" + end + end + end +end diff --git a/spec/factories/support/case_organisation.rb b/spec/factories/support/case_organisation.rb new file mode 100644 index 000000000..d906b257f --- /dev/null +++ b/spec/factories/support/case_organisation.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :support_case_organisation, class: "Support::CaseOrganisation" do + association :case, factory: :support_case + association :organisation, factory: :support_organisation + end +end diff --git a/spec/features/support/agent_can_set_case_contact_spec.rb b/spec/features/support/agent_can_set_case_contact_spec.rb index d45ed4ad2..7c887f850 100644 --- a/spec/features/support/agent_can_set_case_contact_spec.rb +++ b/spec/features/support/agent_can_set_case_contact_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe "Agent can set case contact details" do +describe "Agent can set case contact details", js: true do include_context "with an agent" let(:support_case) do diff --git a/spec/features/support/agent_can_update_participating_schools_spec.rb b/spec/features/support/agent_can_update_participating_schools_spec.rb new file mode 100644 index 000000000..bdbe8e363 --- /dev/null +++ b/spec/features/support/agent_can_update_participating_schools_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +describe "Agent can update participating schools", js: true do + include_context "with an agent" + + let(:organisation) { create(:support_establishment_group, uid: "123", establishment_group_type: create(:support_establishment_group_type, code: "6")) } + let(:support_case) { create(:support_case, ref: "000001", agent:, organisation:) } + + before do + create_list(:support_organisation, 3, trust_code: "123") + + visit support_case_path(support_case) + click_link "School details" + within("#school-details") do + click_link "View" + click_link "change" + check "School #1" + check "School #2" + click_button "Save" + sleep 0.2 + end + end + + it "updates participating schools" do + expect(support_case.participating_schools.pluck(:name)).to match_array(["School #1", "School #2"]) + end +end diff --git a/spec/features/support/case_organisation_details_spec.rb b/spec/features/support/case_organisation_details_spec.rb index 484ba47f9..5108b0428 100644 --- a/spec/features/support/case_organisation_details_spec.rb +++ b/spec/features/support/case_organisation_details_spec.rb @@ -1,4 +1,4 @@ -describe "Case organisation details" do +describe "Case organisation details", js: true do subject(:support_case) do create(:support_case, :opened, organisation: school) end diff --git a/spec/features/support/case_school_details_spec.rb b/spec/features/support/case_school_details_spec.rb index 7fc6952a6..45cf4253e 100644 --- a/spec/features/support/case_school_details_spec.rb +++ b/spec/features/support/case_school_details_spec.rb @@ -1,4 +1,4 @@ -describe "Case school details" do +describe "Case school details", js: true do include_context "with an agent" let(:support_organisation) { create(:support_organisation, urn: "12345", name: "School #1") } diff --git a/spec/features/support/case_tabs_spec.rb b/spec/features/support/case_tabs_spec.rb index c324d2cdd..86753f259 100644 --- a/spec/features/support/case_tabs_spec.rb +++ b/spec/features/support/case_tabs_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Case summary" do +RSpec.feature "Case summary", js: true do include_context "with an agent" before do