Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP-4380: Add copy case feature #5895

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ruby "3.2.2"

gem "aasm", "~> 5.5.0"
gem "active_model_serializers", "~> 0.10.14"
gem "deep_cloneable", "~> 3.2.0"
gem "discard", "~> 1.3"
gem "geckoboard-ruby"
gem "google-apis-sheets_v4"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ GEM
date (3.3.3)
debug_inspector (1.1.0)
declarative (0.0.20)
deep_cloneable (3.2.0)
activerecord (>= 3.1.0, < 8)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.9.3)
Expand Down Expand Up @@ -735,6 +737,7 @@ DEPENDENCIES
cucumber
cucumber-rails (>= 2.4.0)
database_cleaner
deep_cloneable (~> 3.2.0)
devise
devise_saml_authenticatable (>= 1.7.0)
dibber
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/providers/copy_case_confirmations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Providers
class CopyCaseConfirmationsController < ProviderBaseController
def show
@form = CopyCase::ConfirmationForm.new(model: legal_aid_application)
@copiable_case = LegalAidApplication.find(session[:copy_case_id])
end

def update
@form = CopyCase::ConfirmationForm.new(form_params)
@copiable_case = LegalAidApplication.find(session[:copy_case_id])

render :show unless save_continue_or_draft(@form)
end

private

def form_params
merge_with_model(legal_aid_application) do
params.require(:legal_aid_application).permit(:copy_case_id, :copy_case_confirmation)
end
end
end
end
23 changes: 23 additions & 0 deletions app/controllers/providers/copy_case_invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Providers
class CopyCaseInvitationsController < ProviderBaseController
def show
@form = CopyCase::InvitationForm.new(model: legal_aid_application)
end

def update
@form = CopyCase::InvitationForm.new(form_params)

render :show unless save_continue_or_draft(@form)
end

private

def form_params
merge_with_model(legal_aid_application) do
next {} unless params[:legal_aid_application]

params.require(:legal_aid_application).permit(:copy_case)
end
end
end
end
27 changes: 27 additions & 0 deletions app/controllers/providers/copy_case_searches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Providers
class CopyCaseSearchesController < ProviderBaseController
def show
@form = CopyCase::SearchForm.new(model: legal_aid_application)
end

def update
@form = CopyCase::SearchForm.new(form_params)

render :show unless save_continue_or_draft(@form)
end

private

def save_continue_or_draft(form, **)
draft_selected? ? form.save_as_draft : form.save!
return false if form.invalid?

session[:copy_case_id] = form.copiable_case.id
continue_or_draft(**)
end

def form_params
params.require(:legal_aid_application).permit(:search_ref)
end
end
end
30 changes: 30 additions & 0 deletions app/forms/copy_case/confirmation_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module CopyCase
class ConfirmationForm < BaseForm
form_for LegalAidApplication

attr_accessor :copy_case_id, :copy_case_confirmation

validates :copy_case_id, presence: true, unless: proc { draft? }
validates :copy_case_confirmation, presence: true, unless: proc { draft? || copy_case_confirmation.present? }

def save
return false unless valid?

cloner = CopyCase::ClonerService.new(legal_aid_application, legal_aid_application_to_copy)
cloner.call
end
alias_method :save!, :save

def legal_aid_application_to_copy
@legal_aid_application_to_copy ||= LegalAidApplication.find(copy_case_id)
end

def legal_aid_application
@legal_aid_application ||= model
end

def exclude_from_model
%i[copy_case_id copy_case_confirmation]
end
end
end
9 changes: 9 additions & 0 deletions app/forms/copy_case/invitation_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module CopyCase
class InvitationForm < BaseForm
form_for LegalAidApplication

attr_accessor :copy_case

validates :copy_case, presence: true, unless: proc { draft? || copy_case.present? }
end
end
35 changes: 35 additions & 0 deletions app/forms/copy_case/search_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module CopyCase
class SearchForm < BaseForm
form_for LegalAidApplication

APPLICATION_REF_REGEXP = /\AL-[0-9ABCDEFHIJKLMNPRTUVWXY]{3}-[0-9ABCDEFHIJKLMNPRTUVWXY]{3}\z/

attr_accessor :search_ref, :copiable_case

# TODO: error message locales
validates :search_ref,
presence: true,
format: { with: APPLICATION_REF_REGEXP },
unless: :draft?

validate :case_exists, unless: :draft?

def case_exists
errors.add(:search_ref, "does not exist") unless case_found?
end

def save
return false unless valid?

true
end

def case_found?
@copiable_case = LegalAidApplication.find_by(application_ref: search_ref)
end

def exclude_from_model
[:search_ref]
end
end
end
32 changes: 32 additions & 0 deletions app/services/copy_case/cloner_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module CopyCase
class ClonerService
attr_accessor :copy, :original

def self.call(copy, original)
new(copy, original).call
end

def initialize(copy, original)
@copy = copy
@original = original
end

def call
clone_proceedings
end

private

def clone_proceedings
new_proceedings = original.proceedings.each_with_object([]) do |proceeding, memo|
memo << proceeding.deep_clone(
except: %i[legal_aid_application_id proceeding_case_id],
include: [:scope_limitations],
)
end

