Browse Source

CLDC 3623 Support user bulk uploading (#2629)

pull/2642/head^2 v0.4.74
Manny Dinssa 4 months ago committed by GitHub
parent
commit
d0ce0b87f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/components/create_log_actions_component.html.erb
  2. 6
      app/controllers/bulk_upload_lettings_logs_controller.rb
  3. 6
      app/controllers/bulk_upload_sales_logs_controller.rb
  4. 7
      app/models/forms/bulk_upload_lettings/checking_file.rb
  5. 3
      app/models/forms/bulk_upload_lettings/guidance.rb
  6. 5
      app/models/forms/bulk_upload_lettings/needstype.rb
  7. 8
      app/models/forms/bulk_upload_lettings/prepare_your_file.rb
  8. 7
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  9. 9
      app/models/forms/bulk_upload_lettings/year.rb
  10. 7
      app/models/forms/bulk_upload_sales/checking_file.rb
  11. 3
      app/models/forms/bulk_upload_sales/guidance.rb
  12. 7
      app/models/forms/bulk_upload_sales/prepare_your_file.rb
  13. 6
      app/models/forms/bulk_upload_sales/upload_your_file.rb
  14. 9
      app/models/forms/bulk_upload_sales/year.rb
  15. 28
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  16. 28
      app/services/bulk_upload/sales/year2024/row_parser.rb
  17. 1
      app/views/bulk_upload_lettings_logs/forms/checking_file.html.erb
  18. 1
      app/views/bulk_upload_lettings_logs/forms/needstype.erb
  19. 1
      app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb
  20. 1
      app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb
  21. 1
      app/views/bulk_upload_lettings_logs/forms/year.html.erb
  22. 2
      app/views/bulk_upload_lettings_results/show.html.erb
  23. 2
      app/views/bulk_upload_lettings_results/summary.html.erb
  24. 1
      app/views/bulk_upload_sales_logs/forms/checking_file.html.erb
  25. 1
      app/views/bulk_upload_sales_logs/forms/prepare_your_file_2024.html.erb
  26. 1
      app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb
  27. 1
      app/views/bulk_upload_sales_logs/forms/year.html.erb
  28. 2
      app/views/bulk_upload_sales_results/show.html.erb
  29. 2
      app/views/bulk_upload_sales_results/summary.html.erb
  30. 10
      app/views/logs/_create_for_org_actions.html.erb
  31. 5
      db/migrate/20240905092332_add_organisation_id_to_bulk_uploads.rb
  32. 1
      db/schema.rb
  33. 1
      spec/factories/bulk_upload.rb
  34. 8
      spec/features/organisation_spec.rb
  35. 54
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
  36. 54
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

2
app/components/create_log_actions_component.html.erb

@ -3,7 +3,7 @@
<% if create_button_href.present? %>
<%= govuk_button_to create_button_copy, create_button_href, class: "govuk-!-margin-right-6" %>
<% end %>
<% if upload_button_href.present? %>
<% if upload_button_href.present? && !user.support? %>
<%= govuk_button_link_to upload_button_copy, upload_button_href, secondary: true %>
<% end %>
</div>

6
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -4,9 +4,9 @@ class BulkUploadLettingsLogsController < ApplicationController
def start
if have_choice_of_year?
redirect_to bulk_upload_lettings_log_path(id: "year")
redirect_to bulk_upload_lettings_log_path(id: "year", form: { organisation_id: params[:organisation_id] }.compact)
else
redirect_to bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: current_year })
redirect_to bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: current_year, organisation_id: params[:organisation_id] }.compact)
end
end
@ -60,6 +60,6 @@ private
end
def form_params
params.fetch(:form, {}).permit(:year, :needstype, :file)
params.fetch(:form, {}).permit(:year, :needstype, :file, :organisation_id)
end
end

6
app/controllers/bulk_upload_sales_logs_controller.rb

