controllers: use ACSV to import groupe instructeurs

Unlike `CSV`, `ACSV` auto-detect the file encoding and separator type.
This commit is contained in:
Pierre de La Morinerie 2021-10-05 10:58:00 +02:00
parent dee536fca1
commit f854e3af63
3 changed files with 4 additions and 1 deletions

View file

@ -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'

View file

@ -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

View file

@ -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")