Skip to content

Commit

Permalink
Disable assessment forms after assessment
Browse files Browse the repository at this point in the history
When a recommendation has been made by an assessor we should disable the
forms to prevent them being modified after an assessment has been made.
  • Loading branch information
thomasleese committed Apr 23, 2024
1 parent f8bc175 commit 53c768d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def show
end

def update
unless view_object.show_form?
if view_object.disable_form?
redirect_to [
:assessor_interface,
application_form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def show_form?
true
end

def disable_form?
return true unless show_form?
return true unless assessment.unknown?

preliminary? ? assessment.all_preliminary_sections_passed? : false
end

def show_english_language_exemption_content?
assessment_section.english_language_proficiency? &&
application_form.english_language_exempt?
Expand Down
40 changes: 26 additions & 14 deletions app/views/assessor_interface/assessment_sections/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
label: {
text: t(view_object.assessment_section.key, scope: %i[assessor_interface assessment_sections english_language_proficiency passed]),
size: "s",
} %>
},
disabled: view_object.disable_form? %>
<% end %>

<% if view_object.show_english_language_provider_details? %>
Expand All @@ -30,48 +31,57 @@
<% end %>

<% if form.is_a?(AssessorInterface::CheckAgeRangeSubjectsForm) %>
<%= render "shared/age_range_subjects_form_fields", f: %>
<%= render "shared/age_range_subjects_form_fields", f:, disabled: view_object.disable_form? %>
<% end %>

<% if form.is_a?(AssessorInterface::ScotlandFullRegistrationForm) %>
<%= f.govuk_collection_radio_buttons :scotland_full_registration, %i[true false], :itself %>
<%= f.govuk_radio_buttons_fieldset :scotland_full_registration do %>
<%= f.govuk_radio_button :scotland_full_registration, :true, link_errors: true, disabled: view_object.disable_form? %>
<%= f.govuk_radio_button :scotland_full_registration, :false, disabled: view_object.disable_form? %>
<% end %>
<% end %>

<% if form.is_a?(AssessorInterface::InductionRequiredForm) %>
<%= f.govuk_radio_buttons_fieldset :induction_required, legend: { text: t(view_object.country.code, scope: %i[assessor_interface assessment_sections induction_required]) } do %>
<%= f.govuk_radio_button :induction_required, :false, link_errors: true %>
<%= f.govuk_radio_button :induction_required, :true do %>
<%= f.govuk_radio_button :induction_required, :false, link_errors: true, disabled: view_object.disable_form? %>
<%= f.govuk_radio_button :induction_required, :true, disabled: view_object.disable_form? do %>
<p class="govuk-hint">We can still award QTS, but applicant must complete a statutory induction period.</p>
<% end %>
<% end %>
<% end %>

<% if view_object.preliminary? %>
<% view_object.failure_reasons.each do |failure_reason| %>
<%= f.govuk_collection_radio_buttons "#{failure_reason}_checked".to_sym,
<%= f.govuk_collection_radio_buttons :"#{failure_reason}_checked",
[
OpenStruct.new(value: :false, label: "Yes"),
OpenStruct.new(value: :true, label: "No")
],
:value,
:label,
legend: { text: t(failure_reason, scope: %i[assessor_interface assessment_sections failure_reasons as_question label]), size: "s" },
hint: { text: t(failure_reason, scope: %i[assessor_interface assessment_sections failure_reasons as_question hint], default: "") }%>
hint: { text: t(failure_reason, scope: %i[assessor_interface assessment_sections failure_reasons as_question hint], default: "") },
disabled: view_object.disable_form? %>
<% end %>
<% else %>
<%= f.govuk_radio_buttons_fieldset :passed, legend: { text: "Has the applicant completed this section to your satisfaction?" } do %>
<%= f.govuk_radio_button :passed, true, label: { text: "Yes" }, link_errors: true %>
<%= f.govuk_radio_button :passed, false, label: { text: "No" } do %>
<%= f.govuk_radio_button :passed, true, label: { text: "Yes" }, link_errors: true, disabled: view_object.disable_form? %>
<%= f.govuk_radio_button :passed, false, label: { text: "No" }, disabled: view_object.disable_form? do %>
<div id="assessor-interface-assessment-section-form-selected-failure-reasons-field-error"></div>
<%= f.govuk_check_boxes_fieldset :selected_failure_reasons, legend: { size: "s" } do %>
<% view_object.failure_reasons.each do |failure_reason| %>
<%= f.govuk_check_box "#{failure_reason}_checked".to_sym, true, label: { text: t(failure_reason, scope: %i[assessor_interface assessment_sections failure_reasons as_statement]) } do %>
<%= f.govuk_text_area "#{failure_reason}_notes".to_sym,
<%= f.govuk_check_box :"#{failure_reason}_checked", true, label: { text: t(failure_reason, scope: %i[assessor_interface assessment_sections failure_reasons as_statement]) }, disabled: view_object.disable_form? do %>
<%= f.govuk_text_area :"#{failure_reason}_notes",
label: { text: t(view_object.notes_label_key_for(failure_reason:)), size: "s" },
hint: { text: t(view_object.notes_hint_key_for(failure_reason:)) },
placeholder: t(view_object.notes_placeholder_key_for(failure_reason:)) %>
placeholder: t(view_object.notes_placeholder_key_for(failure_reason:)),
disabled: view_object.disable_form? %>
<% if FailureReasons::chooses_work_history?(failure_reason) %>
<%= f.govuk_collection_check_boxes :"#{failure_reason}_work_history_checked", view_object.work_histories, :id, :school_name, multiple: false, legend: { size: "s" } %>
<%= f.govuk_check_boxes_fieldset :"#{failure_reason}_work_history_checked", legend: { size: "s" } do %>
<% view_object.work_histories.each do |work_history| %>
<%= f.govuk_check_box :"#{failure_reason}_work_history_checked", work_history.id, label: { text: work_history.school_name }, disabled: view_object.disable_form? %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
Expand All @@ -80,5 +90,7 @@
<% end %>
<% end %>

