diff --git a/Gemfile.lock b/Gemfile.lock index 808f2c24a..fe5aee68a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -436,6 +436,7 @@ GEM PLATFORMS arm64-darwin-21 arm64-darwin-22 + arm64-darwin-23 x86_64-darwin-19 x86_64-darwin-20 x86_64-darwin-21 diff --git a/app/controllers/bulk_upload_lettings_results_controller.rb b/app/controllers/bulk_upload_lettings_results_controller.rb index a7ea2605a..4281ef4ad 100644 --- a/app/controllers/bulk_upload_lettings_results_controller.rb +++ b/app/controllers/bulk_upload_lettings_results_controller.rb @@ -29,6 +29,12 @@ class BulkUploadLettingsResultsController < ApplicationController authorize @bulk_upload end + def deletion_report + @bulk_upload = BulkUpload.lettings.find(params[:id]) + + authorize @bulk_upload + end + private def reset_logs_filters diff --git a/app/helpers/logs_helper.rb b/app/helpers/logs_helper.rb index c98dedad5..5e7b73d26 100644 --- a/app/helpers/logs_helper.rb +++ b/app/helpers/logs_helper.rb @@ -49,9 +49,10 @@ module LogsHelper end def logs_and_errors_warning(bulk_upload) - this_or_these_errors = bulk_upload.bulk_upload_errors.count == 1 ? "This error" : "These errors" + is_or_are = bulk_upload.total_logs_count == 1 ? "is" : "are" + need_or_needs = bulk_upload.bulk_upload_errors.count == 1 ? "needs" : "need" - "You will upload #{pluralize(bulk_upload.total_logs_count, 'log')}. There are errors in #{pluralize(bulk_upload.logs_with_errors_count, 'log')}, and #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} in total. #{this_or_these_errors} will need to be fixed on the CORE site." + "There #{is_or_are} #{pluralize(bulk_upload.total_logs_count, 'log')} in this bulk upload with #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} that still #{need_or_needs} to be fixed after upload." end def logs_and_soft_validations_warning(bulk_upload) @@ -63,4 +64,12 @@ module LogsHelper def bulk_upload_error_summary(bulk_upload) "You have tried to upload #{bulk_upload.total_logs_count ? pluralize(bulk_upload.total_logs_count, 'log') : 'logs'}. There are errors in #{pluralize(bulk_upload.logs_with_errors_count, 'log')}, and #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} in total." end + + def deleted_errors_warning_text(bulk_upload) + unique_field_count = bulk_upload.bulk_upload_errors.uniq { |e| e.field }.count + this_or_these = unique_field_count == 1 ? "this" : "these" + it_is_or_they_are = unique_field_count == 1 ? "it is" : "they are" + + "#{pluralize(unique_field_count, "answer")} will be deleted because #{it_is_or_they_are} invalid. You will have to answer #{this_or_these} #{"question".pluralize(unique_field_count)} again on the site." + end end diff --git a/app/policies/bulk_upload_policy.rb b/app/policies/bulk_upload_policy.rb index 429661907..2818376d3 100644 --- a/app/policies/bulk_upload_policy.rb +++ b/app/policies/bulk_upload_policy.rb @@ -18,6 +18,10 @@ class BulkUploadPolicy owner? || same_org? || user.support? end + def deletion_report? + owner? || same_org? || user.support? + end + private def owner? diff --git a/app/views/bulk_upload_lettings_results/deletion_report.html.erb b/app/views/bulk_upload_lettings_results/deletion_report.html.erb new file mode 100644 index 000000000..c91be8554 --- /dev/null +++ b/app/views/bulk_upload_lettings_results/deletion_report.html.erb @@ -0,0 +1,27 @@ +
+
+ Bulk upload for lettings (<%= @bulk_upload.year_combo %>) +

<%= @bulk_upload.bulk_upload_errors.count == 1 ? "This" : "These" %> <%= pluralize(@bulk_upload.bulk_upload_errors.count, "answer") %> will be deleted if you upload the logs

+ +

The following cells contain data this is incorrect.

+

If you upload the logs, these answers will be deleted. You will have to re-enter the data on the site and resolve these errors.

+

If you do not want these answers to be deleted, correct the data in the CSV and upload the file again.

+ +

File: <%= @bulk_upload.filename %>

+
+
+ +
+
+ <% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> + <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %> + <% end %> +
+
+ +
+ <%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %> + <%= f.govuk_submit "Clear this data and upload the logs" %> + <%= govuk_button_link_to "I have fixed these errors and I want to reupload the file", start_bulk_upload_lettings_logs_path, secondary: true %> + <% end %> +
diff --git a/app/views/bulk_upload_lettings_resume/confirm.html.erb b/app/views/bulk_upload_lettings_resume/confirm.html.erb index 841fd9e5e..b2fce604e 100644 --- a/app/views/bulk_upload_lettings_resume/confirm.html.erb +++ b/app/views/bulk_upload_lettings_resume/confirm.html.erb @@ -5,9 +5,15 @@
Bulk upload for lettings (<%= @bulk_upload.year_combo %>) -

You have chosen to upload all logs from this bulk upload.

+

Are you sure you want to upload all logs from this bulk upload?

-

<%= logs_and_errors_warning(@bulk_upload) %>

+

+ <%= logs_and_errors_warning(@bulk_upload) %> + <%= govuk_link_to "View the error report", deletion_report_bulk_upload_lettings_result_path %> +

+ + + <%= govuk_warning_text text: deleted_errors_warning_text(@bulk_upload) %> <%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %> <%= f.govuk_submit "Confirm" %> diff --git a/app/views/bulk_upload_lettings_resume/fix_choice.html.erb b/app/views/bulk_upload_lettings_resume/fix_choice.html.erb index 0a46c8c35..b0293e5cb 100644 --- a/app/views/bulk_upload_lettings_resume/fix_choice.html.erb +++ b/app/views/bulk_upload_lettings_resume/fix_choice.html.erb @@ -18,6 +18,10 @@ <%= @form.recommendation %>
+
+ <%= govuk_link_to "View the error report", deletion_report_bulk_upload_lettings_result_path %> +
+ <%= govuk_details(summary_text: "How to choose between fixing errors on the CORE site or in the CSV") do %>

You may find it easier to fix the errors in the CSV file if: