diff --git a/app/controllers/assessor_interface/suitability_records_controller.rb b/app/controllers/assessor_interface/suitability_records_controller.rb index a1048f643..c57243328 100644 --- a/app/controllers/assessor_interface/suitability_records_controller.rb +++ b/app/controllers/assessor_interface/suitability_records_controller.rb @@ -59,6 +59,16 @@ def edit end def update + if suitability_record.archived? + suitability_record.update!( + archived_at: nil, + archived_by: nil, + archive_note: "", + ) + redirect_to [:edit, :assessor_interface, suitability_record] + return + end + @form = SuitabilityRecordForm.new( form_params.merge(suitability_record:, user: current_staff), @@ -71,6 +81,23 @@ def update end end + def archive + @form = ArchiveSuitabilityRecordForm.new(suitability_record:) + end + + def destroy + @form = + ArchiveSuitabilityRecordForm.new( + archive_form_params.merge(suitability_record:, user: current_staff), + ) + + if @form.save + redirect_to action: :index + else + render :archive, status: :unprocessable_entity + end + end + private def form_params @@ -85,6 +112,12 @@ def form_params ) end + def archive_form_params + params.require( + :assessor_interface_archive_suitability_record_form, + ).permit(:note) + end + def suitability_record @suitability_record ||= authorize [:assessor_interface, SuitabilityRecord.find(params[:id])] diff --git a/app/views/assessor_interface/suitability_records/archive.html.erb b/app/views/assessor_interface/suitability_records/archive.html.erb new file mode 100644 index 000000000..1c87a41b5 --- /dev/null +++ b/app/views/assessor_interface/suitability_records/archive.html.erb @@ -0,0 +1,16 @@ +<% title = "Archive suitability record for #{@suitability_record.name}" %> + +<% content_for :page_title, title %> +<% content_for :back_link_url, assessor_interface_suitability_records_path %> + +<%= form_with model: @form, url: [:assessor_interface, @suitability_record], method: :delete do |f| %> + <%= f.govuk_error_summary %> + +

<%= title %>

+ + <%= f.govuk_text_area :note %> + + <%= f.govuk_submit "Archive record" do %> + <%= govuk_link_to "Cancel", %i[assessor_interface suitability_records] %> + <% end %> +<% end %> diff --git a/app/views/assessor_interface/suitability_records/edit.html.erb b/app/views/assessor_interface/suitability_records/edit.html.erb index 29001ba23..fd39edd8d 100644 --- a/app/views/assessor_interface/suitability_records/edit.html.erb +++ b/app/views/assessor_interface/suitability_records/edit.html.erb @@ -40,13 +40,30 @@ row.with_key { "Suitability reasons" } row.with_value { @suitability_record.note } end + + if @suitability_record.archived? + summary_list.with_row do |row| + row.with_key { "Date archived" } + row.with_value { @suitability_record.archived_at.to_fs } + end + + summary_list.with_row do |row| + row.with_key { "Reason for archiving" } + row.with_value { @suitability_record.archive_note } + end + end end %> -

Update record

+ <% if @suitability_record.archived? %> + <%= f.govuk_submit "Set to active", secondary: true %> + <% else %> +

Update record

- <%= render "form_fields", f: %> + <%= render "form_fields", f: %> - <%= f.govuk_submit "Update record" do %> - <%= govuk_link_to "Cancel", %i[assessor_interface suitability_records] %> + <%= f.govuk_submit "Update record" do %> + <%= govuk_button_link_to "Archive record", [:archive, :assessor_interface, @suitability_record], secondary: true, id: "app-archive-button" %> + <%= govuk_link_to "Cancel", %i[assessor_interface suitability_records] %> + <% end %> <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 656749bdc..a0b017258 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -204,9 +204,9 @@ to: "uploads#show", as: :application_form_document_upload - resources :suitability_records, - path: "/suitability-records", - only: %i[index new create edit update] + resources :suitability_records, path: "/suitability-records" do + get "archive", on: :member + end end namespace :eligibility_interface, path: "/eligibility" do diff --git a/spec/support/autoload/page_objects/assessor_interface/archive_suitability_record.rb b/spec/support/autoload/page_objects/assessor_interface/archive_suitability_record.rb new file mode 100644 index 000000000..0c90ee7a3 --- /dev/null +++ b/spec/support/autoload/page_objects/assessor_interface/archive_suitability_record.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module PageObjects + module AssessorInterface + class ArchiveSuitabilityRecord < SitePrism::Page + set_url "/assessor/suitability-records/{id}/archive" + + section :form, "form" do + element :note_field, + "#assessor-interface-archive-suitability-record-form-note-field" + element :submit_button, ".govuk-button:not(.govuk-button--secondary)" + end + end + end +end diff --git a/spec/support/autoload/page_objects/assessor_interface/edit_suitability_record.rb b/spec/support/autoload/page_objects/assessor_interface/edit_suitability_record.rb index becc6d43d..c59b14177 100644 --- a/spec/support/autoload/page_objects/assessor_interface/edit_suitability_record.rb +++ b/spec/support/autoload/page_objects/assessor_interface/edit_suitability_record.rb @@ -6,6 +6,8 @@ class EditSuitabilityRecord < SuitabilityRecordFormPage set_url "/assessor/suitability-records/{id}/edit" element :heading, "h1" + + element :archive_button, "#app-archive-button" end end end diff --git a/spec/support/page_helpers.rb b/spec/support/page_helpers.rb index ce7cbaa7c..b9621caa4 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -29,6 +29,11 @@ def assessor_applications_page PageObjects::AssessorInterface::Applications.new end + def assessor_archive_suitability_record_page + @assessor_archive_suitability_record_page ||= + PageObjects::AssessorInterface::ArchiveSuitabilityRecord.new + end + def assessor_assessment_recommendation_review_page @assessor_assessment_recommendation_review_page ||= PageObjects::AssessorInterface::AssessmentRecommendationReview.new diff --git a/spec/system/assessor_interface/suitability_spec.rb b/spec/system/assessor_interface/suitability_spec.rb index 0ecc0466d..15e3b8694 100644 --- a/spec/system/assessor_interface/suitability_spec.rb +++ b/spec/system/assessor_interface/suitability_spec.rb @@ -14,7 +14,7 @@ then_i_see_the_suitability_records end - it "create and edit suitability records" do + it "create and edit and archive suitability records" do given_i_am_authorized_as_a_user(assessor) when_i_visit_the(:assessor_suitability_records_page) @@ -31,6 +31,13 @@ when_i_fill_in_the_fields and_i_submit_the_form then_i_see_the_suitability_records + + when_i_click_on_the_suitability_record + then_i_see_the(:assessor_edit_suitability_record_page) + + when_i_click_archive + then_i_see_the(:assessor_archive_suitability_record_page) + and_i_submit_the_archive_form end def given_suitability_is_enabled @@ -79,6 +86,16 @@ def when_i_click_on_the_suitability_record assessor_suitability_records_page.records.first.heading.link.click end + def when_i_click_archive + assessor_edit_suitability_record_page.archive_button.click + end + + def and_i_submit_the_archive_form + form = assessor_archive_suitability_record_page.form + form.note_field.fill_in with: "A note." + form.submit_button.click + end + def assessor @assessor ||= create(:staff, :with_assess_permission) end