@ -4,9 +4,9 @@ class BulkUploadSalesLogsController < ApplicationController
def start
if have_choice_of_year?
redirect_to bulk_upload_sales_log_path(id: "year")
redirect_to bulk_upload_sales_log_path(id: "year", form: { organisation_id: params[:organisation_id] }.compact)
else
redirect_to bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: current_year })
redirect_to bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: current_year, organisation_id: params[:organisation_id] }.compact)
end
end
@ -58,6 +58,6 @@ private
end
def form_params
params.fetch(:form, {}).permit(:year, :file)
params.fetch(:form, {}).permit(:year, :file, :organisation_id)
end
end

7
app/models/forms/bulk_upload_lettings/checking_file.rb

@ -6,13 +6,18 @@ module Forms
include Rails.application.routes.url_helpers
attribute :year, :integer
attribute :organisation_id, :integer
def view_path
"bulk_upload_lettings_logs/forms/checking_file"
end
def back_path
bulk_upload_lettings_log_path(id: "start")
if organisation_id.present?
lettings_logs_organisation_path(organisation_id)
else
bulk_upload_lettings_log_path(id: "start")
end
end
def year_combo

3
app/models/forms/bulk_upload_lettings/guidance.rb

@ -7,6 +7,7 @@ module Forms
attribute :year, :integer
attribute :referrer
attribute :organisation_id, :integer
def view_path
"bulk_upload_shared/guidance"
@ -15,7 +16,7 @@ module Forms
def back_path
case referrer
when "prepare-your-file"
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: })
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
when "home"
root_path
else

5
app/models/forms/bulk_upload_lettings/needstype.rb

@ -7,6 +7,7 @@ module Forms
attribute :needstype, :integer
attribute :year, :integer
attribute :organisation_id, :integer
validates :needstype, presence: true
@ -19,11 +20,11 @@ module Forms
end
def back_path
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype: })
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype:, organisation_id: }.compact)
end
def next_path
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype: })
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype:, organisation_id: }.compact)
end
def year_combo

8
app/models/forms/bulk_upload_lettings/prepare_your_file.rb

@ -7,6 +7,7 @@ module Forms
attribute :year, :integer
attribute :needstype, :integer
attribute :organisation_id, :integer
def view_path
case year
@ -19,15 +20,16 @@ module Forms
def back_path
if have_choice_of_year?
Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year: })
Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year:, organisation_id: }.compact)
elsif organisation_id.present?
lettings_logs_organisation_path(organisation_id)
else
Rails.application.routes.url_helpers.lettings_logs_path
end
end
def next_path
page_id = year == 2022 ? "needstype" : "upload-your-file"
bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: })
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype:, organisation_id: }.compact)
end
def legacy_template_path

7
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, :integer
validates :file, presence: true
validate :validate_file_is_csv
@ -20,8 +21,7 @@ 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: })
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype:, organisation_id: }.compact)
end
def year_combo
@ -29,7 +29,7 @@ module Forms
end
def next_path
bulk_upload_lettings_log_path(id: "checking-file", form: { year: })
bulk_upload_lettings_log_path(id: "checking-file", form: { year:, organisation_id: }.compact)
end
def save!
@ -39,6 +39,7 @@ module Forms
year:,
needstype:,
filename: file.original_filename,
organisation_id: (organisation_id if current_user.support?) || current_user.organisation_id,
)
storage_service.write_file(bulk_upload.identifier, File.read(file.path))

9
app/models/forms/bulk_upload_lettings/year.rb

@ -6,6 +6,7 @@ module Forms
include Rails.application.routes.url_helpers
attribute :year, :integer
attribute :organisation_id, :integer
validates :year, presence: true
@ -20,11 +21,15 @@ module Forms
end
def back_path
lettings_logs_path
if organisation_id.present?
lettings_logs_organisation_path(organisation_id)
else
lettings_logs_path
end
end
def next_path
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: })
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
end
def save!

