Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ instructeur je veux pouvoir uploader un referentiel csv de 5 000 lignes (au lieu de 1000 max) #11329

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
%span.fr-download__detail
= template_detail
.fr-hint-text.fr-mb-1w
Votre fichier doit peser maximum #{number_to_human_size(referentiel_max_size)} et ne doit pas contenir plus de #{referentiel_max_lines} lignes.
Votre fichier doit peser maximum #{number_to_human_size(referentiel_max_size)} et ne doit pas contenir plus de #{number_with_delimiter(referentiel_max_lines)} lignes.
.flex.column
= file_field_tag :referentiel_file, required: true, accept: 'text/csv', size: "1", class: 'fr-mb-2w', id: dom_id(type_de_champ, :import_referentiel)

Expand Down
10 changes: 7 additions & 3 deletions app/controllers/administrateurs/types_de_champ_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
before_action :reload_procedure_with_includes, only: [:destroy]

CSV_MAX_SIZE = 1.megabyte
CSV_MAX_LINES = 1000
CSV_MAX_LINES = 5_000
CSV_ACCEPTED_CONTENT_TYPES = [
"text/csv",
"application/vnd.ms-excel"
Expand Down Expand Up @@ -153,9 +153,13 @@

type_de_champ = draft.find_and_ensure_exclusive_use(params[:stable_id])

csv_to_code = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true).map(&:to_h)
begin
csv_to_code = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true).map(&:to_h)
rescue CSV::MalformedCSVError
return flash[:alert] = "Importation impossible : le fichier est mal formaté"

Check warning on line 159 in app/controllers/administrateurs/types_de_champ_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/types_de_champ_controller.rb#L159

Added line #L159 was not covered by tests
end

return flash[:alert] = "Importation impossible : votre fichier CSV fait plus de 1000 lignes" if csv_to_code.size > 1000
return flash[:alert] = "Importation impossible : votre fichier CSV fait plus de #{helpers.number_with_delimiter(CSV_MAX_LINES)} lignes" if csv_to_code.size > CSV_MAX_LINES

headers = csv_to_code.first.keys

Expand Down
Loading