diff --git a/app/controllers/bulk_upload_lettings_resume_controller.rb b/app/controllers/bulk_upload_lettings_resume_controller.rb index 7041051ba..132ca095b 100644 --- a/app/controllers/bulk_upload_lettings_resume_controller.rb +++ b/app/controllers/bulk_upload_lettings_resume_controller.rb @@ -1,5 +1,10 @@ class BulkUploadLettingsResumeController < ApplicationController before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def start @bulk_upload = current_user.bulk_uploads.find(params[:id]) @@ -11,6 +16,8 @@ class BulkUploadLettingsResumeController < ApplicationController @bulk_upload = current_user.bulk_uploads.find(params[:id]) @soft_errors_only = params[:soft_errors_only] == "true" + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "fix-choice" Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadLettingsResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadLettingsResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else diff --git a/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb b/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb index 5f9140452..a70af3c4b 100644 --- a/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb +++ b/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb @@ -2,10 +2,17 @@ class BulkUploadLettingsSoftValidationsCheckController < ApplicationController include ActionView::Helpers::TextHelper before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def show @bulk_upload = current_user.bulk_uploads.find(params[:id]) + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "confirm-soft-errors" Forms::BulkUploadLettingsSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadLettingsSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadLettingsSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else diff --git a/app/controllers/bulk_upload_sales_resume_controller.rb b/app/controllers/bulk_upload_sales_resume_controller.rb index e120620a2..9f937630d 100644 --- a/app/controllers/bulk_upload_sales_resume_controller.rb +++ b/app/controllers/bulk_upload_sales_resume_controller.rb @@ -1,5 +1,10 @@ class BulkUploadSalesResumeController < ApplicationController before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def start @bulk_upload = current_user.bulk_uploads.find(params[:id]) @@ -11,6 +16,8 @@ class BulkUploadSalesResumeController < ApplicationController @bulk_upload = current_user.bulk_uploads.find(params[:id]) @soft_errors_only = params[:soft_errors_only] == "true" + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "fix-choice" Forms::BulkUploadSalesResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadSalesResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadSalesResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else diff --git a/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb b/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb index 6daf167f8..5b71b2c40 100644 --- a/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb +++ b/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb @@ -2,10 +2,17 @@ class BulkUploadSalesSoftValidationsCheckController < ApplicationController include ActionView::Helpers::TextHelper before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def show @bulk_upload = current_user.bulk_uploads.find(params[:id]) + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "confirm-soft-errors" Forms::BulkUploadSalesSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadSalesSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadSalesSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else diff --git a/app/models/forms/bulk_upload_lettings_resume/chosen.rb b/app/models/forms/bulk_upload_lettings_resume/chosen.rb new file mode 100644 index 000000000..6a6f670c4 --- /dev/null +++ b/app/models/forms/bulk_upload_lettings_resume/chosen.rb @@ -0,0 +1,31 @@ +module Forms + module BulkUploadLettingsResume + class Chosen + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_lettings_resume/chosen" + end + + def back_path + lettings_logs_path + end + + def next_path + lettings_logs_path + end + + def save! + true + end + + def preflight_valid? + true + end + end + end +end diff --git a/app/models/forms/bulk_upload_lettings_resume/confirm.rb b/app/models/forms/bulk_upload_lettings_resume/confirm.rb index 7760ab2e8..c109cd1b1 100644 --- a/app/models/forms/bulk_upload_lettings_resume/confirm.rb +++ b/app/models/forms/bulk_upload_lettings_resume/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve + ApplicationRecord.transaction do + processor = BulkUpload::Processor.new(bulk_upload:) + processor.approve + + bulk_upload.update!(choice: "create-fix-inline") + end true end + + def preflight_valid? + bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" + end + + def preflight_redirect + case bulk_upload.choice + when "create-fix-inline" + page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) + when "bulk-confirm-soft-validations" + page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb index 5513434de..76ee10d17 100644 --- a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb +++ b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb @@ -46,8 +46,23 @@ module Forms end def save! + bulk_upload.update!(choice:) if choice == "upload-again" + true end + + def preflight_valid? + bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" + end + + def preflight_redirect + case bulk_upload.choice + when "create-fix-inline" + page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) + when "bulk-confirm-soft-validations" + page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb b/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb new file mode 100644 index 000000000..b3091bc51 --- /dev/null +++ b/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb @@ -0,0 +1,31 @@ +module Forms + module BulkUploadLettingsSoftValidationsCheck + class Chosen + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_lettings_soft_validations_check/chosen" + end + + def back_path + lettings_logs_path + end + + def next_path + lettings_logs_path + end + + def save! + true + end + + def preflight_valid? + true + end + end + end +end diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb b/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb index b804d7767..aba75791e 100644 --- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb +++ b/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve_and_confirm_soft_validations + ApplicationRecord.transaction do + processor = BulkUpload::Processor.new(bulk_upload:) + processor.approve_and_confirm_soft_validations + + bulk_upload.update!(choice: "bulk-confirm-soft-validations") + end true end + + def preflight_valid? + bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" + end + + def preflight_redirect + case bulk_upload.choice + when "bulk-confirm-soft-validations" + page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) + when "create-fix-inline" + page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb b/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb index cbf486a4d..34b4b97f3 100644 --- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb +++ b/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb @@ -35,6 +35,19 @@ module Forms def save! true end + + def preflight_valid? + bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" + end + + def preflight_redirect + case bulk_upload.choice + when "bulk-confirm-soft-validations" + page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) + when "create-fix-inline" + page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_sales_resume/chosen.rb b/app/models/forms/bulk_upload_sales_resume/chosen.rb new file mode 100644 index 000000000..2fa85c6c9 --- /dev/null +++ b/app/models/forms/bulk_upload_sales_resume/chosen.rb @@ -0,0 +1,31 @@ +module Forms + module BulkUploadSalesResume + class Chosen + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_sales_resume/chosen" + end + + def back_path + sales_logs_path + end + + def next_path + sales_logs_path + end + + def save! + true + end + + def preflight_valid? + true + end + end + end +end diff --git a/app/models/forms/bulk_upload_sales_resume/confirm.rb b/app/models/forms/bulk_upload_sales_resume/confirm.rb index 4ce50fb55..1211ef3f0 100644 --- a/app/models/forms/bulk_upload_sales_resume/confirm.rb +++ b/app/models/forms/bulk_upload_sales_resume/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve + ApplicationRecord.transaction do + processor = BulkUpload::Processor.new(bulk_upload:) + processor.approve + + bulk_upload.update!(choice: "create-fix-inline") + end true end + + def preflight_valid? + bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" + end + + def preflight_redirect + case bulk_upload.choice + when "create-fix-inline" + page_bulk_upload_sales_resume_path(bulk_upload, :chosen) + when "bulk-confirm-soft-validations" + page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb b/app/models/forms/bulk_upload_sales_resume/fix_choice.rb index 671891429..fc565e2f6 100644 --- a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb +++ b/app/models/forms/bulk_upload_sales_resume/fix_choice.rb @@ -46,8 +46,23 @@ module Forms end def save! + bulk_upload.update!(choice:) if choice == "upload-again" + true end + + def preflight_valid? + bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" + end + + def preflight_redirect + case bulk_upload.choice + when "create-fix-inline" + page_bulk_upload_sales_resume_path(bulk_upload, :chosen) + when "bulk-confirm-soft-validations" + page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb new file mode 100644 index 000000000..2286d3b39 --- /dev/null +++ b/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb @@ -0,0 +1,31 @@ +module Forms + module BulkUploadSalesSoftValidationsCheck + class Chosen + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_sales_soft_validations_check/chosen" + end + + def back_path + sales_logs_path + end + + def next_path + sales_logs_path + end + + def save! + true + end + + def preflight_valid? + true + end + end + end +end diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb index 579af7e84..894f55123 100644 --- a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb +++ b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve_and_confirm_soft_validations + ApplicationRecord.transaction do + processor = BulkUpload::Processor.new(bulk_upload:) + processor.approve_and_confirm_soft_validations + + bulk_upload.update!(choice: "bulk-confirm-soft-validations") + end true end + + def preflight_valid? + bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" + end + + def preflight_redirect + case bulk_upload.choice + when "bulk-confirm-soft-validations" + page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + when "create-fix-inline" + page_bulk_upload_sales_resume_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb index e6fe00495..041647cf0 100644 --- a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb +++ b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb @@ -35,6 +35,19 @@ module Forms def save! true end + + def preflight_valid? + bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" + end + + def preflight_redirect + case bulk_upload.choice + when "bulk-confirm-soft-validations" + page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + when "create-fix-inline" + page_bulk_upload_sales_resume_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/views/bulk_upload_lettings_resume/chosen.html.erb b/app/views/bulk_upload_lettings_resume/chosen.html.erb new file mode 100644 index 000000000..47ed9bbfd --- /dev/null +++ b/app/views/bulk_upload_lettings_resume/chosen.html.erb @@ -0,0 +1,14 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: @form.back_path %> +<% end %> + +
You have chosen to create logs from your recent bulk upload. To view and complete these logs, return to the list of lettings logs.
+ + <%= govuk_button_link_to "Return to lettings logs", lettings_logs_path %> +You have created logs from your bulk upload. Return to lettings logs to view them.
+ + <%= govuk_button_link_to "Return to lettings logs", lettings_logs_path %> +You have chosen to create logs from your recent bulk upload. To view and complete these logs, return to the list of sales logs.
+ + <%= govuk_button_link_to "Return to sales logs", sales_logs_path %> +You have created logs from your bulk upload. Return to sales logs to view them.
+ + <%= govuk_button_link_to "Return to sales logs", sales_logs_path %> +