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-5828: Editing applications feasibility spike #7711

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ LEGAL_FRAMEWORK_API_HOST=<app url>

CFE_CIVIL_HOST=<app url>
POLICY_DISREGARDS_START_DATE=2020-12-1

EDITABLE_APPLICATIONS=false
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ $govuk-new-organisation-colours: true;
@import "dropzone/src/basic";
@import "providers/summary_list_action_width";
@import "primary_navigation";
@import "task_list";
28 changes: 28 additions & 0 deletions app/assets/stylesheets/task_list.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.app-task-list__task-name {
display: block;

@include govuk-media-query($from: 450px) {
float: left;
}
}

.app-task-list__tag {
margin-top: govuk-spacing(2);
margin-bottom: govuk-spacing(1);

@include govuk-media-query($from: 450px) {
margin-top: 0;
margin-bottom: 0;
float: right;
}
}

.app-task-list__aside {
border-top: 3px solid $govuk-brand-colour;
@include govuk-responsive-margin(5, "left", $adjustment: 0);
@include govuk-responsive-padding(5, "top", $adjustment: 0);
}

.govuk-task-list__items {
padding-left: 0;
}
2 changes: 2 additions & 0 deletions app/controllers/concerns/providers/draftable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def application_has_task_list?
end

def draft_target_endpoint
return providers_legal_aid_application_task_list_path(legal_aid_application) if ENV.fetch("EDITABLE_APPLICATIONS", "false") == "true"

ENDPOINT
end

Expand Down
53 changes: 53 additions & 0 deletions app/controllers/providers/task_list/applicants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is different from the Providers::ApplicantsController in on
# one major aspect. It does not create a legal_aid_application. This
# is because the legal_aid_application should have been created by
# the TaskListsController, from which this controller/page is reached.
#
module Providers
module TaskList
class ApplicantsController < ProviderBaseController
def show
@form = Applicants::BasicDetailsForm.new(model: applicant)
end

def create
@form = Applicants::BasicDetailsForm.new(form_params)

if save_continue_or_draft(@form)
legal_aid_application.update!(
applicant:,
provider_step: edit_applicant_key_point.step,
)
replace_last_page_in_history(edit_applicant_path)
else
render :show
end
end

private

def legal_aid_application
@legal_aid_application ||= LegalAidApplication.find_by(id: params[:legal_aid_application_id])
end

def applicant
@applicant ||= legal_aid_application.applicant || Applicant.new
end

def edit_applicant_path
edit_applicant_key_point.path(legal_aid_application)
end

def edit_applicant_key_point
@edit_applicant_key_point ||= Flow::KeyPoint.new(:providers, :edit_applicant)
end

def form_params
merged_params = merge_with_model(applicant) do
params.expect(applicant: %i[first_name last_name date_of_birth changed_last_name last_name_at_birth])
end
convert_date_params(merged_params)
end
end
end
end
33 changes: 33 additions & 0 deletions app/controllers/providers/task_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Providers
class TaskListsController < ApplicationController
before_action :authenticate_provider!
before_action :update_locale
include Authorizable
include ApplicationDependable

def show
legal_aid_application

@task_list = ::TaskList::StartPageCollection.new(
view_context, application: legal_aid_application
)

legal_aid_application.check_task_list!
end

def create
legal_aid_application

redirect_to providers_legal_aid_application_task_list_path(legal_aid_application.id)
end

def legal_aid_application
@legal_aid_application ||=
LegalAidApplication.find_by(id: task_list_params[:legal_aid_application_id]) || LegalAidApplication.create!(provider: current_provider, office: current_provider.selected_office)
end

def task_list_params
params.permit(%i[legal_aid_application_id locale])
end
end
end
2 changes: 1 addition & 1 deletion app/forms/applicants/basic_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BasicDetailsForm < BaseForm
validates :first_name, presence: true, unless: proc { draft? && last_name.present? }
validates :last_name, presence: true, unless: proc { draft? && first_name.present? }
validates :date_of_birth, presence: true, unless: :draft_and_not_partially_complete_date_of_birth?
validates :changed_last_name, inclusion: %w[true false], unless: :draft?
validates :changed_last_name, inclusion: [true, false, "true", "false"], unless: :draft?
validates :last_name_at_birth, presence: true, unless: proc { draft? || changed_last_name.to_s != "true" }

