diff options
author | Go MAEDA <maeda@farend.jp> | 2019-05-10 00:54:52 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-05-10 00:54:52 +0000 |
commit | a1c40d146a27871bc0621850750fc487eada250b (patch) | |
tree | e4b116c09c361da3e0aa278cf0e123c246fb9838 | |
parent | 1727950c18c83eb2189fbafe2363c9c2f322eead (diff) | |
download | redmine-a1c40d146a27871bc0621850750fc487eada250b.tar.gz redmine-a1c40d146a27871bc0621850750fc487eada250b.zip |
Option to send email notifications while importing issues from CSV files (#22771).
Patch by Yuichi HARADA.
git-svn-id: http://svn.redmine.org/redmine/trunk@18153 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/import.rb | 3 | ||||
-rw-r--r-- | app/models/issue_import.rb | 2 | ||||
-rw-r--r-- | app/views/imports/settings.html.erb | 6 | ||||
-rw-r--r-- | config/locales/en.yml | 1 | ||||
-rw-r--r-- | test/functional/imports_controller_test.rb | 38 |
5 files changed, 48 insertions, 2 deletions
diff --git a/app/models/import.rb b/app/models/import.rb index df6b085a6..ef4b0321e 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -80,7 +80,8 @@ class Import < ActiveRecord::Base 'separator' => separator, 'wrapper' => wrapper, 'encoding' => encoding, - 'date_format' => date_format + 'date_format' => date_format, + 'notifications' => '0' ) end diff --git a/app/models/issue_import.rb b/app/models/issue_import.rb index 5a3542291..5c17f0358 100644 --- a/app/models/issue_import.rb +++ b/app/models/issue_import.rb @@ -86,7 +86,7 @@ class IssueImport < Import def build_object(row, item) issue = Issue.new issue.author = user - issue.notify = false + issue.notify = !!ActiveRecord::Type::Boolean.new.cast(settings['notifications']) tracker_id = nil if tracker diff --git a/app/views/imports/settings.html.erb b/app/views/imports/settings.html.erb index 0fbb01857..c538ea983 100644 --- a/app/views/imports/settings.html.erb +++ b/app/views/imports/settings.html.erb @@ -21,6 +21,12 @@ <label for="import_settings_date_format"><%= l(:setting_date_format) %></label> <%= select_tag 'import_settings[date_format]', options_for_select(date_format_options, @import.settings['date_format']) %> </p> + <br> + <p> + <label for="import_settings_notifications"><%= l(:label_import_notifications) %></label> + <%= hidden_field_tag 'import_settings[notifications]', '0', :id => nil %> + <%= check_box_tag 'import_settings[notifications]', '1', "#{@import.settings['notifications']}" == '1' %> + </p> </fieldset> <p><%= submit_tag l(:label_next).html_safe + " »".html_safe, :name => nil %></p> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 2310d1eec..9bcbc48aa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -950,6 +950,7 @@ en: label_profile: Profile label_subtask_plural: Subtasks label_project_copy_notifications: Send email notifications during the project copy + label_import_notifications: Send email notifications during the import label_principal_search: "Search for user or group:" label_user_search: "Search for user:" label_additional_workflow_transitions_for_author: Additional transitions allowed when the user is the author diff --git a/test/functional/imports_controller_test.rb b/test/functional/imports_controller_test.rb index 85645e24c..f75156379 100644 --- a/test/functional/imports_controller_test.rb +++ b/test/functional/imports_controller_test.rb @@ -237,6 +237,44 @@ class ImportsControllerTest < Redmine::ControllerTest assert_equal ["Child of existing issue", "Child 1", "First"], issues.map(&:subject) end + def test_post_run_with_notifications + import = generate_import + + post :settings, :params => { + :id => import, + :import_settings => { + :separator => ';', + :wrapper => '"', + :encoding => 'ISO-8859-1', + :notifications => '1', + :mapping => { + :project_id => '1', + :tracker => '13', + :subject => '1', + :assigned_to => '11', + }, + }, + } + + ActionMailer::Base.deliveries.clear + assert_difference 'Issue.count', 3 do + post :run, :params => { + :id => import, + } + assert_response :found + end + actual_email_count = ActionMailer::Base.deliveries.size + assert_not_equal 0, actual_email_count + + import.reload + issue_ids = import.items.collect(&:obj_id) + expected_email_count = + Issue.where(:id => issue_ids).inject(0) do |sum, issue| + sum + (issue.notified_users | issue.notified_watchers).size + end + assert_equal expected_email_count, actual_email_count + end + def test_show_without_errors import = generate_import_with_mapping import.run |