<%= render "shared/assessor_interface/continue_cancel_button", f: %>
<%= f.govuk_submit disabled: view_object.disable_form? do %>
<%= render "shared/assessor_interface/cancel_link" %>
<% end %>
<% end %>
16 changes: 10 additions & 6 deletions app/views/shared/_age_range_subjects_form_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<%= f.govuk_fieldset legend: { text: 'What age range is the applicant qualified to teach?' } do %>
<% disabled ||= false %>

<%= f.govuk_fieldset legend: { text: "What age range is the applicant qualified to teach?" } do %>
<p class="govuk-body">Based on the evidence the applicant has provided, you can either copy the age range they entered if you agree, or enter a new range.</p>

<%= f.govuk_number_field :age_range_min, width: 3 %>
<%= f.govuk_number_field :age_range_max, width: 3 %>
<%= f.govuk_text_area :age_range_note, label: { text: t("helpers.label.assessor_interface_assessment_section_form.age_range_note").html_safe } %>
<%= f.govuk_number_field :age_range_min, width: 3, disabled: %>
<%= f.govuk_number_field :age_range_max, width: 3, disabled: %>
<%= f.govuk_text_area :age_range_note, label: { text: t("helpers.label.assessor_interface_assessment_section_form.age_range_note").html_safe }, disabled: %>
<% end %>

<h2 class="govuk-heading-m">Which subjects can the applicant teach in England?</h2>
Expand All @@ -20,8 +22,10 @@
dfe_autocomplete_options(Subject.all),
f.object.send(field),
),
)
disabled:
),
html_attributes: { disabled: disabled ? "disabled" : "" }
) %>
<% end %>

<%= f.govuk_text_area :subjects_note, label: { text: t("helpers.label.assessor_interface_assessment_section_form.subjects_note").html_safe } %>
<%= f.govuk_text_area :subjects_note, label: { text: t("helpers.label.assessor_interface_assessment_section_form.subjects_note").html_safe }, disabled: %>
18 changes: 9 additions & 9 deletions spec/forms/assessor_interface/assessment_section_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@
end
it do
is_expected.not_to validate_presence_of(
"#{decline_failure_reason}_notes".to_sym,
:"#{decline_failure_reason}_notes",
)
end
end

context "when reasons are checked and notes are provided" do
let(:attributes) do
{
:passed => false,
:"#{further_information_failure_reason}_checked" => true,
:"#{further_information_failure_reason}_notes" => "Notes.",
:"#{work_history_failure_reason}_checked" => true,
:"#{work_history_failure_reason}_notes" => "Notes.",
:"#{work_history_failure_reason}_work_history_checked" => [1],
"#{decline_failure_reason}_checked".to_sym => true,
"#{decline_failure_reason}_notes".to_sym => "Notes",
passed: false,
"#{further_information_failure_reason}_checked": true,
"#{further_information_failure_reason}_notes": "Notes.",
"#{work_history_failure_reason}_checked": true,
"#{work_history_failure_reason}_notes": "Notes.",
"#{work_history_failure_reason}_work_history_checked": [1],
"#{decline_failure_reason}_checked": true,
"#{decline_failure_reason}_notes": "Notes",
}
end

Expand Down

0 comments on commit 53c768d

Please sign in to comment.