7
app/models/forms/bulk_upload_sales/checking_file.rb

@ -6,13 +6,18 @@ module Forms
include Rails.application.routes.url_helpers
attribute :year, :integer
attribute :organisation_id, :integer
def view_path
"bulk_upload_sales_logs/forms/checking_file"
end
def back_path
bulk_upload_sales_log_path(id: "start")
if organisation_id.present?
sales_logs_organisation_path(organisation_id)
else
bulk_upload_sales_log_path(id: "start")
end
end
def year_combo

3
app/models/forms/bulk_upload_sales/guidance.rb

@ -7,6 +7,7 @@ module Forms
attribute :year, :integer
attribute :referrer
attribute :organisation_id, :integer
def view_path
"bulk_upload_shared/guidance"
@ -15,7 +16,7 @@ module Forms
def back_path
case referrer
when "prepare-your-file"
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
when "home"
root_path
else

7
app/models/forms/bulk_upload_sales/prepare_your_file.rb

@ -6,6 +6,7 @@ module Forms
include Rails.application.routes.url_helpers
attribute :year, :integer
attribute :organisation_id, :integer
def view_path
case year
@ -18,14 +19,16 @@ module Forms
def back_path
if have_choice_of_year?
Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: })
Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: }.compact)
elsif organisation_id.present?
sales_logs_organisation_path(organisation_id)
else
Rails.application.routes.url_helpers.sales_logs_path
end
end
def next_path
bulk_upload_sales_log_path(id: "upload-your-file", form: { year: })
bulk_upload_sales_log_path(id: "upload-your-file", form: { year:, organisation_id: }.compact)
end
def legacy_template_path

6
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, :integer
validates :file, presence: true
validate :validate_file_is_csv
@ -19,7 +20,7 @@ module Forms
end
def back_path
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
end
def year_combo
@ -27,7 +28,7 @@ module Forms
end
def next_path
bulk_upload_sales_log_path(id: "checking-file", form: { year: })
bulk_upload_sales_log_path(id: "checking-file", form: { year:, organisation_id: }.compact)
end
def save!
@ -36,6 +37,7 @@ module Forms
log_type: BulkUpload.log_types[:sales],
year:,
filename: file.original_filename,
organisation_id: (organisation_id if current_user.support?) || current_user.organisation_id,
)
storage_service.write_file(bulk_upload.identifier, File.read(file.path))

9
app/models/forms/bulk_upload_sales/year.rb

@ -6,6 +6,7 @@ module Forms
include Rails.application.routes.url_helpers
attribute :year, :integer
attribute :organisation_id, :integer
validates :year, presence: true
@ -20,11 +21,15 @@ module Forms
end
def back_path
sales_logs_path
if organisation_id.present?
sales_logs_organisation_path(organisation_id)
else
sales_logs_path
end
end
def next_path
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
end
def save!

