@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)
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
'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
<%= 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>
<% 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),
: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),
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
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