Skip to content

Commit

Permalink
Merge pull request #1830 from DFE-Digital/work-history-verification
Browse files Browse the repository at this point in the history
Add work history verification journey
  • Loading branch information
thomasleese authored Jan 24, 2024
2 parents 29d26b2 + 59cf23f commit 77ed7b1
Show file tree
Hide file tree
Showing 54 changed files with 872 additions and 704 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def show
end

def edit
@professional_standing = session[:professional_standing]
@qualifications =
application_form.qualifications.where(id: session[:qualification_ids])
@work_histories =
application_form.work_histories.where(id: session[:work_history_ids])
end

def update
Expand Down Expand Up @@ -59,19 +64,25 @@ def update_verify_qualifications
if @form.valid?
session[:qualification_ids] = []

redirect_to [
(
if @form.verify_qualifications
:qualification_requests
else
:professional_standing
end
),
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
]
if @form.verify_qualifications
# rubocop:disable Layout/LineLength
redirect_to qualification_requests_assessor_interface_application_form_assessment_assessment_recommendation_verify_path(
application_form,
assessment,
back_to_summary: params[:back_to_summary],
)
# rubocop:enable Layout/LineLength
else
redirect_to back_to_summary_path(
[
:professional_standing,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
],
)
end
else
render :edit_verify_qualifications, status: :unprocessable_entity
end
Expand Down Expand Up @@ -105,13 +116,15 @@ def update_qualification_requests
)

if @form.save
redirect_to [
:email_consent_letters,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
]
redirect_to back_to_summary_path(
[
:email_consent_letters,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
],
)
else
render :edit_qualification_requests, status: :unprocessable_entity
end
Expand Down Expand Up @@ -156,13 +169,15 @@ def update_professional_standing
if @form.valid?
session[:professional_standing] = @form.verify_professional_standing

redirect_to [
:reference_requests,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
]
redirect_to back_to_summary_path(
[
:reference_requests,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
],
)
else
render :edit_professional_standing, status: :unprocessable_entity
end
Expand All @@ -171,12 +186,7 @@ def update_professional_standing
def edit_reference_requests
authorize %i[assessor_interface assessment_recommendation], :edit?

@form =
SelectWorkHistoriesForm.new(
application_form:,
session:,
work_history_ids: application_form.work_histories.pluck(:id),
)
@form = SelectWorkHistoriesForm.new(application_form:, session:)
end

def update_reference_requests
Expand All @@ -196,26 +206,20 @@ def update_reference_requests
)

if @form.save
redirect_to [
:preview_referee,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
]
redirect_to back_to_summary_path(
[
:edit,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
],
)
else
render :edit_reference_requests, status: :unprocessable_entity
end
end

def preview_referee
authorize %i[assessor_interface assessment_recommendation], :edit?
end

def preview_teacher
authorize %i[assessor_interface assessment_recommendation], :edit?
end

private

def assessment
Expand All @@ -242,5 +246,19 @@ def load_assessment_and_application_form
@assessment = assessment
@application_form = application_form
end

def back_to_summary_path(ordinary_path)
if ActiveModel::Type::Boolean.new.cast(params[:back_to_summary])
[
:edit,
:assessor_interface,
application_form,
assessment,
:assessment_recommendation_verify,
]
else
ordinary_path
end
end
end
end
130 changes: 72 additions & 58 deletions app/controllers/assessor_interface/reference_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,125 @@

module AssessorInterface
class ReferenceRequestsController < BaseController
before_action only: %i[index update_verify_references] do
authorize %i[assessor_interface reference_request]
end

before_action except: %i[index update_verify_references] do
authorize [:assessor_interface, reference_request]
end

before_action :set_list_variables, only: %i[index update_verify_references]
before_action :set_individual_variables,
except: %i[index update_verify_references]
before_action :set_individual_variables, except: :index

def index
@form =
VerifyReferencesForm.new(
assessment: @assessment,
references_verified: @assessment.references_verified,
)
authorize %i[assessor_interface reference_request]

@reference_requests = reference_requests
@application_form = reference_requests.first.application_form
@assessment = reference_requests.first.assessment

render layout: "full_from_desktop"
end

def update_verify_references
def edit_review
@form = RequestableReviewForm.new(requestable:)
end