validates(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HasNationalInsuranceNumberForm < BaseForm

before_validation :normalise_national_insurance_number

validates :has_national_insurance_number, inclusion: %w[true false], unless: :draft?
validates :has_national_insurance_number, inclusion: ["true", "false", true, false], unless: :draft?
validates :national_insurance_number, presence: true, if: :has_national_insurance_number?, unless: :draft?
validate :validate_national_insurance_number
end
Expand Down
5 changes: 3 additions & 2 deletions app/forms/applicants/previous_reference_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ class PreviousReferenceForm < BaseForm

before_validation :normalise_previous_reference

validates :applied_previously, inclusion: %w[true false], unless: :draft?
validates :applied_previously, inclusion: [true, false, "true", "false"], unless: :draft?
validates :previous_reference, presence: true, if: :applied_previously?, unless: :draft?
validate :validate_previous_reference, unless: :draft?

private

# For task lists to be able to validate using form objects booleans must take both strings and boolean values into account
def applied_previously?
applied_previously.eql?("true")
applied_previously.in?(["true", true])
end

def normalise_previous_reference
Expand Down
2 changes: 1 addition & 1 deletion app/forms/concerns/national_insurance_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module NationalInsuranceHandling
private

def has_national_insurance_number?
has_national_insurance_number.eql?("true")
has_national_insurance_number.in?(["true", true])
end

def normalise_national_insurance_number
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/flow_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def next_action_buttons_with_form(
show_draft: false,
inverse_continue: false,
continue_button_text: t("generic.save_and_continue"),
draft_button_text: t("generic.save_and_come_back_later"),
draft_button_text: ENV.fetch("EDITABLE_APPLICATIONS", "false") == "true" ? t("generic.save_and_go_to_task_list") : t("generic.save_and_come_back_later"),
container_class: nil
)
form_with(url:, method:, local: true) do |form|
Expand All @@ -29,7 +29,7 @@ def next_action_buttons(
show_draft: false,
inverse_continue: false,
continue_button_text: t("generic.save_and_continue"),
draft_button_text: t("generic.save_and_come_back_later"),
draft_button_text: ENV.fetch("EDITABLE_APPLICATIONS", "false") == "true" ? t("generic.save_and_go_to_task_list") : t("generic.save_and_come_back_later"),
container_class: nil
)
render(
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/providers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ def link_to_application(text, legal_aid_application)
end

def url_for_application(legal_aid_application)
return providers_legal_aid_application_task_list_path(legal_aid_application) if ENV.fetch("EDITABLE_APPLICATIONS", "false") == "true"

name = if legal_aid_application.expired?
:providers_blocked
else
Expand Down
9 changes: 9 additions & 0 deletions app/models/concerns/base_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def log_status_change

include AASM

# aasm(:task_list, column: "aasm_task_list_state") do
# state :initiated_primary_task_list, initial: true
# state :checking_primary_task_list

# event :checking_primary_task_list do
# transitions from: :initiated_primary_task_list, to: :checking_primary_task_list
# end
# end

aasm do
state :initiated, initial: true
state :entering_applicant_details
Expand Down
78 changes: 78 additions & 0 deletions app/models/concerns/editable_application_state_machine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
class EditableApplicationStateMachine < BaseStateMachine
def case_add_requestor
raise "TODO: implement for editable applications"
end

aasm do
state :checking_task_list, initial: true
event :check_task_list do
transitions to: :checking_task_list
end

state :checking_applicant_details
event :check_applicant_details do
transitions to: :checking_applicant_details
end

state :checking_passported_answers
event :check_passported_answers do
transitions to: :checking_passported_answers
end

state :checking_citizen_answers
event :check_citizen_answers? do
transitions to: :checking_citizen_answers
end

state :checking_non_passported_means
event :check_non_passported_means do
transitions to: :checking_non_passported_means
end

state :checking_means_income
event :check_means_income do
transitions to: :checking_means_income
end
end

# The following methods override state queries and events that are not applicable for an
# editable application journey but which, nonetheless, must be responded to when calls
# are made in controllers :(

#######################################################################
# Added to ignore these events for editable applications list #
#######################################################################
def entering_applicant_details?
false
end

def enter_applicant_details!
false
end

def provider_assessing_means?
false
end

def provider_assess_means!
false
end

def applicant_entering_means?
false
end

def applicant_enter_means!
false
end

# will probably need handling
def awaiting_applicant?
false
end

# will probably need handling
def await_applicant!
false
end
end
13 changes: 12 additions & 1 deletion app/models/legal_aid_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ class LegalAidApplication < ApplicationRecord
:merits_parental_responsibilities_all_rejected?,
to: :state_machine_proxy

# editable journey task list state machine related delegations
delegate :check_task_list!,
:checking_task_list?,
to: :state_machine_proxy

scope :latest, -> { order(created_at: :desc) }
scope :search, lambda { |term|
attributes = [
Expand Down Expand Up @@ -557,8 +562,14 @@ def state
def state_machine_proxy
if state_machine.nil?
save!
create_state_machine(type: "PassportedStateMachine")

if ENV.fetch("EDITABLE_APPLICATIONS", "false") == "true"
create_state_machine(type: "EditableApplicationStateMachine")
else
create_state_machine(type: "PassportedStateMachine")
end
end

state_machine
end
alias_method :find_or_create_state_machine, :state_machine_proxy
Expand Down
12 changes: 12 additions & 0 deletions app/presenters/task/applicants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Task
class Applicants < Base
def path
# TODO: this needs to go to the last step reached in the applicants task flow or the beginning of that task flow
# if status.in_progress?
# last_task_page_path(self)
# else
providers_legal_aid_application_applicants_path(application)
# end
end
end
end
Loading