]> source.dussan.org Git - redmine.git/commitdiff
Adds private issue option to receiving emails (#8424).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 10 May 2015 09:07:36 +0000 (09:07 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 10 May 2015 09:07:36 +0000 (09:07 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14262 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
extra/mail_handler/rdm-mailhandler.rb
lib/tasks/email.rake
test/functional/mail_handler_controller_test.rb
test/unit/mail_handler_test.rb

index 408932d5749b9e900eb88d773d9560b81cf3db61..78cff699b85d6aadaacfe95af8e33368a5c7c9b6 100644 (file)
@@ -69,6 +69,9 @@ class MailHandler < ActionMailer::Base
     %w(allow_override unknown_user no_permission_check no_account_notice default_group).each do |option|
       options[option.to_sym] = env[option] if env[option]
     end
+    if env['private']
+      options[:issue][:is_private] = '1'
+    end
     options
   end
 
@@ -205,6 +208,7 @@ class MailHandler < ActionMailer::Base
     end
     issue.description = cleaned_up_text_body
     issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
+    issue.is_private = (handler_options[:issue][:is_private] == '1')
 
     # add To and Cc as watchers before saving so the watchers can reply to Redmine
     add_watchers(issue)
index 36d06cb569d6d897e18595d241444e94902ff86c..f5fbe3ac957333360554fe553513b108a4d35e00 100644 (file)
@@ -87,6 +87,7 @@ class RedmineMailHandler
       opts.on("-t", "--tracker TRACKER",      "name of the target tracker") {|v| self.issue_attributes['tracker'] = v}
       opts.on(      "--category CATEGORY",    "name of the target category") {|v| self.issue_attributes['category'] = v}
       opts.on(      "--priority PRIORITY",    "name of the target priority") {|v| self.issue_attributes['priority'] = v}
+      opts.on(      "--private",              "create new issues as private") {|v| self.issue_attributes['is_private'] = '1'}
       opts.on("-o", "--allow-override ATTRS", "allow email content to override attributes",
                                               "specified by previous options",
                                               "ATTRS is a comma separated list of attributes") {|v| self.allow_override = v}
index 121afc4a6a0d22f49a612bcbe21344dfaa5a908e..82b84788cda50514f7cf093adc781bf776813f58 100644 (file)
@@ -89,6 +89,7 @@ Issue attributes control options:
   tracker=TRACKER          name of the target tracker
   category=CATEGORY        name of the target category
   priority=PRIORITY        name of the target priority
+  private                  create new issues as private
   allow_override=ATTRS     allow email content to override attributes
                            specified by previous options
                            ATTRS is a comma separated list of attributes
index 3487d5eb21fad60a3c090c40f4a2dd204c0770e3..a966b774dc31714bf2685b12d74c97852b0d4097 100644 (file)
@@ -38,6 +38,21 @@ class MailHandlerControllerTest < ActionController::TestCase
     assert_response 201
   end
 
+  def test_should_create_issue_with_options
+    # Enable API and set a key
+    Setting.mail_handler_api_enabled = 1
+    Setting.mail_handler_api_key = 'secret'
+
+    assert_difference 'Issue.count' do
+      post :index, :key => 'secret',
+        :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')),
+        :issue => {:is_private => '1'}
+    end
+    assert_response 201
+    issue = Issue.order(:id => :desc).first
+    assert_equal true, issue.is_private
+  end
+
   def test_should_respond_with_422_if_not_created
     Project.find('onlinestore').destroy
 
index 2ae3cb5c14f733100e4b5a1499c6bc8c9a61587c..99900666dc0cfb75b516d2963ff428d30c26ea30 100644 (file)
@@ -94,6 +94,13 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert_equal IssueStatus.find_by_name("Resolved"), issue.status
   end
 
+  def test_add_issue_should_accept_is_private_attribute
+    issue = submit_email('ticket_on_given_project.eml', :issue => {:is_private => '1'})
+    assert issue.is_a?(Issue)
+    assert !issue.new_record?
+    assert_equal true, issue.reload.is_private
+  end
+
   def test_add_issue_with_attributes_override
     issue = submit_email(
               'ticket_with_attributes.eml',