28
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -432,6 +432,7 @@ class BulkUpload::Lettings::Year2024::RowParser
validate :validate_assigned_to_exists, on: :after_log
validate :validate_assigned_to_related, on: :after_log
validate :validate_assigned_to_when_support, on: :after_log
validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
validate :validate_address_option_found, on: :after_log, unless: -> { supported_housing? }
@ -582,6 +583,12 @@ private
end
end
def validate_assigned_to_when_support
if field_3.blank? && bulk_upload.user.support?
errors.add(:field_3, category: :setup, message: I18n.t("validations.not_answered", question: "what is the CORE username of the account this letting log should be assigned to?"))
end
end
def validate_assigned_to_related
return unless assigned_to
return if assigned_to.organisation == owning_organisation || assigned_to.organisation == managing_organisation
@ -891,12 +898,17 @@ private
end
def validate_owning_org_permitted
if owning_organisation && !bulk_upload.user.organisation.affiliated_stock_owners.include?(owning_organisation)
block_log_creation!
return unless owning_organisation
return if bulk_upload_organisation.affiliated_stock_owners.include?(owning_organisation)
if errors[:field_1].blank?
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
block_log_creation!
return if errors[:field_1].present?
if bulk_upload.user.support?
errors.add(:field_1, "This owning organisation is not affiliated with #{bulk_upload_organisation.name}", category: :setup)
else
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
end
@ -1137,7 +1149,7 @@ private
attributes["renewal"] = renewal
attributes["scheme"] = scheme
attributes["location"] = location
attributes["assigned_to"] = assigned_to || bulk_upload.user
attributes["assigned_to"] = assigned_to || (bulk_upload.user.support? ? nil : bulk_upload.user)
attributes["created_by"] = bulk_upload.user
attributes["needstype"] = field_4
attributes["rent_type"] = RENT_TYPE_BU_MAPPING[field_11]
@ -1625,4 +1637,8 @@ private
def reason_is_other?
field_98 == 20
end
def bulk_upload_organisation
Organisation.find(bulk_upload.organisation_id)
end
end

28
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -462,6 +462,7 @@ class BulkUpload::Sales::Year2024::RowParser
validate :validate_assigned_to_exists, on: :after_log
validate :validate_assigned_to_related, on: :after_log
validate :validate_assigned_to_when_support, on: :after_log
validate :validate_managing_org_related, on: :after_log
validate :validate_relevant_collection_window, on: :after_log
validate :validate_incomplete_soft_validations, on: :after_log
@ -925,7 +926,7 @@ private
attributes["owning_organisation"] = owning_organisation
attributes["managing_organisation"] = managing_organisation
attributes["assigned_to"] = assigned_to || bulk_upload.user
attributes["assigned_to"] = assigned_to || (bulk_upload.user.support? ? nil : bulk_upload.user)
attributes["created_by"] = bulk_upload.user
attributes["hhregres"] = field_72
attributes["hhregresstill"] = field_73
@ -1302,12 +1303,17 @@ private
end
def validate_owning_org_permitted
if owning_organisation && !bulk_upload.user.organisation.affiliated_stock_owners.include?(owning_organisation)
block_log_creation!
return unless owning_organisation
return if bulk_upload_organisation.affiliated_stock_owners.include?(owning_organisation)
if errors[:field_1].blank?
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
block_log_creation!
return if errors[:field_1].present?
if bulk_upload.user.support?
errors.add(:field_1, "This owning organisation is not affiliated with #{bulk_upload_organisation.name}", category: :setup)
else
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
end
@ -1319,6 +1325,12 @@ private
end
end
def validate_assigned_to_when_support
if field_3.blank? && bulk_upload.user.support?
errors.add(:field_3, category: :setup, message: I18n.t("validations.not_answered", question: "what is the CORE username of the account this sales log should be assigned to?"))
end
end
def validate_assigned_to_related
return unless assigned_to
return if assigned_to.organisation == owning_organisation || assigned_to.organisation == managing_organisation
@ -1492,4 +1504,8 @@ private
def valid_nationality_options
%w[0] + GlobalConstants::COUNTRIES_ANSWER_OPTIONS.keys # 0 is "Prefers not to say"
end
def bulk_upload_organisation
Organisation.find(bulk_upload.organisation_id)
end
end

1
app/views/bulk_upload_lettings_logs/forms/checking_file.html.erb

@ -6,6 +6,7 @@
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "prepare-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<%= f.hidden_field :organisation_id %>
<span class="govuk-caption-l">Upload lettings logs in bulk (<%= @form.year_combo %>)</span>
<h1 class="govuk-heading-l">We’re checking the file</h1>

1
app/views/bulk_upload_lettings_logs/forms/needstype.erb

@ -7,6 +7,7 @@
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "needstype"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= f.hidden_field :year %>
<%= f.hidden_field :organisation_id %>
<%= f.govuk_collection_radio_buttons :needstype,
@form.options,