def update_review
@form =
VerifyReferencesForm.new(
assessment: @assessment,
**verify_references_form_params,
RequestableReviewForm.new(
requestable:,
user: current_staff,
**review_form_params,
)

if @form.save
redirect_to [:assessor_interface, @application_form]
redirect_to [:review, :assessor_interface, application_form, assessment]
else
render :index,
layout: "full_from_desktop",
status: :unprocessable_entity
render :edit_review, status: :unprocessable_entity
end
end

def edit
@form = RequestableReviewForm.new(requestable:)
end

def update
def edit_verify
@form =
RequestableReviewForm.new(
RequestableVerifyPassedForm.new(
requestable:,
user: current_staff,
**requestable_review_form_params,
passed: requestable.verify_passed,
)
end

def update_verify
@form =
RequestableVerifyPassedForm.new(
verify_passed_form_params.merge(requestable:, user: current_staff),
)

if @form.save
redirect_to [
:assessor_interface,
requestable.application_form,
requestable.assessment,
:reference_requests,
]
if @form.passed
redirect_to [
:assessor_interface,
application_form,
assessment,
:reference_requests,
]
else
redirect_to [
:verify_failed,
:assessor_interface,
application_form,
assessment,
reference_request,
]
end
else
render :edit, status: :unprocessable_entity
render :edit_verify, status: :unprocessable_entity
end
end

def edit_review
@form = RequestableReviewForm.new(requestable:)
end

def update_review
def edit_verify_failed
@form =
RequestableReviewForm.new(
RequestableVerifyFailedForm.new(
requestable:,
user: current_staff,
**requestable_review_form_params,
note: requestable.verify_note,
)
end

def update_verify_failed
@form =
RequestableVerifyFailedForm.new(
verify_failed_form_params.merge(requestable:, user: current_staff),
)

if @form.save
redirect_to [:review, :assessor_interface, application_form, assessment]
redirect_to [
:assessor_interface,
requestable.application_form,
requestable.assessment,
:reference_requests,
]
else
render :edit_review, status: :unprocessable_entity
render :edit_verify_failed, status: :unprocessable_entity
end
end

private

def set_list_variables
@reference_requests = reference_requests
@application_form = reference_requests.first.application_form
@assessment = reference_requests.first.assessment
end

def set_individual_variables
@reference_request = reference_request
@reference_request = authorize [:assessor_interface, reference_request]
@application_form = reference_request.application_form
@assessment = reference_request.assessment
end

def requestable_review_form_params
def review_form_params
params.require(:assessor_interface_requestable_review_form).permit(
:passed,
:note,
)
end

def verify_references_form_params
params.fetch(:assessor_interface_verify_references_form, {}).permit(
:references_verified,
def verify_passed_form_params
params.require(:assessor_interface_requestable_verify_passed_form).permit(
:passed,
)
end

def verify_failed_form_params
params.require(:assessor_interface_requestable_verify_failed_form).permit(
:note,
)
end

Expand Down
27 changes: 19 additions & 8 deletions app/forms/assessor_interface/select_work_histories_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AssessorInterface::SelectWorkHistoriesForm
&.map(&:to_s) || []
end,
}
validate :work_history_enough_months
validate :work_history_enough_months_selected
validate :work_history_most_recent_selected

def save
return false unless valid?
Expand All @@ -29,16 +30,26 @@ def save

private

def work_history_enough_months
def work_history_enough_months_selected
return if application_form.nil? || session.nil?

errors.add(:work_history_ids, :blank) unless has_enough_work_history?
unless WorkHistoryDuration.for_ids(
work_history_ids,
application_form:,
).enough_for_submission?
errors.add(:work_history_ids, :less_than_9_months)
end
end

def has_enough_work_history?
WorkHistoryDuration.for_ids(
work_history_ids,
application_form:,
).enough_for_submission?
def work_history_most_recent_selected
return if application_form.nil? || session.nil?
return if application_form.region.checks_available?

most_recent_work_history_id =
application_form.work_histories.order_by_role.first.id.to_s

unless work_history_ids.include?(most_recent_work_history_id)
errors.add(:work_history_ids, :most_recent_not_selected)
end
end
end
Loading

0 comments on commit 77ed7b1

Please sign in to comment.