0001-allows-setting-the-private-flag-via-mail-keyword.patch

Jens Krämer, 2019-05-08 10:50

Download (6.01 KB)

View differences:

app/models/mail_handler.rb
203 203
    end
204 204
    issue.description = cleaned_up_text_body
205 205
    issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date?
206
    issue.is_private = (handler_options[:issue][:is_private] == '1')
206
    if handler_options[:issue][:is_private] == '1'
207
      issue.is_private = true
208
    end
207 209

  
208 210
    # add To and Cc as watchers before saving so the watchers can reply to Redmine
209 211
    add_watchers(issue)
......
415 417
      'due_date' => get_keyword(:due_date, :format => '\d{4}-\d{2}-\d{2}'),
416 418
      'estimated_hours' => get_keyword(:estimated_hours),
417 419
      'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0'),
420
      'is_private' => get_keyword_bool(:is_private),
418 421
      'parent_issue_id' => get_keyword(:parent_issue)
419 422
    }.delete_if {|k, v| v.blank? }
420 423

  
421 424
    attrs
422 425
  end
423 426

  
427
  def get_keyword_bool(attr)
428
    true_values = ["1"]
429
    false_values = ["0"]
430
    locales = [Setting.default_language]
431
    if user
432
      locales << user.language
433
    end
434
    locales.select(&:present?).each do |locale|
435
      true_values << l("general_text_yes", :default => '', :locale =>  locale)
436
      true_values << l("general_text_Yes", :default => '', :locale =>  locale)
437
      false_values << l("general_text_no", :default => '', :locale =>  locale)
438
      false_values << l("general_text_No", :default => '', :locale =>  locale)
439
    end
440
    values = (true_values + false_values).select(&:present?)
441
    format = Regexp.union values
442
    if value = get_keyword(attr, :format => format)
443
      if true_values.include?(value)
444
        return true
445
      elsif false_values.include?(value)
446
        return false
447
      end
448
    end
449
    nil
450
  end
451

  
424 452
  # Returns a Hash of issue custom field values extracted from keywords in the email body
425 453
  def custom_field_values_from_keywords(customized)
426 454
    customized.custom_field_values.inject({}) do |h, v|
test/fixtures/mail_handler/ticket_with_localized_private_flag.eml
1
Return-Path: <jsmith@somenet.foo>
2
Received: from osiris ([127.0.0.1])
3
	by OSIRIS
4
	with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
5
Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
6
From: "John Smith" <jsmith@somenet.foo>
7
To: <inbox+test+secret+onlinestore@plan.io>
8
Subject: New ticket on a given project
9
Date: Sun, 22 Jun 2008 12:28:07 +0200
10
MIME-Version: 1.0
11
Content-Type: text/plain;
12
	format=flowed;
13
	charset="iso-8859-1";
14
	reply-type=original
15
Content-Transfer-Encoding: 7bit
16
X-Priority: 3
17
X-MSMail-Priority: Normal
18
X-Mailer: Microsoft Outlook Express 6.00.2900.2869
19
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
20

  
21
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet 
22
turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus 
23
blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti 
24
sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In 
25
in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras 
26
sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum 
27
id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus 
28
eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique 
29
sed, mauris. Pellentesque habitant morbi tristique senectus et netus et 
30
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse 
31
platea dictumst.
32

  
33
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque 
34
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem. 
35
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et, 
36
dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed, 
37
massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo 
38
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
39

  
40
Priv?e: oui
test/unit/mail_handler_test.rb
496 496
    assert_equal 'ecookbook', issue.project.identifier
497 497
  end
498 498

  
499
  def test_add_issue_with_private_keyword
500
    User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
501
    # give the user permission to set issues private:
502
    MemberRole.create! member_id: 3, role_id: 1
503
    issue = submit_email(
504
              'ticket_with_localized_private_flag.eml',
505
              :allow_override => 'is_private,tracker,category,priority'
506
            )
507
    assert issue.is_a?(Issue)
508
    refute issue.new_record?
509
    issue.reload
510
    assert_equal 'New ticket on a given project', issue.subject
511
    assert issue.is_private
512
  end
513

  
499 514
  def test_add_issue_with_localized_attributes
500 515
    User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
501 516
    issue = submit_email(
502
-