1
app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb

@ -6,6 +6,7 @@
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "prepare-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<%= f.hidden_field :organisation_id %>
<span class="govuk-caption-l">Upload lettings logs in bulk (<%= @form.year_combo %>)</span>
<h1 class="govuk-heading-l">Prepare your file</h1>

1
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 %>
<%= f.govuk_error_summary %>

1
app/views/bulk_upload_lettings_logs/forms/year.html.erb

@ -4,6 +4,7 @@
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "year"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= f.hidden_field :organisation_id %>
<%= f.govuk_collection_radio_buttons :year,
@form.options,

2
app/views/bulk_upload_lettings_results/show.html.erb

@ -25,4 +25,4 @@
</div>
</div>
<%= 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) %>

2
app/views/bulk_upload_lettings_results/summary.html.erb

@ -29,4 +29,4 @@
<% end %>
</div>
<%= 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) %>

1
app/views/bulk_upload_sales_logs/forms/checking_file.html.erb

@ -6,6 +6,7 @@
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "prepare-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<%= f.hidden_field :organisation_id %><%= f.hidden_field :organisation_id %>
<span class="govuk-caption-l">Upload sales logs in bulk (<%= @form.year_combo %>)</span>
<h1 class="govuk-heading-l">We’re checking the file</h1>

1
app/views/bulk_upload_sales_logs/forms/prepare_your_file_2024.html.erb

@ -6,6 +6,7 @@
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "prepare-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<%= f.hidden_field :organisation_id %>
<span class="govuk-caption-l">Upload sales logs in bulk (<%= @form.year_combo %>)</span>
<h1 class="govuk-heading-l">Prepare your file</h1>

1
app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb

@ -6,6 +6,7 @@
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "upload-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<%= f.hidden_field :organisation_id %>
<%= f.govuk_error_summary %>

1
app/views/bulk_upload_sales_logs/forms/year.html.erb

@ -4,6 +4,7 @@
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "year"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= f.hidden_field :organisation_id %>
<%= f.govuk_collection_radio_buttons :year,
@form.options,

2
app/views/bulk_upload_sales_results/show.html.erb

@ -25,4 +25,4 @@
</div>
</div>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path %>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path(organisation_id: @bulk_upload.organisation_id) %>

2
app/views/bulk_upload_sales_results/summary.html.erb

@ -29,4 +29,4 @@
<% end %>
</div>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path %>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path(organisation_id: @bulk_upload.organisation_id) %>

10
app/views/logs/_create_for_org_actions.html.erb

@ -1,10 +1,12 @@
<div class="govuk-button-group app-filter-toggle">
<% 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: "start", organisation_id: @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: "start", organisation_id: @organisation.id), secondary: true %>
<% end %>
<% end %>
</div>

5
db/migrate/20240905092332_add_organisation_id_to_bulk_uploads.rb

@ -0,0 +1,5 @@
class AddOrganisationIdToBulkUploads < ActiveRecord::Migration[7.0]
def change
add_column :bulk_uploads, :organisation_id, :integer
end
end

1
db/schema.rb

@ -42,6 +42,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_09_23_145326) do
t.text "choice"
t.integer "total_logs_count"
t.string "rent_type_fix_status", default: "not_applied"
t.integer "organisation_id"
t.integer "moved_user_id"
t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true
t.index ["user_id"], name: "index_bulk_uploads_on_user_id"

1
spec/factories/bulk_upload.rb

@ -9,6 +9,7 @@ FactoryBot.define do
sequence(:filename) { |n| "bulk-upload-#{n}.csv" }
needstype { 1 }
rent_type_fix_status { BulkUpload.rent_type_fix_statuses.values.sample }
organisation_id { user.organisation_id }
trait(:sales) do
log_type { BulkUpload.log_types[:sales] }

8
spec/features/organisation_spec.rb

