-
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.
AP-5347 Mandatory disregards page (#7351)
* AP-5347 Add mandatory disregards page Add route, controller, view, step and form for new mandatory disregards page, behind the MTR2A feature flag. Add specs and feature test --------- Co-authored-by: RoseSAK <[email protected]>
- Loading branch information
Showing
18 changed files
with
514 additions
and
15 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
app/controllers/providers/means/capital_disregards/mandatory_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,28 @@ | ||
module Providers | ||
module Means | ||
module CapitalDisregards | ||
class MandatoryController < ProviderBaseController | ||
prefix_step_with :capital_disregards | ||
|
||
def show | ||
@form = Providers::Means::CapitalDisregards::MandatoryForm.new(model: legal_aid_application) | ||
end | ||
|
||
def update | ||
@form = Providers::Means::CapitalDisregards::MandatoryForm.new(form_params) | ||
render :show unless save_continue_or_draft(@form) | ||
end | ||
|
||
private | ||
|
||
def form_params | ||
merge_with_model(legal_aid_application) do | ||
params.require(:providers_means_capital_disregards_mandatory_form) | ||
.permit(:none_selected, mandatory_capital_disregards: []) | ||
.merge(legal_aid_application:) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
115 changes: 115 additions & 0 deletions
115
app/forms/providers/means/capital_disregards/mandatory_form.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,115 @@ | ||
module Providers | ||
module Means | ||
module CapitalDisregards | ||
class MandatoryForm | ||
include ActiveModel::Model | ||
|
||
DISREGARD_TYPES = %i[ | ||
backdated_benefits | ||
backdated_community_care | ||
budgeting_advances | ||
compensation_miscarriage_of_justice | ||
government_cost_of_living | ||
independent_living_fund | ||
infected_blood_support_scheme | ||
modern_slavery_victim_care | ||
payment_on_account_of_benefit | ||
historical_child_abuse | ||
social_fund | ||
vaccine_damage | ||
variant_creutzfeldt_jakob_disease | ||
welsh_independent_living_grant | ||
windrush_compensation_scheme | ||
].freeze | ||
|
||
attr_reader :mandatory_capital_disregards | ||
attr_accessor :legal_aid_application, :none_selected | ||
|
||
validate :validate_any_checkbox_checked, unless: :draft? | ||
validate :validate_none_selected_and_another_checkbox_not_both_checked, unless: :draft? | ||
|
||
def initialize(params = {}) | ||
self.legal_aid_application = params.delete(:model) | ||
self.mandatory_capital_disregards = params["mandatory_capital_disregards"] || existing_mandatory_disregards | ||
|
||
super | ||
end | ||
|
||
def mandatory_capital_disregards=(names) | ||
@mandatory_capital_disregards = [names].flatten.compact_blank | ||
end | ||
|
||
def save_as_draft | ||
@draft = true | ||
save! | ||
end | ||
|
||
def draft? | ||
@draft | ||
end | ||
|
||
def save | ||
return false unless valid? | ||
|
||
destroy_previous_disregards! | ||
create_new_disregards! | ||
end | ||
alias_method :save!, :save | ||
|
||
private | ||
|
||
# create new records if they don't already exist | ||
def create_new_disregards! | ||
return unless mandatory_capital_disregards | ||
|
||
mandatory_capital_disregards&.reject { |disregard| | ||
existing_mandatory_disregards.include?(disregard) | ||
}&.each { |disregard| legal_aid_application.capital_disregards.create!(name: disregard, mandatory: true) } | ||
end | ||
|
||
# destroy only the records which already exist but aren't selected | ||
def destroy_previous_disregards! | ||
legal_aid_application.mandatory_capital_disregards&.where&.not(name: mandatory_capital_disregards)&.destroy_all | ||
end | ||
|
||
def existing_mandatory_disregards | ||
legal_aid_application.mandatory_capital_disregards.pluck(:name) | ||
end | ||
|
||
def none_selected? | ||
none_selected == "true" | ||
end | ||
|
||
def any_checkbox_checked? | ||
none_selected? || mandatory_capital_disregards.any? | ||
end | ||
|
||
def none_and_another_checkbox_checked? | ||
none_selected? && mandatory_capital_disregards.any? | ||
end | ||
|
||
def validate_any_checkbox_checked | ||
errors.add :mandatory_capital_disregards, error_message_for_none_selected unless any_checkbox_checked? | ||
end | ||
|
||
def validate_none_selected_and_another_checkbox_not_both_checked | ||
errors.add :mandatory_capital_disregards, error_message_for_none_and_another_option_selected if none_and_another_checkbox_checked? | ||
end | ||
|
||
def error_message_for_none_selected | ||
I18n.t("activemodel.errors.models.mandatory_capital_disregards.attributes.base.none_selected") | ||
end | ||
|
||
def error_message_for_none_and_another_option_selected | ||
I18n.t("activemodel.errors.models.mandatory_capital_disregards.attributes.base.#{error_key('none_and_another_option_selected')}") | ||
end | ||
|
||
def error_key(key_name) | ||
return "#{key_name}_with_partner" if legal_aid_application&.applicant&.has_partner_with_no_contrary_interest? | ||
|
||
key_name | ||
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
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
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
11 changes: 11 additions & 0 deletions
11
app/services/flow/steps/provider_capital_disregards/mandatory_step.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,11 @@ | ||
module Flow | ||
module Steps | ||
module ProviderCapitalDisregards | ||
MandatoryStep = Step.new( | ||
path: ->(application) { Steps.urls.providers_legal_aid_application_means_capital_disregards_mandatory_path(application) }, | ||
forward: :capital_disregards_discretionary, | ||
check_answers: ->(application) { application.provider_checking_or_checked_citizens_means_answers? ? :check_capital_answers : :check_passported_answers }, | ||
) | ||
end | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
app/views/providers/means/capital_disregards/mandatory/show.html.erb
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,34 @@ | ||
<%= form_with(model: @form, | ||
url: providers_legal_aid_application_means_capital_disregards_mandatory_path(@legal_aid_application), | ||
method: :patch, | ||
local: true) do |form| %> | ||
<% individual = @legal_aid_application.applicant.has_partner_with_no_contrary_interest? ? "partner" : "client" %> | ||
<%= page_template page_title: t(".h1-heading"), template: :basic, form: do %> | ||
<h1 class="govuk-heading-xl"><%= page_title %></h1> | ||
<p class="govuk-body govuk-!-margin-bottom-6"><%= t(".paragraph.#{individual}") %></p> | ||
|
||
<%= form.govuk_check_boxes_fieldset :mandatory_capital_disregards, | ||
legend: { text: t(".h2-heading.#{individual}"), size: "l", tag: "h1" }, | ||
hint: { text: t(".hint-text_html") }, | ||
form_group: { class: @form.errors[:mandatory_capital_disregards].any? ? "govuk-form-group--error" : "" } do %> | ||
<div class="deselect-group" data-deselect-ctrl="#providers-means-capital-disregards-mandatory-form-none-selected-true-field"> | ||
<% Providers::Means::CapitalDisregards::MandatoryForm::DISREGARD_TYPES.each_with_index do |disregard_type, idx| %> | ||
<%= form.govuk_check_box :mandatory_capital_disregards, | ||
disregard_type.to_s, | ||
link_errors: idx.zero?, | ||
label: { text: t(".#{disregard_type}") }, | ||
hint: { text: t(".#{disregard_type}_hint", default: "") } %> | ||
<% end %> | ||
</div> | ||
|
||
<%= form.govuk_radio_divider %> | ||
<%= form.govuk_check_box :mandatory_capital_disregards, | ||
:none_of_these, | ||
exclusive: true, | ||
label: { text: t(".none_of_these") } %> | ||
<% end %> | ||
<%= 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
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
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
7 changes: 7 additions & 0 deletions
7
db/migrate/20241030094958_add_uniqueness_index_to_capital_disregards.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,7 @@ | ||
class AddUniquenessIndexToCapitalDisregards < ActiveRecord::Migration[7.2] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
add_index(:capital_disregards, [:legal_aid_application_id, :name], unique: true, algorithm: :concurrently) | ||
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.