From f854e3af63a55fda88c2a8e70a6f340edfc90e49 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 5 Oct 2021 10:58:00 +0200 Subject: [PATCH] controllers: use ACSV to import groupe instructeurs Unlike `CSV`, `ACSV` auto-detect the file encoding and separator type. --- Gemfile | 1 + Gemfile.lock | 2 ++ .../new_administrateur/groupe_instructeurs_controller.rb | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5e53fd5f8..33cc8f5c0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' gem 'aasm' +gem 'acsv' gem 'active_link_to' # Automatically set a class on active links gem 'active_model_serializers' gem 'activestorage-openstack' diff --git a/Gemfile.lock b/Gemfile.lock index b74b2f130..a76117296 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,6 +20,7 @@ GEM specs: aasm (5.1.1) concurrent-ruby (~> 1.0) + acsv (0.0.1) actioncable (6.1.4.1) actionpack (= 6.1.4.1) activesupport (= 6.1.4.1) @@ -779,6 +780,7 @@ PLATFORMS DEPENDENCIES aasm + acsv active_link_to active_model_serializers active_storage_validations diff --git a/app/controllers/new_administrateur/groupe_instructeurs_controller.rb b/app/controllers/new_administrateur/groupe_instructeurs_controller.rb index 18ca4b449..d3e6d3f9f 100644 --- a/app/controllers/new_administrateur/groupe_instructeurs_controller.rb +++ b/app/controllers/new_administrateur/groupe_instructeurs_controller.rb @@ -215,7 +215,7 @@ module NewAdministrateur else file = group_csv_file.read base_encoding = CharlockHolmes::EncodingDetector.detect(file) - groupes_emails = CSV.new(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase) + groupes_emails = ACSV::CSV.new(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase) .map { |r| r.to_h.slice('groupe', 'email') } groupes_emails_has_keys = groupes_emails.first.has_key?("groupe") && groupes_emails.first.has_key?("email")