@ -139,6 +139,10 @@ RSpec.describe "User Features" do
expect(page).to have_button("Create a new lettings log for this organisation")
end
it "shows a upload lettings logs in bulk link" do
expect(page).to have_link("Upload lettings logs in bulk")
end
context "when creating a log for that organisation" do
it "pre-fills the value for owning organisation for that log" do
click_button("Create a new lettings log for this organisation")
@ -230,6 +234,10 @@ RSpec.describe "User Features" do
expect(page).to have_button("Create a new sales log for this organisation")
end
it "shows a upload sales logs in bulk link" do
expect(page).to have_link("Upload sales logs in bulk")
end
context "when creating a log for that organisation" do
it "pre-fills the value for owning organisation for that log" do
click_button("Create a new sales log for this organisation")

54
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -815,6 +815,23 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end
end
context "when blank and bulk upload user is support" do
let(:bulk_upload) { create(:bulk_upload, :sales, user: create(:user, :support), year: 2024) }
let(:attributes) { setup_section_params.merge(bulk_upload:, field_3: nil) }
it "is not permitted" do
parser.valid?
expect(parser.errors[:field_3]).to be_present
expect(parser.errors[:field_3]).to include("You must answer what is the CORE username of the account this letting log should be assigned to?")
end
it "blocks log creation" do
parser.valid?
expect(parser).to be_block_log_creation
end
end
context "when user could not be found" do
let(:attributes) { { bulk_upload:, field_3: "idonotexist@example.com" } }
@ -1439,6 +1456,43 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.errors[:field_10]).to include(/Enter a date when the owning and managing organisation was active/)
end
end
context "when user is an unaffiliated non-support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_user) { create(:user, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
let(:organisation_id) { unaffiliated_user.organisation_id }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id:, user: unaffiliated_user)
end
it "blocks log creation and adds an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser).to be_block_log_creation
expect(parser.errors[:field_1]).to include("You do not have permission to add logs for this owning organisation")
end
end
context "when user is an unaffiliated support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_support_user) { create(:user, :support, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
let(:organisation_id) { affiliated_org.id }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id:, user: unaffiliated_support_user)
end
it "does not block log creation and does not add an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors[:field_1]).not_to include("You do not have permission to add logs for this owning organisation")
end
end
end
describe "#field_2" do # managing org

54
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -554,6 +554,43 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
expect(parser.errors[:field_6]).to include(/Enter a date when the owning organisation was active/)
end
end
context "when user is an unaffiliated non-support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_user) { create(:user, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
let(:organisation_id) { unaffiliated_user.organisation_id }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id:, user: unaffiliated_user)
end
it "blocks log creation and adds an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser).to be_block_log_creation
expect(parser.errors[:field_1]).to include("You do not have permission to add logs for this owning organisation")
end
end
context "when user is an unaffiliated support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_support_user) { create(:user, :support, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
let(:organisation_id) { affiliated_org.id }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id:, user: unaffiliated_support_user)
end
it "does not block log creation and does not add an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors[:field_1]).not_to include("You do not have permission to add logs for this owning organisation")
end
end
end
describe "#field_3" do # username for assigned_to
@ -576,6 +613,23 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end
end
context "when blank and bulk upload user is support" do
let(:bulk_upload) { create(:bulk_upload, :sales, user: create(:user, :support), year: 2024) }
let(:attributes) { setup_section_params.merge(bulk_upload:, field_3: nil) }
it "is not permitted" do
parser.valid?
expect(parser.errors[:field_3]).to be_present
expect(parser.errors[:field_3]).to include("You must answer what is the CORE username of the account this sales log should be assigned to?")
end
it "blocks log creation" do
parser.valid?
expect(parser).to be_block_log_creation
end
end
context "when user could not be found" do
let(:attributes) { { bulk_upload:, field_3: "idonotexist@example.com" } }

Loading…
Cancel
Save