-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5932 from ministryofjustice/ap-4575/copy-case-pag…
…e-flows AP-4575: Add copy case page flows
- Loading branch information
Showing
31 changed files
with
1,571 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/controllers/providers/copy_case/confirmations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
app/controllers/providers/copy_case/invitations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
app/controllers/providers/copy_case/searches_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.