]> source.dussan.org Git - redmine.git/commitdiff
Reject CSV file without data row when importing (#35137).
authorGo MAEDA <maeda@farend.jp>
Sun, 20 Jun 2021 13:25:10 +0000 (13:25 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 20 Jun 2021 13:25:10 +0000 (13:25 +0000)
Patch by Yuichi HARADA.

git-svn-id: http://svn.redmine.org/redmine/trunk@21041 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/imports_controller.rb
config/locales/en.yml
test/fixtures/files/import_issues_no_data_row.csv [new file with mode: 0644]
test/functional/imports_controller_test.rb

index 721d08fa23fe41179e836a1cd8e223b91f000078..612bab97bcc674a138aa46e57c8fecb5ac8cc999 100644 (file)
@@ -50,7 +50,11 @@ class ImportsController < ApplicationController
 
   def settings
     if request.post? && @import.parse_file
-      redirect_to import_mapping_path(@import)
+      if @import.total_items == 0
+        flash.now[:error] = l(:error_no_data_in_file)
+      else
+        redirect_to import_mapping_path(@import)
+      end
     end
 
   rescue CSV::MalformedCSVError, EncodingError => e
index d89d39ebcf37f66efa14778cd3bb508740b6c6e9..0aeafe516bb991edbd1cedd6b1b87e7251353e0a 100644 (file)
@@ -223,6 +223,7 @@ en:
   error_invalid_file_encoding: "The file is not a valid %{encoding} encoded file"
   error_invalid_csv_file_or_settings: "The file is not a CSV file or does not match the settings below (%{value})"
   error_can_not_read_import_file: "An error occurred while reading the file to import"
+  error_no_data_in_file: "The file does not contain any data"
   error_attachment_extension_not_allowed: "Attachment extension %{extension} is not allowed"
   error_ldap_bind_credentials: "Invalid LDAP Account/Password"
   error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue"
diff --git a/test/fixtures/files/import_issues_no_data_row.csv b/test/fixtures/files/import_issues_no_data_row.csv
new file mode 100644 (file)
index 0000000..269117b
--- /dev/null
@@ -0,0 +1 @@
+priority;Subject;start_date;parent;private;progress;custom;"target version";category;user;estimated_hours;tracker;status;database;cf_6;
index fa122979143c77c9a798f0653ee6eb2edae36dc5..f87fd029f525a09670824f4177e49362f1876180 100644 (file)
@@ -180,6 +180,27 @@ class ImportsControllerTest < Redmine::ControllerTest
     assert_select 'div#flash_error', /The file is not a CSV file or does not match the settings below \([[:print:]]+\)/
   end
 
+  def test_post_settings_with_no_data_row_should_display_error
+    import = generate_import('import_issues_no_data_row.csv')
+
+    post(
+      :settings,
+      :params => {
+        :id => import.to_param,
+        :import_settings => {
+          :separator => ';',
+          :wrapper => '"',
+          :encoding => 'ISO-8859-1'
+        }
+      }
+    )
+    assert_response 200
+    import.reload
+    assert_equal 0, import.total_items
+
+    assert_select 'div#flash_error', /The file does not contain any data/
+  end
+
   def test_get_mapping_should_display_mapping_form
     import = generate_import('import_iso8859-1.csv')
     import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"}