From 597381f2877a38f0c01de9097877db3db300dafd Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 22 Aug 2022 10:23:33 +0100 Subject: [PATCH] Add BOMs before CSV info --- app/controllers/case_logs_controller.rb | 3 ++- app/controllers/organisations_controller.rb | 6 ++++-- app/controllers/users_controller.rb | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 740dd2003..60ef7af3b 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -13,6 +13,7 @@ class CaseLogsController < ApplicationController all_logs = current_user.case_logs unpaginated_filtered_logs = filtered_case_logs(filtered_collection(all_logs, search_term)) + byte_order_mark = "\uFEFF" respond_to do |format| format.html do @@ -22,7 +23,7 @@ class CaseLogsController < ApplicationController end format.csv do - send_data unpaginated_filtered_logs.to_csv, filename: "logs-#{Time.zone.now}.csv" + send_data byte_order_mark + unpaginated_filtered_logs.to_csv, filename: "logs-#{Time.zone.now}.csv" end end end diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index cb600b004..c12c1856b 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -31,6 +31,7 @@ class OrganisationsController < ApplicationController def users organisation_users = @organisation.users.sorted_by_organisation_and_role unpaginated_filtered_users = filtered_collection(organisation_users, search_term) + byte_order_mark = "\uFEFF" respond_to do |format| format.html do @@ -45,7 +46,7 @@ class OrganisationsController < ApplicationController end end format.csv do - send_data unpaginated_filtered_users.to_csv, filename: "users-#{@organisation.name}-#{Time.zone.now}.csv" + send_data byte_order_mark + unpaginated_filtered_users.to_csv, filename: "users-#{@organisation.name}-#{Time.zone.now}.csv" end end end @@ -93,6 +94,7 @@ class OrganisationsController < ApplicationController organisation_logs = CaseLog.all.where(owning_organisation_id: @organisation.id) unpaginated_filtered_logs = filtered_case_logs(filtered_collection(organisation_logs, search_term)) + byte_order_mark = "\uFEFF" respond_to do |format| format.html do @@ -103,7 +105,7 @@ class OrganisationsController < ApplicationController end format.csv do - send_data unpaginated_filtered_logs.to_csv, filename: "logs-#{@organisation.name}-#{Time.zone.now}.csv" + send_data byte_order_mark + unpaginated_filtered_logs.to_csv, filename: "logs-#{@organisation.name}-#{Time.zone.now}.csv" end end else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cd82742b6..b06b13feb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -12,6 +12,8 @@ class UsersController < ApplicationController all_users = User.sorted_by_organisation_and_role filtered_users = filtered_users(all_users, search_term) + byte_order_mark = "\uFEFF" + @pagy, @users = pagy(filtered_users) @searched = search_term.presence @total_count = all_users.size @@ -20,7 +22,7 @@ class UsersController < ApplicationController format.html format.csv do if current_user.support? - send_data filtered_users.to_csv, filename: "users-#{Time.zone.now}.csv" + send_data byte_order_mark + filtered_users.to_csv, filename: "users-#{Time.zone.now}.csv" else head :unauthorized end