Skip to content

Commit

Permalink
Merge pull request #2845 from DFE-Digital/remove-shim
Browse files Browse the repository at this point in the history
CAPT-1720/Remove shim
  • Loading branch information
rjlynch authored Jun 13, 2024
2 parents b635048 + bf1d187 commit 10b388b
Show file tree
Hide file tree
Showing 34 changed files with 120 additions and 400 deletions.
9 changes: 1 addition & 8 deletions app/controllers/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,7 @@ def claim_in_progress?
end

def claim_ineligible?
journey::EligibilityChecker.new(journey_session: shim).ineligible?
end

def shim
@shim ||= journey::ClaimJourneySessionShim.new(
current_claim: current_claim,
journey_session: journey_session
)
journey::EligibilityChecker.new(journey_session: journey_session).ineligible?
end

def page_sequence
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/concerns/journey_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ def find_journey_session
end

def create_journey_session!
journey::Session.create!(journey: params[:journey])
journey::Session.create!(
journey: params[:journey],
answers: {
academic_year: journey_configuration.current_academic_year
}
)
end

def journey_session_key
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ class SubmissionsController < BasePublicController
skip_before_action :send_unstarted_claimants_to_the_start, only: [:show]

def create
shim = journey::ClaimJourneySessionShim.new(
current_claim: current_claim,
journey_session: journey_session
)

@form = journey::ClaimSubmissionForm.new(journey_session: shim)
@form = journey::ClaimSubmissionForm.new(journey_session: journey_session)

if @form.save
current_claim.claims.each(&:destroy!)
Expand Down
7 changes: 1 addition & 6 deletions app/forms/claim_submission_base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ def set_eligibility_attributes(eligibility)
end

def set_attributes_for_claim_submission
# Temp conditional while we're working with the shim
claim.journey_session = if journey_session.is_a?(ClaimJourneySessionShim)
journey_session.journey_session
else
journey_session
end
claim.journey_session = journey_session
claim.policy_options_provided = generate_policy_options_provided
claim.reference = generate_reference
claim.submitted_at = Time.zone.now
Expand Down
28 changes: 1 addition & 27 deletions app/forms/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ def persisted?
true
end

# NOTE RL: temporary method while migrating away from current claim for when
# we need to check against either answers or the claim for some information
# Will be removed once the migration is complete and we delete the shim
def shim
@shim ||= Journeys::AdditionalPaymentsForTeaching::ClaimJourneySessionShim.new(
current_claim: claim,
journey_session: journey_session
)
end

private

def permitted_attributes
Expand Down Expand Up @@ -91,22 +81,6 @@ def attributes_with_current_value
end

def load_current_value(attribute)
if journey_session.answered?(attribute)
return journey_session.answers.public_send(attribute)
end

# TODO: re-implement when the underlying claim and eligibility data sources
# are moved to an alternative place e.g. a session hash

# Some, but not all attributes are present directly on the claim record.
return claim.public_send(attribute) if claim.has_attribute?(attribute)

# At the moment, some attributes are unique to a policy eligibility record,
# so we need to loop through all the claims in the wrapper and check each
# eligibility individually; if the search fails, it should return `nil`.
claim.claims.each do |c|
return c.eligibility.public_send(attribute) if c.eligibility.has_attribute?(attribute)
end
nil
journey_session.answers.public_send(attribute) if journey_session.answers.has_attribute?(attribute)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def policies_eligible_now_and_sorted
end

def award_amount(policy)
policy::PolicyEligibilityChecker.new(answers: shim.answers).calculate_award_amount
policy::PolicyEligibilityChecker.new(answers: answers).calculate_award_amount
end

def selected_policy?(policy)
Expand All @@ -47,7 +47,7 @@ def allowed_policy_names
end

def eligibility_checker
@eligibility_checker ||= EligibilityChecker.new(journey_session: shim)
@eligibility_checker ||= EligibilityChecker.new(journey_session: journey_session)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def chemistry_or_physics_available?

def subject_symbols
@subject_symbols ||=
JourneySubjectEligibilityChecker.selectable_subject_symbols(shim.answers)
JourneySubjectEligibilityChecker.selectable_subject_symbols(answers)
end

def save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def save
subject_to_formal_performance_action:,
subject_to_disciplinary_action:
)

journey_session.save
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ def sent_one_time_password_at?
rescue Date::Error
false
end

