diff --git a/app/controllers/bulk_upload_lettings_logs_controller.rb b/app/controllers/bulk_upload_lettings_logs_controller.rb index c02202e42..93c5541f4 100644 --- a/app/controllers/bulk_upload_lettings_logs_controller.rb +++ b/app/controllers/bulk_upload_lettings_logs_controller.rb @@ -3,6 +3,8 @@ class BulkUploadLettingsLogsController < ApplicationController before_action :validate_data_protection_agrement_signed! def start + support_user_redirection and return if current_user.support? + if have_choice_of_year? redirect_to bulk_upload_lettings_log_path(id: "year") else @@ -51,7 +53,7 @@ private when "needstype" Forms::BulkUploadLettings::Needstype.new(form_params) when "upload-your-file" - Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:, organisation_id: params[:org])) + Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:, request:)) when "checking-file" Forms::BulkUploadLettings::CheckingFile.new(form_params) else @@ -60,6 +62,12 @@ private end def form_params - params.fetch(:form, {}).permit(:year, :needstype, :file) + params.fetch(:form, {}).permit(:year, :needstype, :file, :organisation_id) + end + + def support_user_redirection + if params[:organisation_id].present? + redirect_to bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: current_year }, organisation_id: params[:organisation_id]) + end end end diff --git a/app/controllers/bulk_upload_sales_logs_controller.rb b/app/controllers/bulk_upload_sales_logs_controller.rb index ce4cd9c2a..1efa22499 100644 --- a/app/controllers/bulk_upload_sales_logs_controller.rb +++ b/app/controllers/bulk_upload_sales_logs_controller.rb @@ -3,6 +3,8 @@ class BulkUploadSalesLogsController < ApplicationController before_action :validate_data_protection_agrement_signed! def start + support_user_redirection and return if current_user.support? + if have_choice_of_year? redirect_to bulk_upload_sales_log_path(id: "year") else @@ -49,7 +51,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:, organisation_id: params[:org])) + Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:, request:)) when "checking-file" Forms::BulkUploadSales::CheckingFile.new(form_params) else @@ -58,6 +60,12 @@ private end def form_params - params.fetch(:form, {}).permit(:year, :file) + params.fetch(:form, {}).permit(:year, :file, :organisation_id) + end + + def support_user_redirection + if params[:organisation_id].present? + redirect_to bulk_upload_sales_log_path(id: "upload-your-file", form: { year: current_year }, organisation_id: params[:organisation_id]) + end end end diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index e193c0909..7af43ee28 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -3,7 +3,6 @@ class BulkUpload < ApplicationRecord enum rent_type_fix_status: { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" } belongs_to :user - belongs_to :organisation, optional: true has_many :bulk_upload_errors, dependent: :destroy 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 16fff950f..f501da811 100644 --- a/app/models/forms/bulk_upload_lettings/upload_your_file.rb +++ b/app/models/forms/bulk_upload_lettings/upload_your_file.rb @@ -11,7 +11,8 @@ module Forms attribute :needstype, :integer attribute :file attribute :current_user - attribute :organisation_id + attribute :organisation_id, :integer + attr_accessor :request validates :file, presence: true validate :validate_file_is_csv @@ -21,6 +22,7 @@ module Forms end def back_path + organisation_id = request.query_parameters[:organisation_id] if organisation_id.present? lettings_logs_organisation_path(organisation_id) else 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 cd25baea1..83cc12def 100644 --- a/app/models/forms/bulk_upload_sales/upload_your_file.rb +++ b/app/models/forms/bulk_upload_sales/upload_your_file.rb @@ -10,7 +10,8 @@ module Forms attribute :year, :integer attribute :file attribute :current_user - attribute :organisation_id + attribute :organisation_id, :integer + attr_accessor :request validates :file, presence: true validate :validate_file_is_csv @@ -20,6 +21,7 @@ module Forms end def back_path + organisation_id = request.query_parameters[:organisation_id] if organisation_id.present? sales_logs_organisation_path(organisation_id) else diff --git a/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb b/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb index bbafc28b3..3218be947 100644 --- a/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb +++ b/app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb @@ -7,6 +7,7 @@ <%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "upload-your-file"), method: :patch do |f| %> <%= f.hidden_field :year %> <%= f.hidden_field :needstype %> + <%= f.hidden_field :organisation_id, value: params[:organisation_id]%> <%= f.govuk_error_summary %> diff --git a/app/views/bulk_upload_lettings_results/show.html.erb b/app/views/bulk_upload_lettings_results/show.html.erb index 56448f24e..a39851850 100644 --- a/app/views/bulk_upload_lettings_results/show.html.erb +++ b/app/views/bulk_upload_lettings_results/show.html.erb @@ -23,4 +23,4 @@ -<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path %> +<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path(organisation_id: @bulk_upload.organisation_id) %> diff --git a/app/views/bulk_upload_lettings_results/summary.html.erb b/app/views/bulk_upload_lettings_results/summary.html.erb index 8c36af632..8056e73d6 100644 --- a/app/views/bulk_upload_lettings_results/summary.html.erb +++ b/app/views/bulk_upload_lettings_results/summary.html.erb @@ -27,4 +27,4 @@ <% end %> -<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path %> +<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path(organisation_id: @bulk_upload.organisation_id) %> diff --git a/app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb b/app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb index 36e7240dc..1bc615439 100644 --- a/app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb +++ b/app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb @@ -6,6 +6,7 @@