]> source.dussan.org Git - redmine.git/commitdiff
Merged r19381 to 4.1-stable (#21766).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 20 Dec 2019 08:51:01 +0000 (08:51 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 20 Dec 2019 08:51:01 +0000 (08:51 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@19387 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/imports_controller.rb
app/models/import.rb
app/views/imports/new.html.erb
app/views/issues/index.html.erb
app/views/timelog/index.html.erb
test/functional/imports_controller_test.rb
test/unit/issue_import_test.rb

index d73e98c0143fcca77b51e7b934b39a2906799a46..633cc232c053301cda406b4403551085a910f0cd 100644 (file)
@@ -36,7 +36,7 @@ class ImportsController < ApplicationController
     @import = import_type.new
     @import.user = User.current
     @import.file = params[:file]
-    @import.set_default_settings
+    @import.set_default_settings(:project_id => params[:project_id])
 
     if @import.save
       redirect_to import_settings_path(@import)
index 696cd4d383b81f83fcdbd5a7bba69ff4dd9554c3..3244b13e22d55753bbc3fdca0b23845361d8e9c4 100644 (file)
@@ -62,7 +62,7 @@ class Import < ActiveRecord::Base
     Redmine::Utils.save_upload(arg, filepath)
   end
 
-  def set_default_settings
+  def set_default_settings(options={})
     separator = lu(user, :general_csv_separator)
     if file_exists?
       begin
@@ -84,6 +84,14 @@ class Import < ActiveRecord::Base
       'date_format' => date_format,
       'notifications' => '0'
     )
+
+    if options.key?(:project_id) && !options[:project_id].blank?
+      # Do not fail if project doesn't exist
+      begin
+        project = Project.find(options[:project_id])
+        self.settings.merge!('mapping' => {'project_id' => project.id})
+      rescue; end
+    end
   end
 
   def to_param
index 41b27d6c98cf756e28d7a5e2012081e6f634aa43..e7ca8242826ba1f65a33a91c09ab797f5ebdddff 100644 (file)
@@ -2,6 +2,7 @@
 
 <%= form_tag(imports_path, :multipart => true) do %>
   <%= hidden_field_tag 'type', @import.type %>
+  <%= hidden_field_tag 'project_id', params[:project_id] %>
   <fieldset class="box">
     <legend><%= l(:label_select_file_to_import) %> (CSV)</legend>
     <p>
index c3c3398517e148c6413324586a195ff2175efcc8..3377fd68192ab8817c12bea0b6894a3bfefe0edc 100644 (file)
@@ -8,7 +8,7 @@
     <% end %>
 
     <% if User.current.allowed_to?(:import_issues, @project, :global => true) %>
-      <%= link_to l(:button_import), new_issues_import_path %>
+      <%= link_to l(:button_import), new_issues_import_path(:project_id => @project) %>
     <% end %>
 
     <%= link_to_if_authorized l(:label_settings),
index 1e243debb36c94cf2c8a6986509a2ff2fef34f32..c34a2440914ccb9572dfc45b0eca6872d5ac7268 100644 (file)
@@ -4,7 +4,7 @@
             :class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %>
 <%= actions_dropdown do %>
   <% if User.current.allowed_to?(:import_time_entries, @project, :global => true) %>
-    <%= link_to l(:button_import), new_time_entries_import_path %>
+    <%= link_to l(:button_import), new_time_entries_import_path(:project_id => @project) %>
   <% end %>
 
   <%= link_to_if_authorized l(:label_settings),
index 77bc6723f1152daeb583a11f6daecd740fa78936..6b22bb19aee1e806843150efa8fab68203d9996e 100644 (file)
@@ -44,9 +44,10 @@ class ImportsControllerTest < Redmine::ControllerTest
   end
 
   def test_new_should_display_the_upload_form
-    get :new, :params => { :type => 'IssueImport' }
+    get :new, :params => { :type => 'IssueImport', :project_id => 'subproject1' }
     assert_response :success
     assert_select 'input[name=?]', 'file'
+    assert_select 'input[name=?][type=?][value=?]', 'project_id', 'hidden', 'subproject1'
   end
 
   def test_create_should_save_the_file
index 8404a0ec1845fda3c4727b312ef78c8874d1925e..7068f46e310aa469292a67c90e856a360fc4d004 100644 (file)
@@ -266,4 +266,32 @@ class IssueImportTest < ActiveSupport::TestCase
     issues = new_records(Issue, 3) { import.run }
     assert [nil, 3, system_version.id], issues.map(&:fixed_version_id)
   end
+
+  def test_set_default_settings_with_project_id
+    import = Import.new
+    import.set_default_settings(:project_id => 3)
+
+    assert_equal 3, import.mapping['project_id']
+  end
+
+  def test_set_default_settings_with_project_identifier
+    import = Import.new
+    import.set_default_settings(:project_id => 'ecookbook')
+
+    assert_equal 1, import.mapping['project_id']
+  end
+
+  def test_set_default_settings_without_project_id
+    import = Import.new
+    import.set_default_settings
+
+    assert_empty import.mapping
+  end
+
+  def test_set_default_settings_with_invalid_project_should_not_fail
+    import = Import.new
+    import.set_default_settings(:project_id => 'abc')
+
+    assert_empty import.mapping
+  end
 end