From b6c3a1be64026bee55beb1ec0df48f2c6c68730a Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:32:01 +0100 Subject: [PATCH] Add bulk upload button and add org id to upload your file --- .../bulk_upload_lettings_logs_controller.rb | 2 +- app/controllers/bulk_upload_sales_logs_controller.rb | 2 +- .../forms/bulk_upload_lettings/upload_your_file.rb | 10 ++++++++-- app/models/forms/bulk_upload_sales/upload_your_file.rb | 8 +++++++- app/views/logs/_create_for_org_actions.html.erb | 10 ++++++---- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/controllers/bulk_upload_lettings_logs_controller.rb b/app/controllers/bulk_upload_lettings_logs_controller.rb index 465bbc5f6..c02202e42 100644 --- a/app/controllers/bulk_upload_lettings_logs_controller.rb +++ b/app/controllers/bulk_upload_lettings_logs_controller.rb @@ -51,7 +51,7 @@ private when "needstype" Forms::BulkUploadLettings::Needstype.new(form_params) when "upload-your-file" - Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:)) + Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:, organisation_id: params[:org])) when "checking-file" Forms::BulkUploadLettings::CheckingFile.new(form_params) else diff --git a/app/controllers/bulk_upload_sales_logs_controller.rb b/app/controllers/bulk_upload_sales_logs_controller.rb index 56bd1d4de..ce4cd9c2a 100644 --- a/app/controllers/bulk_upload_sales_logs_controller.rb +++ b/app/controllers/bulk_upload_sales_logs_controller.rb @@ -49,7 +49,7 @@ private when "guidance" Forms::BulkUploadSales::Guidance.new(form_params.merge(referrer: params[:referrer])) when "upload-your-file" - Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:)) + Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:, organisation_id: params[:org])) when "checking-file" Forms::BulkUploadSales::CheckingFile.new(form_params) else diff --git a/app/models/forms/bulk_upload_lettings/upload_your_file.rb b/app/models/forms/bulk_upload_lettings/upload_your_file.rb index 9ccec7622..16fff950f 100644 --- a/app/models/forms/bulk_upload_lettings/upload_your_file.rb +++ b/app/models/forms/bulk_upload_lettings/upload_your_file.rb @@ -11,6 +11,7 @@ module Forms attribute :needstype, :integer attribute :file attribute :current_user + attribute :organisation_id validates :file, presence: true validate :validate_file_is_csv @@ -20,8 +21,12 @@ module Forms end def back_path - page_id = year == 2022 ? "needstype" : "prepare-your-file" - bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: }) + if organisation_id.present? + lettings_logs_organisation_path(organisation_id) + else + page_id = year == 2022 ? "needstype" : "prepare-your-file" + bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: }) + end end def year_combo @@ -39,6 +44,7 @@ module Forms year:, needstype:, filename: file.original_filename, + organisation_id: organisation_id || current_user.organisation_id, ) storage_service.write_file(bulk_upload.identifier, File.read(file.path)) diff --git a/app/models/forms/bulk_upload_sales/upload_your_file.rb b/app/models/forms/bulk_upload_sales/upload_your_file.rb index de650c831..cd25baea1 100644 --- a/app/models/forms/bulk_upload_sales/upload_your_file.rb +++ b/app/models/forms/bulk_upload_sales/upload_your_file.rb @@ -10,6 +10,7 @@ module Forms attribute :year, :integer attribute :file attribute :current_user + attribute :organisation_id validates :file, presence: true validate :validate_file_is_csv @@ -19,7 +20,11 @@ module Forms end def back_path - bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) + if organisation_id.present? + sales_logs_organisation_path(organisation_id) + else + bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) + end end def year_combo @@ -36,6 +41,7 @@ module Forms log_type: BulkUpload.log_types[:sales], year:, filename: file.original_filename, + organisation_id: organisation_id || current_user.organisation_id, ) storage_service.write_file(bulk_upload.identifier, File.read(file.path)) diff --git a/app/views/logs/_create_for_org_actions.html.erb b/app/views/logs/_create_for_org_actions.html.erb index f6ed9ad82..fe5d1d0ef 100644 --- a/app/views/logs/_create_for_org_actions.html.erb +++ b/app/views/logs/_create_for_org_actions.html.erb @@ -1,10 +1,12 @@
<% if @organisation.data_protection_confirmed? %> <% if current_page?(controller: 'organisations', action: 'lettings_logs') %> - <%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %> - <% end %> + <%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %> + <%= govuk_button_link_to "Upload lettings logs in bulk", bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, org: @organisation.id), secondary: true %> +<% end %> <% if current_page?(controller: 'organisations', action: 'sales_logs') %> - <%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %> - <% end %> + <%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %> + <%= govuk_button_link_to "Upload sales logs in bulk", bulk_upload_sales_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, org: @organisation.id), secondary: true %> +<% end %> <% end %>