Skip to content

Commit

Permalink
Merge pull request #2052 from DFE-Digital/review-consent
Browse files Browse the repository at this point in the history
Allow reviewing consent requests
  • Loading branch information
thomasleese authored Feb 29, 2024
2 parents 357c035 + e513334 commit cbdc0c7
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 18 deletions.
7 changes: 7 additions & 0 deletions app/controllers/assessor_interface/assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def review
@professional_standing_request =
assessment.professional_standing_request if assessment.professional_standing_request&.verify_failed?

@consent_requests =
assessment
.consent_requests
.includes(:qualification)
.where(verify_passed: false)
.order_by_role

@qualification_requests =
assessment
.qualification_requests
Expand Down
67 changes: 67 additions & 0 deletions app/controllers/assessor_interface/consent_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

module AssessorInterface
class ConsentRequestsController < BaseController
include HistoryTrackable

before_action :set_variables

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

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

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

private

def application_form
@application_form ||=
ApplicationForm.includes(:assessment).find_by(
reference: params[:application_form_reference],
assessment: {
id: params[:assessment_id],
},
)
end

def assessment
@assessment ||= application_form.assessment
end

def consent_requests
@consent_requests ||= assessment.consent_requests
end

def consent_request
@consent_request ||= consent_requests.find(params[:id])
end

alias_method :requestable, :consent_request

def set_variables
@consent_request = authorize [:assessor_interface, consent_request]
@application_form = application_form
@assessment = assessment
end

def review_form_params
params.require(:assessor_interface_requestable_review_form).permit(
:passed,
:note,
)
end
end
end
50 changes: 44 additions & 6 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ def can_award?
all_sections_or_further_information_requests_passed?
elsif verify?
enough_reference_requests_verify_passed? &&
all_consent_requests_verify_passed? &&
all_qualification_requests_review_passed? &&
professional_standing_request_verify_passed?
elsif review?
enough_reference_requests_review_passed? &&
all_consent_requests_review_passed? &&
all_qualification_requests_review_passed? &&
professional_standing_request_review_passed?
else
Expand All @@ -122,22 +124,26 @@ def can_decline?
any_further_information_requests_failed?
elsif verify?
if professional_standing_request_verify_failed? ||
any_reference_requests_verify_failed?
any_reference_requests_verify_failed? ||
any_consent_requests_verify_failed?
return false
end

return false unless all_reference_requests_verified?
return false unless all_consent_requests_verified?
return false unless all_qualification_requests_reviewed?
return false unless all_reference_requests_verified?
return false unless professional_standing_request_verified?

any_qualification_requests_review_failed?
elsif review?
return false unless all_reference_requests_reviewed?
return false unless all_consent_requests_reviewed?
return false unless all_qualification_requests_reviewed?
return false unless all_reference_requests_reviewed?
return false unless professional_standing_request_reviewed?

any_reference_requests_review_failed? ||
any_consent_requests_review_failed? ||
any_qualification_requests_review_failed? ||
any_reference_requests_review_failed? ||
professional_standing_request_review_failed?
else
false
Expand All @@ -158,11 +164,13 @@ def can_review?
return false unless verify?
return false unless application_form.created_under_new_regulations?

return false unless all_reference_requests_verified?
return false unless all_consent_requests_verified?
return false unless all_qualification_requests_reviewed?
return false unless all_reference_requests_verified?
return false unless professional_standing_request_verified?

any_qualification_requests_verify_failed? ||
any_consent_requests_verify_failed? ||
any_qualification_requests_verify_failed? ||
any_reference_requests_verify_failed? ||
professional_standing_request_verify_failed?
end
Expand Down Expand Up @@ -287,7 +295,37 @@ def any_reference_requests_review_failed?
reference_requests.any?(&:review_failed?)
end

def all_consent_requests_reviewed?
consent_requests.where(verify_passed: false).all?(&:reviewed?)
end

def any_consent_requests_review_failed?
consent_requests.any?(&:review_failed?)
end

def all_consent_requests_review_passed?
consent_requests.all? do |consent_request|
consent_request.verify_passed? || consent_request.review_passed?
end
end

def all_consent_requests_verified?
consent_requests.all?(&:verified?)
end

def any_consent_requests_verify_failed?
consent_requests.any?(&:verify_failed?)
end

def all_consent_requests_verify_passed?
consent_requests.all?(&:verify_passed?)
end

def all_qualification_requests_reviewed?
# we can skip qualifications if consent is invalid
if all_consent_requests_verified? && any_consent_requests_verify_failed?
return true
end
qualification_requests.all?(&:reviewed?)
end

Expand Down
9 changes: 9 additions & 0 deletions app/policies/assessor_interface/consent_request_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class AssessorInterface::ConsentRequestPolicy < ApplicationPolicy
def update_review?
user.assess_permission
end

alias_method :edit_review?, :update_review?
end
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def management_tasks
:teaching_authority_provides_written_statement,
:work_histories,
to: :application_form
delegate :professional_standing_request,
delegate :consent_requests,
:professional_standing_request,
:qualification_requests,
:reference_requests,
to: :assessment
Expand Down Expand Up @@ -257,15 +258,15 @@ def further_information_request_task_list_item(further_information_request)

def verification_task_list_section
return unless pre_assessment_complete?
return if assessment.unknown? || assessment.request_further_information?

items = [
qualification_requests_task_list_item,
reference_requests_task_list_item,
professional_standing_request_task_list_item,
verification_decision_task_list_item,
].compact

items << verification_decision_task_list_item if items.present?

