Browse Source

CLDC-3523 Only count visible logs on CSV downloads page (#2477)

* Only count visible logs

* Refactor

* Update csv count for sales
pull/2491/head
kosiakkatrina 7 months ago committed by GitHub
parent
commit
9dc4f0bbb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/controllers/lettings_logs_controller.rb
  2. 2
      app/controllers/sales_logs_controller.rb
  3. 24
      spec/requests/lettings_logs_controller_spec.rb
  4. 24
      spec/requests/sales_logs_controller_spec.rb

2
app/controllers/lettings_logs_controller.rb

@ -90,7 +90,7 @@ class LettingsLogsController < LogsController
def download_csv
redirect_to filters_years_lettings_logs_path(search: search_term, codes_only: codes_only_export?) and return if session_filters["years"].blank? || session_filters["years"].count != 1
unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.lettings_logs, search_term, session_filters)
unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.lettings_logs.visible, search_term, session_filters)
render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_lettings_logs_path, codes_only: codes_only_export?, session_filters:, filter_type: "lettings_logs", download_csv_back_link: lettings_logs_path }
end

2
app/controllers/sales_logs_controller.rb

@ -64,7 +64,7 @@ class SalesLogsController < LogsController
def download_csv
redirect_to filters_years_sales_logs_path(search: search_term, codes_only: codes_only_export?) and return if session_filters["years"].blank? || session_filters["years"].count != 1
unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.sales_logs, search_term, session_filters)
unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.sales_logs.visible, search_term, session_filters)
render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_sales_logs_path, codes_only: codes_only_export?, session_filters:, filter_type: "sales_logs", download_csv_back_link: sales_logs_path }
end

24
spec/requests/lettings_logs_controller_spec.rb

@ -1865,6 +1865,30 @@ RSpec.describe LettingsLogsController, type: :request do
get "/lettings-logs/csv-download?codes_only=#{codes_only}", headers:, params: {}
expect(response).to have_http_status(:unauthorized)
end
context "when filtering by organisation and year" do
let(:other_organisation) { FactoryBot.create(:organisation) }
let(:lettings_logs) { create_list(:lettings_log, 2, :setup_completed, assigned_to: user, owning_organisation: other_organisation, managing_organisation: user.organisation) }
let(:params) do
{
years: [lettings_logs[0].form.start_date.year],
owning_organisation: other_organisation.id,
owning_organisation_select: "specific_org",
codes_only: false,
}
end
before do
create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: user.organisation)
create_list(:lettings_log, 2, :setup_completed, assigned_to: user, owning_organisation: other_organisation, managing_organisation: user.organisation, discarded_at: Time.zone.yesterday)
end
it "does not count deleted logs" do
get csv_download_lettings_logs_path, headers:, params: params
expect(page).to have_content("You've selected 2 logs.")
end
end
end
context "when the user is a data provider" do

24
spec/requests/sales_logs_controller_spec.rb

@ -1042,6 +1042,30 @@ RSpec.describe SalesLogsController, type: :request do
expect(response).to have_http_status(:unauthorized)
end
end
context "and filtering by organisation and year" do
let(:other_organisation) { FactoryBot.create(:organisation) }
let(:sales_logs) { create_list(:sales_log, 2, :in_progress, assigned_to: user, owning_organisation: other_organisation, managing_organisation: user.organisation) }
let(:params) do
{
years: [sales_logs[0].form.start_date.year],
owning_organisation: other_organisation.id,
owning_organisation_select: "specific_org",
codes_only: false,
}
end
before do
create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: user.organisation)
create_list(:sales_log, 2, :in_progress, assigned_to: user, owning_organisation: other_organisation, managing_organisation: user.organisation, discarded_at: Time.zone.yesterday)
end
it "does not count deleted logs" do
get csv_download_sales_logs_path, headers:, params: params
expect(page).to have_content("You've selected 2 logs.")
end
end
end
context "when user is support" do

Loading…
Cancel
Save