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-4575: Add copy case page flows #5932

Merged
merged 32 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
319a111
AP-4575: Add `copy_case` column to legal_aid_application
jsugarman Oct 20, 2023
09299ab
AP-4575: Add copy case invitation form
jsugarman Oct 20, 2023
960dd9d
AP-4575: Add copy case find and confirmation components
jsugarman Oct 20, 2023
a0c65f8
AP-4575: Add cloner service and copy proceedings
jsugarman Oct 23, 2023
9eed525
AP-4575: Include proceeding scope limitations
jsugarman Oct 24, 2023
e6ea71d
AP-4575: Add basic copy case feature tests and adjust content from de…
jsugarman Nov 1, 2023
4f4b158
AP-4575: Add copy_case_invitations request specs
jsugarman Nov 2, 2023
428cfa1
AP-4575: Extend addresses controller spec
jsugarman Nov 3, 2023
49c0f54
AP-4575: rename addresses controller spec
jsugarman Nov 3, 2023
b77d2b2
AP-4575: Extend address selections controller spec
jsugarman Nov 3, 2023
fbfea58
AP-4575: Add copy_case_searches request specs
jsugarman Nov 3, 2023
5e10d03
AP-4575: Add copy_case_confirmations request specs
jsugarman Nov 3, 2023
bd330dc
AP-4575: Add copy_case/invitation_form specs
jsugarman Nov 6, 2023
9e2d3e8
AP-4575: Add copy_case/search_form specs
jsugarman Nov 6, 2023
4eec414
AP-4575: add save! alias to ensure correct calls made
jsugarman Nov 6, 2023
b8cc256
AP-4575: correct copy_case_confirmations form_params
jsugarman Nov 6, 2023
cc16363
AP-4575: correct copy_case_searches form_params
jsugarman Nov 6, 2023
a126328
AP-4575: amend copy_case_searches_controller_spec
jsugarman Nov 6, 2023
000e666
AP-4575: enable save as draft for search
jsugarman Nov 6, 2023
c359b60
AP-4575: Add confirmation_form spec
jsugarman Nov 6, 2023
75acf73
AP-4575: remove unneeded exclude_from_model overrides
jsugarman Nov 6, 2023
e815459
AP-4575: Extend cloner service spec
jsugarman Nov 6, 2023
5eae1cc
AP-4575: Refactor copy_case/confirmation_form
jsugarman Nov 7, 2023
bc0c108
AP-4575: Extend copy_case/search_form spec
jsugarman Nov 7, 2023
d5520ec
AP-4575: Amend copy case confirmation table to summary list
jsugarman Nov 7, 2023
853615d
AP-4575: Amend migration to add copy_case_id column
jsugarman Nov 7, 2023
10f6598
AP-4575: Update copy_case searches controller and form to use copy_ca…
jsugarman Nov 7, 2023
3cfd966
AP-4575: Amend copy case confirmations controller and form to use cop…
jsugarman Nov 7, 2023
e57970a
AP-4575: remove unneeded have_error_message spec helper method
jsugarman Nov 8, 2023
eb29620
AP-4575: Namespace copy_case controllers
jsugarman Nov 8, 2023
0aebd49
AP-4575: Update content for copy case invitations page
jsugarman Nov 9, 2023
4860c31
AP-4575: Remove unneeded save_continue_or_draft override
jsugarman Nov 9, 2023
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 @@ -218,6 +218,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 @@ -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