def load_current_value(attribute)
# TODO: re-implement when the underlying claim and eligibility data sources
# are moved to an alternative place e.g. a session hash

# Some, but not all attributes are present directly on the claim record.
return claim.public_send(attribute) if claim.has_attribute?(attribute)

# At the moment, some attributes are unique to a policy eligibility record,
# so we need to loop through all the claims in the wrapper and check each
# eligibility individually; if the search fails, it should return `nil`.
claim.claims.each do |c|
return c.eligibility.public_send(attribute) if c.eligibility.has_attribute?(attribute)
end
nil
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ def save
def i18n_form_namespace
"reminders.#{super}"
end

def load_current_value(attribute)
# TODO: re-implement when the underlying claim and eligibility data sources
# are moved to an alternative place e.g. a session hash

# Some, but not all attributes are present directly on the claim record.
return claim.public_send(attribute) if claim.has_attribute?(attribute)

# At the moment, some attributes are unique to a policy eligibility record,
# so we need to loop through all the claims in the wrapper and check each
# eligibility individually; if the search fails, it should return `nil`.
claim.claims.each do |c|
return c.eligibility.public_send(attribute) if c.eligibility.has_attribute?(attribute)
end
nil
end
end
end
end
Expand Down
90 changes: 0 additions & 90 deletions app/models/claim_journey_session_shim.rb

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,16 @@ def set_by_teacher_id?(field)
answers.teacher_id_user_info[field].present?
end

def shim
@shim ||= Journeys::AdditionalPaymentsForTeaching::ClaimJourneySessionShim.new(
current_claim: claim,
journey_session: journey_session
)
end

def overall_eligibility_status
@overall_eligibility_status ||= EligibilityChecker.new(journey_session: shim).status
@overall_eligibility_status ||= EligibilityChecker.new(journey_session: journey_session).status
end

def ecp_eligibility_checker
@ecp_eligibility_checker ||= Policies::EarlyCareerPayments::PolicyEligibilityChecker.new(answers: shim.answers)
@ecp_eligibility_checker ||= Policies::EarlyCareerPayments::PolicyEligibilityChecker.new(answers: answers)
end

def lup_eligibility_checker
@lup_eligibility_checker ||= Policies::LevellingUpPremiumPayments::PolicyEligibilityChecker.new(answers: shim.answers)
@lup_eligibility_checker ||= Policies::LevellingUpPremiumPayments::PolicyEligibilityChecker.new(answers: answers)
end
end
end
Expand Down
11 changes: 2 additions & 9 deletions app/models/journeys/page_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,11 @@ def journey
end

def claim_submittable?
journey::ClaimSubmissionForm.new(journey_session: shim).valid?
end

def shim
@shim ||= journey::ClaimJourneySessionShim.new(
current_claim: @claim,
journey_session: @journey_session
)
journey::ClaimSubmissionForm.new(journey_session: @journey_session).valid?
end

def journey_ineligible?
@journey_ineligible ||= journey::EligibilityChecker.new(journey_session: shim).ineligible?
@journey_ineligible ||= journey::EligibilityChecker.new(journey_session: @journey_session).ineligible?
end
end
end
26 changes: 0 additions & 26 deletions app/models/journeys/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,6 @@ def submitted?
claim.present?
end

# This method and the associated `before_save` callback are temporary
# methods while we're working with both a current claim and journey
# session.
# When setting default values in a form object we need to know if the
# answer was stored on the journey session or whether we should check the
# current claim. Values for answers may be `nil`, so we need to explicitly
# check that the question was answered.
# Once all forms has been migrated to use the journey session, this method,
# the before_save and after_initialize call backs and the
# SessionAnswer#answered attribute can be removed.
# This will be removed in
# https://dfedigital.atlassian.net.mcas.ms/browse/CAPT-1637
def answered?(attribute_name)
answers.answered.include?(attribute_name.to_s)
end

after_initialize do
answers.clear_changes_information
end

before_save do
unless answers.answered_changed? # Allow overwriting answered attributes
answers.answered += answers.changes.keys.map(&:to_s)
end
end

def logged_in_with_tid_and_has_recent_tps_school?
answers.trn_from_tid? && recent_tps_school.present?
end
Expand Down
Loading

0 comments on commit 10b388b

Please sign in to comment.