Skip to content

Commit

Permalink
Merge pull request #5932 from ministryofjustice/ap-4575/copy-case-pag…
Browse files Browse the repository at this point in the history
…e-flows

AP-4575: Add copy case page flows
  • Loading branch information
jsugarman authored Nov 13, 2023
2 parents d0cd3fc + 4860c31 commit 7691800
Show file tree
Hide file tree
Showing 31 changed files with 1,571 additions and 12 deletions.
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 @@ -218,6 +218,8 @@ GEM
date (3.3.4)
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 @@ -759,6 +761,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
29 changes: 29 additions & 0 deletions app/controllers/providers/copy_case/confirmations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Providers
module CopyCase
class ConfirmationsController < ProviderBaseController
prefix_step_with :copy_case

def show
@form = ::CopyCase::ConfirmationForm.new(model: legal_aid_application)
@copiable_case = LegalAidApplication.find(legal_aid_application.copy_case_id)
end

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

render :show unless save_continue_or_draft(@form, copy_case_confirmed: @form.copy_case_confirmed?)
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_id, :copy_case_confirmation)
end
end
end
end
end
27 changes: 27 additions & 0 deletions app/controllers/providers/copy_case/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Providers
module CopyCase
class InvitationsController < ProviderBaseController
prefix_step_with :copy_case

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
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
module CopyCase
class SearchesController < ProviderBaseController
prefix_step_with :copy_case

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 form_params
merge_with_model(legal_aid_application) do
next {} unless params[:legal_aid_application]

params.require(:legal_aid_application).permit(:search_ref)
end
end
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: :draft?
validates :copy_case_confirmation, presence: true, unless: proc { draft? || copy_case_confirmation.present? }

def save
return if invalid? || draft? || !copy_case_confirmed?

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 copy_case_confirmed?
copy_case_confirmation == "true"
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

validates :search_ref,
presence: true,
format: { with: APPLICATION_REF_REGEXP },
unless: :draft?

validate :case_exists, unless: :draft?

def save
return false unless valid?

model.update!(copy_case_id: copiable_case.id) unless draft?

true
end
alias_method :save!, :save

def case_exists
errors.add(:search_ref, :not_found) unless case_found?
end

def case_found?
@copiable_case = LegalAidApplication
.where(provider: model.provider)
.find_by(application_ref: search_ref)
end
end
end
36 changes: 36 additions & 0 deletions app/services/copy_case/cloner_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module CopyCase
class ClonerService
attr_accessor :target, :source

def self.call(target, source)
new(target, source).call
end

def initialize(target, source)
@target = target
@source = source
end

def call
clone_proceedings

# TODO: clone opponents, clone other merits tasks(??)
# and copy values from other fields on legal_aid_application source object
# see ticket AP-4577
end

private

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

target.proceedings = new_proceedings
target.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, options|
options[:copy_case_confirmed] ? :has_national_insurance_numbers : :copy_case_invitations
end,
check_answers: :check_provider_answers,
},
about_financial_means: {
Expand Down
36 changes: 36 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,36 @@
<%= 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_fieldset_header page_title %>

<%= govuk_summary_list(actions: false) do |summary_list|
summary_list.with_row do |row|
row.with_key { t(".summary_list_item.laa_reference") }
row.with_value { @copiable_case.application_ref }
end

summary_list.with_row do |row|
row.with_key { t(".summary_list_item.client") }
row.with_value { @copiable_case.applicant.full_name }
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: "h2", text: t(".legend", application_ref: @copiable_case.application_ref) },
) %>

<%= next_action_buttons(
show_draft: true,
form:,
) %>
<% end %>
<% end %>
21 changes: 21 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,21 @@
<%= 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") },
hint: { text: t(".hint_html") },
) %>

<%= next_action_buttons(
show_draft: true,
form:,
) %>
<% end %>
<% end %>
18 changes: 18 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,18 @@
<%= 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(
form:,
show_draft: true,
continue_button_text: "Search",
) %>
<% end %>
<% end %>
8 changes: 8 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ en:
blank: Enter details of the incident
legal_aid_application:
attributes:
copy_case:
blank: Select yes if you want to copy an application
copy_case_confirmation:
blank: Select yes if you want to copy the application
search_ref:
blank: Enter an application reference to search for
invalid: Enter a valid application reference to search for
not_found: The application reference entered cannot be found
confirm_delegated_functions_date:
blank: Confirm the date you used delegated functions
has_dependants:
Expand Down
23 changes: 23 additions & 0 deletions config/locales/en/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,29 @@ 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: Search result
table_caption: Application to copy to your application
legend: Do you want to copy %{application_ref} to your application?
summary_list_item:
laa_reference: LAA Reference
client: Client
invitations:
show:
heading: Do you want to copy an application to your current application?
hint_html: |
<p>You can do this in family cases where the children involved are related, so you do not have to repeat infomrmation.</p>
<p>You cannot copy applications created in CCMS.</p>
searches:
show:
heading: What is the LAA reference of the application you want to copy?
search_ref:
label: What is the LAA reference of the application you want to copy?
hint: For example, 'A-BCD-E1F'.

check_passported_answers:
show:
h1-heading: Check your answers
Expand Down
Loading

0 comments on commit 7691800

Please sign in to comment.