{
title:
I18n.t(
Expand Down Expand Up @@ -370,7 +371,8 @@ def review_task_list_section
if (
!teaching_authority_provides_written_statement &&
professional_standing_request&.verify_failed?
) || qualification_requests.any?(&:verify_failed?) ||
) || consent_requests.any?(&:verify_failed?) ||
qualification_requests.any?(&:verify_failed?) ||
reference_requests.any?(&:verify_failed?)
{
title:
Expand Down Expand Up @@ -398,7 +400,8 @@ def review_verifications_task_list_item
elsif (
!teaching_authority_provides_written_statement &&
professional_standing_request&.reviewed?
) || reference_requests.any?(:reviewed?)
) || consent_requests.any?(:reviewed?) ||
reference_requests.any?(:reviewed?)
:in_progress
else
:not_started
Expand Down
10 changes: 8 additions & 2 deletions app/views/assessor_interface/assessments/review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@
],
}
end,
if @qualification_requests.present?
if @consent_requests.present? || @qualification_requests.present?
{
title: "Qualifications",
indentation: false,
items: @qualification_requests.map do |qualification_request|
items: @consent_requests.map do |consent_request|
{
name: qualification_title(consent_request.qualification),
link: [:review, :assessor_interface, @application_form, @assessment, consent_request],
status: consent_request.review_status,
}
end + @qualification_requests.map do |qualification_request|
{
name: qualification_title(qualification_request.qualification),
link: [:review, :assessor_interface, @application_form, @assessment, qualification_request],
Expand Down
41 changes: 41 additions & 0 deletions app/views/assessor_interface/consent_requests/edit_review.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<% title = "Review qualification" %>

<% content_for :page_title, title_with_error_prefix(title, error: @form.errors.any?) %>
<% content_for :back_link_url, back_history_path(default: review_assessor_interface_application_form_assessment_path(@application_form, @assessment)) %>

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

<h1 class="govuk-heading-xl"><%= title %></h1>

<h2 class="govuk-heading-m">
<%= qualification_title(@consent_request.qualification) %>
</h2>

<% if @consent_request.expired? && @consent_request.received? %>
<%= govuk_inset_text do %>
<p>This qualifications’s status has changed from <%= render(StatusTag::Component.new("overdue")) %> to <%= render(StatusTag::Component.new("received")) %>.</p>
<% end %>

<%= govuk_details(summary_text: "See previous notes") do %>
<%= govuk_inset_text do %>
<h3 class="govuk-heading-s">Internal note</h3>
<%= simple_format @consent_request.verify_note %>
<% end %>
<% end %>
<% else %>
<%= govuk_inset_text do %>
<h3 class="govuk-heading-s">Internal note</h3>
<%= simple_format @consent_request.verify_note %>
<% end %>
<% end %>

<%= f.govuk_radio_buttons_fieldset :passed, legend: { text: "After review, does the response confirm that this qualification is legitimate?", size: "s" } do %>
<%= f.govuk_radio_button :passed, :true, link_errors: true %>
<%= f.govuk_radio_button :passed, :false do %>
<%= f.govuk_text_area :note, label: { text: "Internal note: briefly explain why the qualification should not be accepted." } %>
<% end %>
<% end %>

<%= render "shared/assessor_interface/continue_cancel_button", f: %>
<% end %>
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
"assessment_recommendation_verify#update_professional_standing"
end

resources :consent_requests, path: "/consent-requests", only: [] do
member do
get "review", to: "consent_requests#edit_review"
post "review", to: "consent_requests#update_review"
end
end

resources :further_information_requests,
path: "/further-information-requests",
only: %i[new create edit update] do
Expand Down
47 changes: 47 additions & 0 deletions spec/policies/assessor_interface/consent_request_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AssessorInterface::ConsentRequestPolicy do
it_behaves_like "a policy"

let(:user) { nil }
let(:record) { nil }

subject(:policy) { described_class.new(user, record) }

describe "#index?" do
subject(:index?) { policy.index? }
it_behaves_like "a policy method without permission"
end

describe "#show?" do
subject(:show?) { policy.show? }
it_behaves_like "a policy method without permission"
end

describe "#create?" do
subject(:create?) { policy.create? }
it_behaves_like "a policy method without permission"
end

describe "#new?" do
subject(:new?) { policy.new? }
it_behaves_like "a policy method without permission"
end

describe "#update_review?" do
subject(:update_review?) { policy.update_review? }
it_behaves_like "a policy method requiring the assess permission"
end

describe "#edit_review?" do
subject(:edit_review?) { policy.edit_review? }
it_behaves_like "a policy method requiring the assess permission"
end

describe "#destroy?" do
subject(:destroy?) { policy.destroy? }
it_behaves_like "a policy method without permission"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module PageObjects
module AssessorInterface
class ReviewConsentRequest < ReviewRequestablePage
set_url "/assessor/applications/{reference}/assessments/{assessment_id}" \
"/consent-requests/{id}/review"
end
end
end
5 changes: 5 additions & 0 deletions spec/support/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ def assessor_reverse_decision_page
PageObjects::AssessorInterface::ReverseDecision.new
end

def assessor_review_consent_request_page
@assessor_review_consent_request_page ||=
PageObjects::AssessorInterface::ReviewConsentRequest.new
end

def assessor_review_further_information_request_page
@assessor_review_further_information_request_page ||=
PageObjects::AssessorInterface::ReviewFurtherInformationRequest.new
Expand Down
Loading

0 comments on commit cbdc0c7

Please sign in to comment.