add windows content type to avoid errors

This commit is contained in:
kara Diaby 2021-07-15 15:52:51 +02:00
parent ebf0b5ce8f
commit c731f8cf1f

View file

@ -3,6 +3,10 @@ module NewAdministrateur
include ActiveSupport::NumberHelper
ITEMS_PER_PAGE = 25
CSV_MAX_SIZE = 1.megabytes
CSV_ACCEPTED_CONTENT_TYPES = [
"text/csv",
"application/vnd.ms-excel"
]
def index
@procedure = procedure
@ -161,7 +165,7 @@ module NewAdministrateur
end
def import
if (group_csv_file.content_type != "text/csv") && (marcel_content_type != "text/csv")
if !CSV_ACCEPTED_CONTENT_TYPES.include?(group_csv_file.content_type) && !CSV_ACCEPTED_CONTENT_TYPES.include?(marcel_content_type)
flash[:alert] = "Importation impossible : veuillez importer un fichier CSV"
redirect_to admin_procedure_groupe_instructeurs_path(procedure)
@ -171,7 +175,6 @@ module NewAdministrateur
else
file = group_csv_file.read
# find the original encoding to avoid encoding errors
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)
.map { |r| r.to_h.slice('groupe', 'email') }