copy.proceedings = new_proceedings
copy.save!
end
end
end
39 changes: 37 additions & 2 deletions app/services/flow/flows/provider_start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,47 @@ class ProviderStart < FlowSteps
},
address_selections: {
path: ->(application) { urls.providers_legal_aid_application_address_selection_path(application) },
forward: ->(application) { application.proceedings.any? ? :has_other_proceedings : :proceedings_types },
forward: lambda do |application|
if Setting.linked_applications?
:copy_case_invitations
else
application.proceedings.any? ? :has_other_proceedings : :proceedings_types
end
end,
check_answers: :check_provider_answers,
},
addresses: {
path: ->(application) { urls.providers_legal_aid_application_address_path(application) },
forward: ->(application) { application.proceedings.any? ? :has_other_proceedings : :proceedings_types },
forward: lambda do |application|
if Setting.linked_applications?
:copy_case_invitations
else
application.proceedings.any? ? :has_other_proceedings : :proceedings_types
end
end,
check_answers: :check_provider_answers,
},
copy_case_invitations: {
path: ->(application) { urls.providers_legal_aid_application_copy_case_invitation_path(application) },
forward: lambda do |application|
if application.copy_case?
:copy_case_searches
else
application.proceedings.any? ? :has_other_proceedings : :proceedings_types
end
end,
check_answers: :check_provider_answers,
},
copy_case_searches: {
path: ->(application) { urls.providers_legal_aid_application_copy_case_search_path(application) },
forward: :copy_case_confirmations,
check_answers: :check_provider_answers,
},
copy_case_confirmations: {
path: ->(application) { urls.providers_legal_aid_application_copy_case_confirmation_path(application) },
forward: lambda do |application|
application.proceedings.any? ? :has_other_proceedings : :proceedings_types
end,
check_answers: :check_provider_answers,
},
about_financial_means: {
Expand Down
44 changes: 44 additions & 0 deletions app/views/providers/copy_case_confirmations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<%= form_with(model: @form,
url: providers_legal_aid_application_copy_case_confirmation_path,
method: :patch,
local: true) do |form| %>
<%= page_template page_title: t(".heading"), template: :basic, form: do %>

<%= govuk_table do |table|
table.with_caption(html_attributes: { class: "govuk-visually-hidden" }, text: t(".table_caption"))

table.with_head do |head|
head.with_row do |row|
row.with_cell(text: "LAA Ref.")
row.with_cell(text: "Client")
row.with_cell(text: "Category")
row.with_cell(text: "Firm")
end
end

table.with_body do |body|
body.with_row do |row|
row.with_cell(text: @copiable_case.application_ref)
row.with_cell(text: @copiable_case.applicant.full_name)
row.with_cell(text: @copiable_case.proceedings.map(&:category_of_law).join(","))
row.with_cell(text: @copiable_case.provider.firm.name)
end
end
end %>

<%= form.hidden_field :copy_case_id, value: @copiable_case.id %>

<%= form.govuk_collection_radio_buttons(
:copy_case_confirmation,
yes_no_options,
:value,
:label,
legend: { size: "xl", tag: "h1", text: t(".heading") },
) %>

<%= next_action_buttons(
show_draft: true,
form:,
) %>
<% end %>
<% end %>
20 changes: 20 additions & 0 deletions app/views/providers/copy_case_invitations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%= form_with(model: @form,
url: providers_legal_aid_application_copy_case_invitation_path,
method: :patch,
local: true) do |form| %>
<%= page_template page_title: t(".heading"), template: :basic, form: do %>

<%= form.govuk_collection_radio_buttons(
:copy_case,
yes_no_options,
:value,
:label,
legend: { size: "xl", tag: "h1", text: t(".heading") },
) %>

<%= next_action_buttons(
show_draft: true,
form:,
) %>
<% end %>
<% end %>
17 changes: 17 additions & 0 deletions app/views/providers/copy_case_searches/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_with(model: @form,
url: providers_legal_aid_application_copy_case_search_path,
method: :patch,
local: true) do |form| %>
<%= page_template page_title: t(".heading"), template: :basic, form: do %>
<%= form.govuk_text_field :search_ref,
label: { text: t(".search_ref.label"), size: "xl", tag: "h1" },
hint: { text: t(".search_ref.hint") },
width: "three-quarters",
value: params["search_ref"] || "" %>

<%= next_action_buttons(
show_draft: true,
form:,
) %>
<% end %>
<% end %>
2 changes: 2 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ en:
blank: Enter details of the incident
legal_aid_application:
attributes:
copy_case:
blank: Select yes if you want to copy an application
confirm_delegated_functions_date:
blank: Confirm the date you used delegated functions
has_dependants:
Expand Down
15 changes: 15 additions & 0 deletions config/locales/en/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ en:
be prosecuted
need to pay a financial penalty
have their legal aid stopped and have to pay back the costs

copy_case_confirmations:
show:
heading: Copy this application to your application?
table_caption: Application to copy to your application
copy_case_invitations:
show:
heading: Copy an application to your application?
copy_case_searches:
show:
heading: Find the application to copy
search_ref:
label: Find the application to copy
hint: Enter the LAA reference of the case you are searching for

check_passported_answers:
show:
h1-heading: Check your answers
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
resources :remove_state_benefits, only: %i[show update]
end
get :search, on: :collection
resource :copy_case_invitation, only: %i[show update]
resource :copy_case_search, only: %i[show update]
resource :copy_case_confirmation, only: %i[show update]
resource :delete, controller: :delete, only: %i[show destroy]
resources :proceedings_types, only: %i[index create]
resource :has_other_proceedings, only: %i[show update destroy]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCopyCaseToLegalAidApplication < ActiveRecord::Migration[7.0]
def change
add_column :legal_aid_applications, :copy_case, :boolean
end
end
Loading
Loading