Skip to content

Commit

Permalink
Split verification in to two pages
Browse files Browse the repository at this point in the history
If the admin decides that the LoPS is not acceptable, and they'd like to
send this to review, we've decided to split this in to two pages so the
internal notes appears on its own page.
  • Loading branch information
thomasleese committed Nov 7, 2023
1 parent 5f6c3b1 commit 2d2b95b
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module AssessorInterface
class ProfessionalStandingRequestsController < BaseController
before_action :set_variables

def show
before_action do
authorize [:assessor_interface, professional_standing_request]
end

def show
render layout: "full_from_desktop"
end

def edit_locate
authorize [:assessor_interface, professional_standing_request]

@form =
ProfessionalStandingRequestLocationForm.new(
requestable:,
Expand All @@ -24,8 +24,6 @@ def edit_locate
end

def update_locate
authorize [:assessor_interface, professional_standing_request]

@form =
ProfessionalStandingRequestLocationForm.new(
location_form_params.merge(requestable:, user: current_staff),
Expand All @@ -39,14 +37,10 @@ def update_locate
end

def edit_request
authorize [:assessor_interface, professional_standing_request]

@form = RequestableRequestForm.new(requestable:, user: current_staff)
end

def update_request
authorize [:assessor_interface, professional_standing_request]

@form =
RequestableRequestForm.new(
request_form_params.merge(user: current_staff, requestable:),
Expand All @@ -63,8 +57,6 @@ def update_request
end

def edit_review
authorize [:assessor_interface, professional_standing_request]

@form =
RequestableReviewForm.new(
requestable:,
Expand All @@ -75,8 +67,6 @@ def edit_review
end

def update_review
authorize [:assessor_interface, professional_standing_request]

@form =
RequestableReviewForm.new(
review_form_params.merge(requestable:, user: current_staff),
Expand All @@ -95,23 +85,55 @@ def update_review
end

def edit_verify
authorize [:assessor_interface, professional_standing_request]

@form =
RequestableVerifyForm.new(
RequestableVerifyPassedForm.new(
requestable:,
user: current_staff,
passed: requestable.verify_passed,
note: requestable.verify_note,
)
end

def update_verify
authorize [:assessor_interface, professional_standing_request]
@form =
RequestableVerifyPassedForm.new(
verify_passed_form_params.merge(requestable:, user: current_staff),
)

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

def edit_verify_failed
@form =
RequestableVerifyForm.new(
verify_form_params.merge(requestable:, user: current_staff),
RequestableVerifyFailedForm.new(
requestable:,
user: current_staff,
note: requestable.verify_note,
)
end

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

if @form.save
Expand All @@ -122,7 +144,7 @@ def update_verify
:professional_standing_request,
]
else
render :edit_verify, status: :unprocessable_entity
render :edit_verify_failed, status: :unprocessable_entity
end
end

Expand Down Expand Up @@ -153,9 +175,14 @@ def review_form_params
)
end

def verify_form_params
params.require(:assessor_interface_requestable_verify_form).permit(
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
20 changes: 20 additions & 0 deletions app/forms/assessor_interface/requestable_verify_failed_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

class AssessorInterface::RequestableVerifyFailedForm
include ActiveModel::Model
include ActiveModel::Attributes

attr_accessor :requestable, :user
validates :requestable, :user, presence: true

attribute :note, :string
validates :note, presence: true

def save
return false if invalid?

VerifyRequestable.call(requestable:, user:, passed: false, note:)

true
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class AssessorInterface::RequestableVerifyForm
class AssessorInterface::RequestableVerifyPassedForm
include ActiveModel::Model
include ActiveModel::Attributes

Expand All @@ -10,14 +10,12 @@ class AssessorInterface::RequestableVerifyForm
attribute :passed, :boolean
validates :passed, inclusion: [true, false]

attribute :note, :string
validates :note, presence: true, if: -> { passed == false }

def save
return false if invalid?

ReceiveRequestable.call(requestable:, user:) unless requestable.received?
VerifyRequestable.call(requestable:, user:, passed:, note:)

VerifyRequestable.call(requestable:, user:, passed:, note: "") if passed

true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def update_verify?

alias_method :edit_verify?, :update_verify?

def update_verify_failed?
user.verify_permission
end

alias_method :edit_verify_failed?, :update_verify_failed?

def update_review?
user.assess_permission
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

<h1 class="govuk-heading-xl">Record LoPS response</h1>

<%= f.govuk_radio_buttons_fieldset :passed, legend: { text: "Does the response confirm that the LoPS is valid?" } do %>
<%= f.govuk_radio_button :passed, :true, label: { text: "Yes, mark as completed" }, link_errors: true %>
<%= f.govuk_radio_button :passed, :false, label: { text: "No, send for review" } do %>
<%= f.govuk_text_area :note, label: { text: "Internal note: briefly explain to the assessor why you are sending this LoPS for review." } %>
<% end %>
<% end %>
<%= f.govuk_collection_radio_buttons :passed, %i[true false], :itself,
legend: { text: "Does the response confirm that the LoPS is valid?" } %>

<%= f.govuk_submit do %>
<%= govuk_link_to "Cancel", [:assessor_interface, @application_form] %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% content_for :page_title, "#{"Error: " if @form.errors.any?}Record LoPS response" %>
<% content_for :back_link_url, assessor_interface_application_form_path(@application_form) %>

<%= form_with model: @form, url: [:verify_failed, :assessor_interface, @application_form, @assessment, :professional_standing_request] do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-xl">Record LoPS response</h1>

<p class="govuk-body">You have opted to send this LoPS for review.</p>

<%= f.govuk_text_area :note, label: { text: "Internal note: briefly explain to the assessor why you are sending this LoPS for review." } %>

<%= f.govuk_submit do %>
<%= govuk_link_to "Cancel", [:assessor_interface, @application_form] %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
status: @professional_standing_request.requested? ? "completed" : "not_started"
},
{
name: "Record LoPS verification",
link: [
:verify,
:assessor_interface,
@application_form,
@assessment,
:professional_standing_request
],
status: @professional_standing_request.status,
name: "Record LoPS response",
link: if @professional_standing_request.requested?
[
:verify,
:assessor_interface,
@application_form,
@assessment,
:professional_standing_request
]
end,
status: @professional_standing_request.requested? ? @professional_standing_request.status : "cannot_start"
}
],
}
Expand Down
8 changes: 5 additions & 3 deletions config/locales/assessor_interface.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,14 @@ en:
inclusion: Select whether you are satisfied with the request
note:
blank: Enter why you are not satisfied
assessor_interface/requestable_verify_form:
assessor_interface/requestable_verify_failed_form:
attributes:
passed:
inclusion: Select whether you are satisfied with the request
note:
blank: Enter why you are not satisfied
assessor_interface/requestable_verify_passed_form:
attributes:
passed:
inclusion: Select whether you are satisfied with the request
assessor_interface/select_qualifications_form:
attributes:
qualification_ids:
Expand Down
6 changes: 3 additions & 3 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ en:
passed_options:
true: "Yes"
false: "No"
assessor_interface_requestable_verify_form:
assessor_interface_requestable_verify_passed_form:
passed_options:
true: "Yes"
false: "No"
true: "Yes, mark as completed"
false: "No, send for review"
assessor_interface_verify_professional_standing_form:
verify_professional_standing_options:
true: Yes, verify LoPS
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
post "review", to: "professional_standing_requests#update_review"
get "verify", to: "professional_standing_requests#edit_verify"
post "verify", to: "professional_standing_requests#update_verify"
get "verify-failed",
to: "professional_standing_requests#edit_verify_failed"
post "verify-failed",
to: "professional_standing_requests#update_verify_failed"
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AssessorInterface::RequestableVerifyFailedForm, type: :model do
let(:requestable) { create(:reference_request, :received) }
let(:user) { create(:staff) }
let(:note) { "" }

subject(:form) { described_class.new(requestable:, user:, note:) }

describe "validations" do
it { is_expected.to validate_presence_of(:note) }
end

describe "#save" do
subject(:save) { form.save }

context "when passed is false" do
let(:note) { "Note." }

it "sets verify_passed" do
expect { save }.to change(requestable, :verify_passed).from(nil).to(
false,
)
end

it "sets verify_note" do
expect { save }.to change(requestable, :verify_note).from("").to(
"Note.",
)
end

it "sets verified_at" do
freeze_time do
expect { save }.to change(requestable, :verified_at).from(nil).to(
Time.zone.now,
)
end
end

it "updates induction required" do
expect(UpdateAssessmentInductionRequired).to receive(:call)
save # rubocop:disable Rails/SaveBang
end
end
end
end
Loading

0 comments on commit 2d2b95b

Please sign in to comment.