diff --git a/app/controllers/engagement/case_requests/school_pickers_controller.rb b/app/controllers/engagement/case_requests/school_pickers_controller.rb new file mode 100644 index 000000000..0a4c97d14 --- /dev/null +++ b/app/controllers/engagement/case_requests/school_pickers_controller.rb @@ -0,0 +1,28 @@ +module Engagement + module CaseRequests + class SchoolPickersController < ApplicationController + def edit + @case_request = CaseRequest.find(params[:id]) + @back_url = params[:source] == "change_link" ? engagement_case_request_path(@case_request) : edit_engagement_case_request_path(@case_request) + @school_picker = @case_request.school_picker + @group = @case_request.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_request = CaseRequest.find(params[:id]) + @school_picker = @case_request.school_picker(school_urns: form_params[:school_urns].compact_blank) + @school_picker.save! + redirect_to engagement_case_request_path(@case_request) + end + + private + + def form_params + params.fetch(:case_request, {}).permit(filters: params.key?(:clear) ? nil : { local_authorities: [], phases: [] }, school_urns: []) + end + end + end +end diff --git a/app/controllers/engagement/case_requests_controller.rb b/app/controllers/engagement/case_requests_controller.rb index 80947abdc..9977399fb 100644 --- a/app/controllers/engagement/case_requests_controller.rb +++ b/app/controllers/engagement/case_requests_controller.rb @@ -1,31 +1,38 @@ module Engagement class CaseRequestsController < ApplicationController - before_action -> { @back_url = engagement_cases_path }, only: %i[new create] + def create + @case_request = CaseRequest.new(source: :engagement_and_outreach_cms, creation_source: :engagement_and_outreach_team, created_by: current_agent) + @case_request.save!(validate: false) + redirect_to edit_engagement_case_request_path(@case_request, source: :create) + end - def new - @case_request = CaseRequest.new - @upload_reference = SecureRandom.hex + def show + @case_request = CaseRequest.find(params[:id]) end - def create - @case_request = CaseRequest.new(form_params.except(:upload_reference)) - @case_request.created_by = current_agent + def edit + @case_request = CaseRequest.find(params[:id]) + @back_url = params[:source] == "create" ? engagement_cases_path : engagement_case_request_path(@case_request) + end + + def update + @case_request = CaseRequest.find(params[:id]) + @back_url = engagement_case_request_path(@case_request) + @case_request.assign_attributes(form_params.compact_blank) if @case_request.valid? + org_changed = @case_request.organisation_changed? @case_request.save! - # kase = @case_request.create_case - - # CaseFiles::SubmitCaseUpload.new.call(upload_reference: form_params[:upload_reference], support_case_id: kase.id) - - # create_interaction(kase.id, "create_case", "Case created", @case_request.attributes.slice(:source, :category)) - - redirect_to @case_request.eligible_for_school_picker? ? edit_support_case_request_school_picker_path(@case_request) : engagement_case_request_path(@case_request) + redirect_to(org_changed && @case_request.eligible_for_school_picker? ? edit_engagement_case_request_school_picker_path(@case_request) : engagement_case_request_path(@case_request)) else - render :new + render :edit end end def submit + @case_request = CaseRequest.find(params[:id]) + @case_request.create_case + redirect_to engagement_cases_path end private @@ -47,11 +54,7 @@ def form_params :other_category, :other_query, :procurement_amount, - :upload_reference, - ).merge({ - source: :engagement_and_outreach_cms.to_s, - creation_source: :engagement_and_outreach_team.to_s, - }) + ) end end end diff --git a/app/controllers/engagement/cases/uploads_controller.rb b/app/controllers/engagement/cases/uploads_controller.rb index 918ea9046..163ff7925 100644 --- a/app/controllers/engagement/cases/uploads_controller.rb +++ b/app/controllers/engagement/cases/uploads_controller.rb @@ -7,13 +7,13 @@ def upload if file_is_safe? upload = EngagementCaseUpload.pending.create!( file: params[:file], - upload_reference: params[:upload_reference], + case_request_id: params[:upload_reference], filename: params[:file].original_filename, filesize: File.size(params[:file].tempfile.path), ) render status: :ok, json: { file_id: upload.id }.to_json else - Rollbar.error("Infected file uploaded", upload_reference: params[:upload_reference]) + Rollbar.error("Infected file uploaded", case_request_id: params[:upload_reference]) params[:file].tempfile.delete @@ -29,7 +29,7 @@ def remove def list reference = params[:upload_reference] - files = EngagementCaseUpload.where(upload_reference: reference) + files = EngagementCaseUpload.where(case_request_id: reference) result = files.map do |f| { file_id: f.id, diff --git a/app/controllers/support/case_requests_controller.rb b/app/controllers/support/case_requests_controller.rb index 0d3b10d88..3ffa884c2 100644 --- a/app/controllers/support/case_requests_controller.rb +++ b/app/controllers/support/case_requests_controller.rb @@ -1,28 +1,37 @@ module Support class CaseRequestsController < ApplicationController - before_action -> { @back_url = support_cases_path }, only: %i[new create] + def create + @case_request = CaseRequest.new(created_by: current_agent) + @case_request.save!(validate: false) + redirect_to edit_support_case_request_path(@case_request, source: :create) + end - def new - @case_request = CaseRequest.new + def show + @case_request = CaseRequest.find(params[:id]) end - def create - @case_request = CaseRequest.new(form_params.except(:upload_reference)) - @case_request.created_by = current_agent + def edit + @case_request = CaseRequest.find(params[:id]) + @back_url = params[:source] == "create" ? support_cases_path : support_case_request_path(@case_request) + end + + def update + @case_request = ::CaseRequest.find(params[:id]) + @back_url = support_case_request_path(@case_request) + @case_request.assign_attributes(form_params.compact_blank) if @case_request.valid? @case_request.save! - # kase = @case_request.create_case - - # create_interaction(kase.id, "create_case", "Case created", @case_request.attributes.slice(:source, :category)) - redirect_to support_case_request_path(@case_request) else - render :new + render :edit end end def submit + @case_request = ::CaseRequest.find(params[:id]) + kase = @case_request.create_case + redirect_to support_case_path(kase) end private diff --git a/app/controllers/support/cases/request_details/participating_schools_controller.rb b/app/controllers/support/cases/request_details/participating_schools_controller.rb new file mode 100644 index 000000000..85cb27132 --- /dev/null +++ b/app/controllers/support/cases/request_details/participating_schools_controller.rb @@ -0,0 +1,12 @@ +module Support + module Cases + module RequestDetails + class ParticipatingSchoolsController < Cases::ApplicationController + def show + @back_url = support_case_request_details_path + @participating_schools = @current_case.request.selected_schools.map { |s| Support::OrganisationPresenter.new(s) } + end + end + end + end +end diff --git a/app/controllers/support/cases/requests_controller.rb b/app/controllers/support/cases/request_details_controller.rb similarity index 54% rename from app/controllers/support/cases/requests_controller.rb rename to app/controllers/support/cases/request_details_controller.rb index 696eca7f8..ce53ee87c 100644 --- a/app/controllers/support/cases/requests_controller.rb +++ b/app/controllers/support/cases/request_details_controller.rb @@ -1,8 +1,8 @@ module Support module Cases - class RequestsController < Cases::ApplicationController + class RequestDetailsController < Cases::ApplicationController def show - @request = FrameworkRequestPresenter.new(@current_case.framework_request) + @request = FrameworkRequestPresenter.new(@current_case.request) end private diff --git a/app/controllers/support/cases/requests/participating_schools_controller.rb b/app/controllers/support/cases/requests/participating_schools_controller.rb deleted file mode 100644 index bd0deb028..000000000 --- a/app/controllers/support/cases/requests/participating_schools_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Support - module Cases - module Requests - class ParticipatingSchoolsController < Cases::ApplicationController - def show - @back_url = support_case_request_path - @participating_schools = @current_case.framework_request.selected_schools.map { |s| Support::OrganisationPresenter.new(s) } - end - end - end - end -end diff --git a/app/models/case_request.rb b/app/models/case_request.rb index 72b7b6a93..c9d2540c1 100644 --- a/app/models/case_request.rb +++ b/app/models/case_request.rb @@ -1,10 +1,16 @@ class CaseRequest < ApplicationRecord + include SchoolPickable + + before_save :clear_school_urns, if: -> { attribute_changed?(:organisation_id) } + belongs_to :category, class_name: "Support::Category", optional: true belongs_to :query, class_name: "Support::Query", optional: true belongs_to :organisation, polymorphic: true, optional: true belongs_to :created_by, class_name: "Support::Agent", optional: true belongs_to :support_case, class_name: "Support::Case", optional: true + has_many :engagement_case_uploads, class_name: "EngagementCaseUpload" + enum source: { digital: 0, nw_hub: 1, sw_hub: 2, incoming_email: 3, faf: 4, engagement_and_outreach: 5, schools_commercial_team: 6, engagement_and_outreach_cms: 7 } enum creation_source: { default: 0, engagement_and_outreach_team: 5 } @@ -18,16 +24,10 @@ class CaseRequest < ApplicationRecord validates :other_category, presence: true, if: -> { category_id == Support::Category.other_category_id } validates :other_query, presence: true, if: -> { query_id == Support::Query.other_query_id } - def organisation_name - return nil unless organisation - - organisation.name - end - - def organisation_urn - return nil unless organisation + attribute :creation_source, default: :default - organisation.urn + def full_name + "#{first_name} #{last_name}" end def request_type @@ -36,18 +36,64 @@ def request_type category.present? end + def type + request_type ? I18n.t("support.case_hub_migration.label.procurement") : I18n.t("support.case_hub_migration.label.non_procurement") + end + + def contract_length = nil + + def flow = nil + + def same_supplier_used = nil + + def origin = nil + + def selected_schools + school_urns.map { |urn| Support::Organisation.find_by(urn:) } + end + def eligible_for_school_picker? return false unless organisation.is_a?(Support::EstablishmentGroup) organisation.eligible_for_school_picker? end + def multischool? + school_urns.present? + end + def create_case - CreateCase.new(attributes).call + transaction do + attrs = attributes.symbolize_keys.merge(participating_schools: school_urns.map { |urn| Support::Organisation.find_by(urn:) }, creator: created_by) + kase = Support::CreateCase.new(attrs).call + submit_uploads(kase.id) if engagement_case_uploads.present? + Support::CreateInteraction.new(kase.id, "create_case", created_by.id, { body: "Case created", additional_data: attrs.slice(:source, :category).compact }).call + update!(support_case: kase) + kase + end end private + def submit_uploads(support_case_id) + engagement_case_uploads.update_all(upload_status: :submitted, support_case_id:) + + engagement_case_uploads.each do |upload| + Support::CaseAttachment.create( + attachable: upload, + support_case_id:, + custom_name: upload.file_name, + description: "User uploaded attachment", + created_at: upload.created_at, + updated_at: upload.updated_at, + ) + end + end + + def clear_school_urns + self.school_urns = [] + end + def request_type_validation return if category.present? || query.present? diff --git a/app/models/case_request/school_pickable.rb b/app/models/case_request/school_pickable.rb new file mode 100644 index 000000000..89fe6c483 --- /dev/null +++ b/app/models/case_request/school_pickable.rb @@ -0,0 +1,12 @@ +module CaseRequest::SchoolPickable + extend ActiveSupport::Concern + + def school_picker(school_urns: self.school_urns) + CaseRequest::SchoolPicker.new(case_request: self, school_urns:) + end + + def pick_schools(school_urns) + self.school_urns = school_urns + save! + end +end diff --git a/app/models/case_request/school_picker.rb b/app/models/case_request/school_picker.rb new file mode 100644 index 000000000..7921a9b62 --- /dev/null +++ b/app/models/case_request/school_picker.rb @@ -0,0 +1,12 @@ +class CaseRequest::SchoolPicker + include ActiveModel::Model + + attr_accessor( + :case_request, + :school_urns, + ) + + def save! + case_request.pick_schools(school_urns) + end +end diff --git a/app/models/support/establishment_group.rb b/app/models/support/establishment_group.rb index a373ebddf..7d667ba0d 100644 --- a/app/models/support/establishment_group.rb +++ b/app/models/support/establishment_group.rb @@ -11,6 +11,10 @@ def formatted_name "#{uid} - #{name}" end + def postcode + address["postcode"] + end + def organisations return Support::Organisation.where(federation_code: uid) if federation? diff --git a/app/views/components/_new_case_request_components.html.erb b/app/views/components/_new_case_request_components.html.erb index 1eb51d761..0af83caca 100644 --- a/app/views/components/_new_case_request_components.html.erb +++ b/app/views/components/_new_case_request_components.html.erb @@ -9,11 +9,10 @@ element_name: "case_request[organisation_name]", template_suggestion: "{{name}}, {{postcode}}
{{establishment_type}}
URN: {{urn}} - UKPRN: {{ukprn}}", value_field: :name, - default_value: form.object.organisation_name, + default_value: form.object.organisation&.name, hidden_fields: { - 'case_request[organisation_id]' => [:id, form.object.organisation_id], - 'case_request[organisation_type]' => [:source, form.object.organisation_type], - 'case_request[organisation_urn]' => [:urn, form.object.organisation_urn], + 'case_request[organisation_id]' => [:id, form.object.organisation&.id], + 'case_request[organisation_type]' => [:source, form.object.organisation.class&.name], }, query_url: support_establishments_path(format: :json, q: "{{QUERY}}") %> diff --git a/app/views/engagement/case_requests/new.html.erb b/app/views/engagement/case_requests/edit.html.erb similarity index 88% rename from app/views/engagement/case_requests/new.html.erb rename to app/views/engagement/case_requests/edit.html.erb index b86a4cfb7..52097867c 100644 --- a/app/views/engagement/case_requests/new.html.erb +++ b/app/views/engagement/case_requests/edit.html.erb @@ -1,12 +1,11 @@
- <%= form_with model: @case_request, scope: :case_request, url: engagement_case_requests_path, html: { + <%= form_with model: @case_request, scope: :case_request, method: :patch, url: engagement_case_request_path, html: { "data-controller" => "case-attachment", "data-action" => "submit->case-attachment#onFormSubmitted", "data-case-attachment-target" => "form", "data-case-attachment-dropzone-outlet" => ".drop-zone-container", - "data-case-attachment-error-summary-outlet" => ".govuk-error-summary", - "data-case-attachment-reference-value" => @upload_reference + "data-case-attachment-error-summary-outlet" => ".govuk-error-summary" } do |form| %> <%= form.govuk_error_summary %> @@ -17,9 +16,9 @@
+ data-dropzone-list-files-url-value="<%= list_uploads_engagement_cases_url(@case_request.id) %>" + data-dropzone-add-file-url-value="<%= add_uploads_engagement_cases_url(@case_request.id) %>" + data-dropzone-remove-file-url-value="<%= remove_uploads_engagement_cases_url(@case_request.id) %>">
@@ -64,7 +63,6 @@
- <%= form.hidden_field :upload_reference, :value => @upload_reference %> <%= form.submit I18n.t("support.case_hub_migration.submit"), class: "govuk-button", role: "button", "data-prevent-double-click" => true, "data-case-attachment-target" => "btnSubmit" %>
<% end %> diff --git a/app/views/engagement/case_requests/school_pickers/edit.html.erb b/app/views/engagement/case_requests/school_pickers/edit.html.erb new file mode 100644 index 000000000..d4cb5ed97 --- /dev/null +++ b/app/views/engagement/case_requests/school_pickers/edit.html.erb @@ -0,0 +1,9 @@ +

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

+ +<%= render "components/school_picker/school_picker", + results_model: @school_picker, + filters_model: @filters, + scope: :case_request, + update_url: engagement_case_request_school_picker_path(@case_request), + filters_url: edit_engagement_case_request_school_picker_path(@case_request), + method: :patch %> diff --git a/app/views/engagement/case_requests/show.html.erb b/app/views/engagement/case_requests/show.html.erb new file mode 100644 index 000000000..6028c1a64 --- /dev/null +++ b/app/views/engagement/case_requests/show.html.erb @@ -0,0 +1,270 @@ +
+
+

+ <%= I18n.t("support.case_hub_migration.edit.header") %> +

+ +

+ <%= I18n.t("support.case_hub_migration.edit.section.establishment") %> +

+ +
+
+
+ <%= I18n.t("support.case_hub_migration.label.school_name") %> +
+
+ <%= @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" %> +
+
+ +
+
+ <%= 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?(:urn) %> +
+
+ <%= I18n.t("support.case_hub_migration.label.school_urn") %> +
+
+ <%= @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" %> +
+
+ <% end %> + + <% if @case_request.organisation.respond_to?(:uid) %> +
+
+ <%= I18n.t("support.case_hub_migration.label.school_uid") %> +
+
+ <%= @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" %> +
+
+ <% 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.multischool? %> +
+
+ <%= I18n.t("support.case_hub_migration.label.participating_schools") %> +
+
+ <%= 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" %> +
+
+ <% end %> +
+ +

+ <%= I18n.t("support.case_hub_migration.edit.section.contact") %> +

+ +
+
+
+ <%= I18n.t("support.case_hub_migration.label.name") %> +
+
+ <%= @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" %> +
+
+ +
+
+ <%= I18n.t("support.case_hub_migration.label.email") %> +
+
+ <%= @case_request.email %> +
+
+ <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %> +
+
+ +
+
+ <%= I18n.t("support.case_hub_migration.label.phone_number", optional: nil) %> +
+
+ <%= @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" %> +
+
+ +
+
+ <%= I18n.t("support.case_hub_migration.label.extension_number", optional: nil) %> +
+
+ <%= @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" %> +
+
+
+ +

+ <%= I18n.t("support.case.label.discovery_method.legend") %> +

+ +
+
+
+ <%= I18n.t("support.case.label.discovery_method.field") %> +
+
+ <%= I18n.t("support.case.label.discovery_method.#{Support::Case::discovery_methods.keys[@case_request.discovery_method]}") %> + <%= 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" %> +
+
+
+ +

+ <%= I18n.t("support.case_hub_migration.edit.section.source") %> +

+ +
+
+
+ <%= I18n.t("support.case_hub_migration.label.case_source") %> +
+
+ <%= I18n.t("support.case.label.source.#{@case_request.source}") %> +
+
+ <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %> +
+
+
+ + +

+ <%= I18n.t("support.case_hub_migration.edit.section.case") %> +

+ +
+ +
+
+ <%= I18n.t("support.case_hub_migration.label.type") %> +
+
+ <%= @case_request.type %> +
+
+ <%= link_to I18n.t("generic.button.change_answer"), edit_engagement_case_request_path, class: "govuk-link govuk-link--no-visited-state" %> +
+
+ + <% if @case_request.type == "Procurement" %> +
+
+ <%= I18n.t("support.case_hub_migration.label.sub_category") %> +
+
+ <%= @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" %> +
+
+ <% else %> +
+
+ <%= I18n.t("support.case_hub_migration.label.query") %> +
+
+ <%= @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" %> +
+
+ <% end %> +
+ +

+ <%= I18n.t("support.case_hub_migration.edit.section.request_text") %> +

+ +
+
+
+ <%= I18n.t("support.case_hub_migration.label.request_text") %> +
+
+ <%= 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" %> +
+
+
+ +

+ <%= I18n.t("support.case_hub_migration.edit.section.case_details") %> +

+ +
+
+
+ <%= I18n.t("support.case_hub_migration.label.procurement_value") %> +
+
+ <%= 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" %> +
+
+
+ +

+ <%= I18n.t("support.case_hub_migration.edit.label.confirm") %> +

+ + <%= button_to I18n.t("support.case_hub_migration.edit.submit"), submit_engagement_case_request_path, class: "govuk-button", data: { disable_with: "Submitting..." } %> +
+
diff --git a/app/views/engagement/cases/index.html.erb b/app/views/engagement/cases/index.html.erb index 0bd38794e..17ac236c7 100644 --- a/app/views/engagement/cases/index.html.erb +++ b/app/views/engagement/cases/index.html.erb @@ -1,4 +1,4 @@ -<%= link_to I18n.t("support.case.label.create"), new_engagement_case_request_path, class: "govuk-button", role: "button" %> +<%= button_to I18n.t("support.case.label.create"), engagement_case_requests_path, class: "govuk-button" %>
    diff --git a/app/views/support/case_requests/new.html.erb b/app/views/support/case_requests/edit.html.erb similarity index 88% rename from app/views/support/case_requests/new.html.erb rename to app/views/support/case_requests/edit.html.erb index 569f71afe..5d9689f52 100644 --- a/app/views/support/case_requests/new.html.erb +++ b/app/views/support/case_requests/edit.html.erb @@ -1,6 +1,6 @@
    - <%= form_with model: @case_request, scope: :case_request, url: support_case_requests_path do |form| %> + <%= form_with model: @case_request, scope: :case_request, method: :patch, url: support_case_request_path do |form| %> <%= form.govuk_error_summary %> <%= render "components/new_case_request_components", form: %> diff --git a/app/views/support/case_requests/show.html.erb b/app/views/support/case_requests/show.html.erb index da600b40b..cc0f13cec 100644 --- a/app/views/support/case_requests/show.html.erb +++ b/app/views/support/case_requests/show.html.erb @@ -1,242 +1,256 @@
    - <%= form_with url: support_cases_path, scope: :create_case_form, method: :post, class: "new-case-form" do |form| %> -

    - <%= I18n.t("support.case_hub_migration.edit.header") %> -

    +

    + <%= I18n.t("support.case_hub_migration.edit.header") %> +

    -

    - <%= I18n.t("support.case_hub_migration.edit.section.establishment") %> -

    +

    + <%= I18n.t("support.case_hub_migration.edit.section.establishment") %> +

    -
    -
    -
    - <%= I18n.t("support.case_hub_migration.label.school_name") %> -
    -
    - <%= @form.organisation_name %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    +
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.school_name") %> +
    +
    + <%= @case_request.organisation.name %> +
    +
    + <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %> +
    +
    -
    -
    - <%= I18n.t("support.case_hub_migration.label.school_postcode") %> -
    -
    - <%= @form.organisation_postcode %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    +
    +
    + <%= 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?(:urn) %>
    <%= I18n.t("support.case_hub_migration.label.school_urn") %>
    - <%= @form.organisation_urn %> + <%= @case_request.organisation.urn %>
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> + <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
    + <% end %> + <% if @case_request.organisation.respond_to?(:uid) %>
    - <%= I18n.t("support.case_hub_migration.label.school_ukprn") %> + <%= I18n.t("support.case_hub_migration.label.school_uid") %>
    - <%= @form.organisation_ukprn %> + <%= @case_request.organisation.uid %>
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> +
    + <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
    -
    + <% end %> -

    - <%= I18n.t("support.case_hub_migration.edit.section.contact") %> -

    +
    +
    + <%= 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" %> +
    +
    +
    -
    -
    -
    - <%= I18n.t("support.case_hub_migration.label.name") %> -
    -
    - <%= @form.full_name %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    +

    + <%= I18n.t("support.case_hub_migration.edit.section.contact") %> +

    -
    -
    - <%= I18n.t("support.case_hub_migration.label.email") %> -
    -
    - <%= @form.email %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    +
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.name") %> +
    +
    + <%= @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" %> +
    +
    -
    -
    - <%= I18n.t("support.case_hub_migration.label.phone_number", optional: nil) %> -
    -
    - <%= @form.phone_number %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.email") %> +
    +
    + <%= @case_request.email %> +
    +
    + <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %> +
    +
    -
    -
    - <%= I18n.t("support.case_hub_migration.label.extension_number", optional: nil) %> -
    -
    - <%= @form.extension_number %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    -
    - -

    - <%= I18n.t("support.case.label.discovery_method.legend") %> -

    +
    +
    + <%= I18n.t("support.case_hub_migration.label.phone_number", optional: nil) %> +
    +
    + <%= @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" %> +
    +
    -
    -
    -
    - <%= I18n.t("support.case.label.discovery_method.field") %> -
    -
    - <%= I18n.t("support.case.label.discovery_method.#{Support::Case::discovery_methods.keys[@form.discovery_method]}") %> - <%= if @form.discovery_method == Support::Case::discovery_methods[:other] && !@form.discovery_method_other_text.empty? then "- #{@form.discovery_method_other_text}" end %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    -
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.extension_number", optional: nil) %> +
    +
    + <%= @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" %> +
    +
    +
    + +

    + <%= I18n.t("support.case.label.discovery_method.legend") %> +

    -

    - <%= I18n.t("support.case_hub_migration.edit.section.source") %> -

    +
    +
    +
    + <%= I18n.t("support.case.label.discovery_method.field") %> +
    +
    + <%= I18n.t("support.case.label.discovery_method.#{Support::Case::discovery_methods.keys[@case_request.discovery_method]}") %> + <%= 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" %> +
    +
    +
    -
    -
    -
    - <%= I18n.t("support.case_hub_migration.label.case_source") %> -
    -
    - <%= I18n.t("support.case.label.source.#{@form.source}") %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    -
    - +

    + <%= I18n.t("support.case_hub_migration.edit.section.source") %> +

    + +
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.case_source") %> +
    +
    + <%= 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" %> +
    +
    +
    + -

    - <%= I18n.t("support.case_hub_migration.edit.section.case") %> -

    +

    + <%= I18n.t("support.case_hub_migration.edit.section.case") %> +

    -
    +
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.type") %> +
    +
    + <%= @case_request.type %> +
    +
    + <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %> +
    +
    + + <% if @case_request.type == "Procurement" %>
    - <%= I18n.t("support.case_hub_migration.label.type") %> + <%= I18n.t("support.case_hub_migration.label.sub_category") %>
    - <%= @form.type %> + <%= @case_request.category.title %>
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> +
    + <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
    - - <% if @form.type == "Procurement" %> -
    -
    - <%= I18n.t("support.case_hub_migration.label.sub_category") %> -
    -
    - <%= @form.category_name %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    - <% else %> -
    -
    - <%= I18n.t("support.case_hub_migration.label.query") %> -
    -
    - <%= @form.query_name %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    - <% end %> -
    - -

    - <%= I18n.t("support.case_hub_migration.edit.section.request_text") %> -

    - -
    + <% else %>
    - <%= I18n.t("support.case_hub_migration.label.request_text") %> + <%= I18n.t("support.case_hub_migration.label.query") %>
    - <%= simple_format(@form.request_text, class: "govuk-body") %> + <%= @case_request.query.title %>
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> +
    + <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
    -
    + <% end %> +
    + +

    + <%= I18n.t("support.case_hub_migration.edit.section.request_text") %> +

    -

    - <%= I18n.t("support.case_hub_migration.edit.section.case_details") %> -

    +
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.request_text") %> +
    +
    + <%= 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" %> +
    +
    +
    -
    -
    -
    - <%= I18n.t("support.case_hub_migration.label.procurement_value") %> -
    -
    - <%= @form.procurement_amount %> -
    -
    - <%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %> -
    -
    -
    +

    + <%= I18n.t("support.case_hub_migration.edit.section.case_details") %> +

    + +
    +
    +
    + <%= I18n.t("support.case_hub_migration.label.procurement_value") %> +
    +
    + <%= 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" %> +
    +
    +
    -

    - <%= I18n.t("support.case_hub_migration.edit.label.confirm") %> -

    +

    + <%= I18n.t("support.case_hub_migration.edit.label.confirm") %> +

    - <%= form.button I18n.t("support.case_hub_migration.edit.submit"), class: "govuk-button", value: "create" %> - <% end %> + <%= button_to I18n.t("support.case_hub_migration.edit.submit"), submit_support_case_request_path, class: "govuk-button", data: { disable_with: "Submitting..." } %>
    diff --git a/app/views/support/cases/index.html.erb b/app/views/support/cases/index.html.erb index 14bf229b1..5e7487039 100644 --- a/app/views/support/cases/index.html.erb +++ b/app/views/support/cases/index.html.erb @@ -1,4 +1,4 @@ -<%= link_to I18n.t("support.case.label.create"), new_support_case_request_path, class: "govuk-button", role: "button" %> +<%= button_to I18n.t("support.case.label.create"), support_case_requests_path, class: "govuk-button" %>
      diff --git a/app/views/support/cases/requests/participating_schools/show.html.erb b/app/views/support/cases/request_details/participating_schools/show.html.erb similarity index 100% rename from app/views/support/cases/requests/participating_schools/show.html.erb rename to app/views/support/cases/request_details/participating_schools/show.html.erb diff --git a/app/views/support/cases/requests/show.html.erb b/app/views/support/cases/request_details/show.html.erb similarity index 97% rename from app/views/support/cases/requests/show.html.erb rename to app/views/support/cases/request_details/show.html.erb index 4ded3cd8f..eb626803f 100644 --- a/app/views/support/cases/requests/show.html.erb +++ b/app/views/support/cases/request_details/show.html.erb @@ -117,7 +117,7 @@
    <% end %> - <% if @request.flow.energy_or_services? %> + <% if @request.flow.present? && @request.flow.energy_or_services? %>
    <%= I18n.t("support.case.label.contract_start_date") %> @@ -137,7 +137,7 @@ <%= @request.school_urns.count %>
    - <%= link_to I18n.t("support.generic.view"), support_case_request_participating_schools_path, class: "govuk-link" %> + <%= link_to I18n.t("support.generic.view"), support_case_request_details_participating_schools_path, class: "govuk-link" %>
    <% end %> diff --git a/app/views/support/cases/show/_request_details.html.erb b/app/views/support/cases/show/_request_details.html.erb index 731f3aac6..b7725d250 100644 --- a/app/views/support/cases/show/_request_details.html.erb +++ b/app/views/support/cases/show/_request_details.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag "request-details-frame", src: support_case_request_path(@current_case) do %> +<%= turbo_frame_tag "request-details-frame", src: support_case_request_details_path(@current_case) do %>

    Loading...

    diff --git a/config/locales/en.yml b/config/locales/en.yml index bdc313a0c..da0285bc1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1239,6 +1239,8 @@ en: link_text: What is a framework? 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? edit: header: Check your answers before creating a new case label: @@ -1291,12 +1293,15 @@ en: referer: Referrer request_text: Summary school_name: Organisation name + school_number: "%{selected} of %{total} schools" school_postcode: Organisation postcode school_ukprn: Organisation UKPRN school_urn: Organisation URN + school_uid: Organisation UID source: Source sub_category: Procurement sub-category type: Type + participating_schools: Participating schools procurement_value: Procurement value support_level: Support level old: Old diff --git a/config/routes.rb b/config/routes.rb index ddd57ec0e..f80b91bdb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -212,19 +212,10 @@ resources :establishment_groups, only: %i[index] resources :frameworks, only: %i[index] resources :towers, only: [:show] - resources :case_requests, only: %i[new create edit update show] do - scope module: "case_requests" do - member do - post "/submit", to: "case_requests#submit" - resource :school_picker, only: %i[edit update], as: :case_request_school_picker - end - end - end resources :cases, only: %i[index show edit update new create] do resources :interactions, only: %i[new create show] scope module: :cases do collection do - resource :preview, only: %i[new create], as: :create_case_preview resources :searches, only: %i[new index], as: :case_search, path: "find-a-case" end resources :attachments, only: %i[index edit update destroy] @@ -270,14 +261,24 @@ resource :participating_schools, only: %i[show edit update] end end - resource :request, only: %i[show] do - scope module: :requests do + resource :request_details, only: %i[show] do + scope module: :request_details do resource :participating_schools, only: %i[show] end end end end + resources :case_requests, only: %i[create edit update show] do + post "/submit", to: "case_requests#submit", on: :member + + scope module: "case_requests" do + member do + resource :school_picker, only: %i[edit update], as: :case_request_school_picker + end + end + end + resources :notifications, only: :index do scope module: :notifications do resource :read, only: %i[create destroy] @@ -317,12 +318,9 @@ # E&O Portal namespace :engagement do root to: "cases#index" - resources :case_requests, only: %i[new create edit update show] resources :cases, only: %i[index show edit update new create] do scope module: :cases do collection do - resource :preview, only: %i[new create], as: :create_case_preview - post "uploads/(:upload_reference)/add", to: "uploads#upload", as: "add_uploads" delete "uploads/(:upload_reference)/remove", to: "uploads#remove", as: "remove_uploads" get "uploads/(:upload_reference)/list", to: "uploads#list", as: "list_uploads" @@ -330,6 +328,16 @@ end end + resources :case_requests, only: %i[create edit update show] do + post "/submit", to: "case_requests#submit", on: :member + + scope module: "case_requests" do + member do + resource :school_picker, only: %i[edit update], as: :case_request_school_picker + end + end + end + namespace :management do get "/", to: "base#index" resources :agents, only: %i[index edit update new create] diff --git a/db/migrate/20231012094226_add_case_request_to_engagement_case_uploads.rb b/db/migrate/20231012094226_add_case_request_to_engagement_case_uploads.rb new file mode 100644 index 000000000..dbec3d8e8 --- /dev/null +++ b/db/migrate/20231012094226_add_case_request_to_engagement_case_uploads.rb @@ -0,0 +1,5 @@ +class AddCaseRequestToEngagementCaseUploads < ActiveRecord::Migration[7.0] + def change + add_reference :engagement_case_uploads, :case_request, foreign_key: { to_table: :case_requests }, type: :uuid + end +end diff --git a/db/schema.rb b/db/schema.rb index b4754c7e8..ac580b48c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_10_122627) do +ActiveRecord::Schema[7.0].define(version: 2023_10_12_094226) do create_sequence "evaluation_refs" create_sequence "framework_refs" @@ -184,6 +184,8 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.uuid "support_case_id" + t.uuid "case_request_id" + t.index ["case_request_id"], name: "index_engagement_case_uploads_on_case_request_id" end create_table "exit_survey_responses", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -938,12 +940,13 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "all_cases_survey_responses", "support_cases", column: "case_id" - add_foreign_key "documents", "framework_requests" - add_foreign_key "documents", "support_cases" add_foreign_key "case_requests", "support_agents", column: "created_by_id" add_foreign_key "case_requests", "support_cases" add_foreign_key "case_requests", "support_categories", column: "category_id" add_foreign_key "case_requests", "support_queries", column: "query_id" + add_foreign_key "documents", "framework_requests" + add_foreign_key "documents", "support_cases" + add_foreign_key "engagement_case_uploads", "case_requests" add_foreign_key "exit_survey_responses", "support_cases", column: "case_id" add_foreign_key "framework_requests", "request_for_help_categories", column: "category_id" add_foreign_key "framework_requests", "support_cases" diff --git a/spec/features/engagement/create_case_spec.rb b/spec/features/engagement/create_case_spec.rb index 3b35ade53..3bf55ca2e 100644 --- a/spec/features/engagement/create_case_spec.rb +++ b/spec/features/engagement/create_case_spec.rb @@ -8,7 +8,8 @@ create(:support_category, :with_sub_category) create(:support_organisation, name: "Hillside School", urn: "000001") - visit "/engagement/cases/new" + visit "/engagement/cases" + click_button "Create a new case" end describe "Back link" do @@ -27,7 +28,6 @@ click_on "Save and continue" - expect(page).to have_current_path "/engagement/cases/preview" expect(find("h1.govuk-heading-l")).to have_text "Check your answers before creating a new case" end @@ -35,10 +35,10 @@ complete_valid_form within "#changeSchool" do - click_button "Change" + click_link "Change" end - fill_in "create_case_form[first_name]", with: "new_first_name" + fill_in "case_request[first_name]", with: "new_first_name" click_on "Save and continue" within "#fullName" do @@ -95,16 +95,16 @@ def table_cell(row, column) = ".single-row:nth-child(#{row}) .govuk-table__cell: end def valid_form_data_without_organisation - fill_in "create_case_form[first_name]", with: "first_name" - fill_in "create_case_form[last_name]", with: "last_name" - fill_in "create_case_form[email]", with: "test@example.com" - fill_in "create_case_form[phone_number]", with: "0778974653" + fill_in "case_request[first_name]", with: "first_name" + fill_in "case_request[last_name]", with: "last_name" + fill_in "case_request[email]", with: "test@example.com" + fill_in "case_request[phone_number]", with: "0778974653" choose "Non-DfE newsletter" # case origin choose "Procurement" # request type select "Other (General)", from: "select_request_details_category_id" find("#request_details_other_category_text").set("Other Category Details") - fill_in "create_case_form[request_text]", with: "This is a request" - fill_in "create_case_form[procurement_amount]", with: "45.22" + fill_in "case_request[request_text]", with: "This is a request" + fill_in "case_request[procurement_amount]", with: "45.22" end def valid_form_data diff --git a/spec/features/support/create_case_spec.rb b/spec/features/support/create_case_spec.rb index ce00f1825..eb8eeaae8 100644 --- a/spec/features/support/create_case_spec.rb +++ b/spec/features/support/create_case_spec.rb @@ -8,7 +8,8 @@ create(:support_category, :with_sub_category) create(:support_organisation, name: "Hillside School", urn: "000001") - visit "/support/cases/new" + visit "/support/cases" + click_button "Create a new case" end describe "Back link" do @@ -27,7 +28,6 @@ click_on "Save and continue" - expect(page).to have_current_path "/support/cases/preview" expect(find("h1.govuk-heading-l")).to have_text "Check your answers before creating a new case" end @@ -35,10 +35,10 @@ complete_valid_form within "#changeSchool" do - click_button "Change" + click_link "Change" end - fill_in "create_case_form[first_name]", with: "new_first_name" + fill_in "case_request[first_name]", with: "new_first_name" click_on "Save and continue" within "#fullName" do @@ -80,17 +80,17 @@ end def valid_form_data_without_organisation - fill_in "create_case_form[first_name]", with: "first_name" - fill_in "create_case_form[last_name]", with: "last_name" - fill_in "create_case_form[email]", with: "test@example.com" - fill_in "create_case_form[phone_number]", with: "0778974653" + fill_in "case_request[first_name]", with: "first_name" + fill_in "case_request[last_name]", with: "last_name" + fill_in "case_request[email]", with: "test@example.com" + fill_in "case_request[phone_number]", with: "0778974653" choose "Non-DfE newsletter" # case origin choose "Procurement" # request type select "Other (General)", from: "select_request_details_category_id" find("#request_details_other_category_text").set("Other Category Details") - select "Schools Commercial Team (SCT)", from: "create_case_form[source]" - fill_in "create_case_form[request_text]", with: "This is a request" - fill_in "create_case_form[procurement_amount]", with: "45.22" + select "Schools Commercial Team (SCT)", from: "case_request[source]" + fill_in "case_request[request_text]", with: "This is a request" + fill_in "case_request[procurement_amount]", with: "45.22" end def valid_form_data