diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2019-12-20 08:07:57 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2019-12-20 08:07:57 +0000 |
commit | 13da124b16ff58f83e812e8b57f4039b4681a3d6 (patch) | |
tree | fa9b0fd654a48dc7cca7da430bf84098638bc10f | |
parent | 9c6a2c48e0e5bafbe8158269f6c4969d89441e89 (diff) | |
download | redmine-13da124b16ff58f83e812e8b57f4039b4681a3d6.tar.gz redmine-13da124b16ff58f83e812e8b57f4039b4681a3d6.zip |
CSV import does not keep the project it was clicked from (#21766).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@19381 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/imports_controller.rb | 2 | ||||
-rw-r--r-- | app/models/import.rb | 10 | ||||
-rw-r--r-- | app/views/imports/new.html.erb | 1 | ||||
-rw-r--r-- | app/views/issues/index.html.erb | 2 | ||||
-rw-r--r-- | app/views/timelog/index.html.erb | 2 | ||||
-rw-r--r-- | test/functional/imports_controller_test.rb | 3 | ||||
-rw-r--r-- | test/unit/issue_import_test.rb | 28 |
7 files changed, 43 insertions, 5 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index d73e98c01..633cc232c 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -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) diff --git a/app/models/import.rb b/app/models/import.rb index 696cd4d38..3244b13e2 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -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 diff --git a/app/views/imports/new.html.erb b/app/views/imports/new.html.erb index 41b27d6c9..e7ca82428 100644 --- a/app/views/imports/new.html.erb +++ b/app/views/imports/new.html.erb @@ -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> diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 18ec61849..0e8010467 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -11,7 +11,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 %> <% end %> </div> diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb index e33855cd8..01e6752fe 100644 --- a/app/views/timelog/index.html.erb +++ b/app/views/timelog/index.html.erb @@ -7,7 +7,7 @@ :class => 'icon icon-settings' if User.current.allowed_to?(:manage_project_activities, @project) %> <%= 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 %> <% end %> </div> diff --git a/test/functional/imports_controller_test.rb b/test/functional/imports_controller_test.rb index 77bc6723f..6b22bb19a 100644 --- a/test/functional/imports_controller_test.rb +++ b/test/functional/imports_controller_test.rb @@ -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 diff --git a/test/unit/issue_import_test.rb b/test/unit/issue_import_test.rb index 8404a0ec1..7068f46e3 100644 --- a/test/unit/issue_import_test.rb +++ b/test/unit/issue_import_test.rb @@ -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 |