@@ -188,7 +188,13 class Issue < ActiveRecord::Base | |||||
188 | issue.attributes = options[:attributes] |
|
188 | issue.attributes = options[:attributes] | |
189 | end |
|
189 | end | |
190 | if issue.save |
|
190 | if issue.save | |
191 |
|
|
191 | if options[:copy] | |
|
192 | if current_journal && current_journal.notes.present? | |||
|
193 | issue.init_journal(current_journal.user, current_journal.notes) | |||
|
194 | issue.current_journal.notify = false | |||
|
195 | issue.save | |||
|
196 | end | |||
|
197 | else | |||
192 | # Manually update project_id on related time entries |
|
198 | # Manually update project_id on related time entries | |
193 | TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) |
|
199 | TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) | |
194 |
|
200 |
@@ -78,4 +78,12 class Journal < ActiveRecord::Base | |||||
78 | s << ' has-details' unless details.blank? |
|
78 | s << ' has-details' unless details.blank? | |
79 | s |
|
79 | s | |
80 | end |
|
80 | end | |
|
81 | ||||
|
82 | def notify? | |||
|
83 | @notify != false | |||
|
84 | end | |||
|
85 | ||||
|
86 | def notify=(arg) | |||
|
87 | @notify = arg | |||
|
88 | end | |||
81 | end |
|
89 | end |
@@ -1,5 +1,5 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -17,10 +17,12 | |||||
17 |
|
17 | |||
18 | class JournalObserver < ActiveRecord::Observer |
|
18 | class JournalObserver < ActiveRecord::Observer | |
19 | def after_create(journal) |
|
19 | def after_create(journal) | |
20 | if Setting.notified_events.include?('issue_updated') || |
|
20 | if journal.notify? && | |
|
21 | (Setting.notified_events.include?('issue_updated') || | |||
21 | (Setting.notified_events.include?('issue_note_added') && journal.notes.present?) || |
|
22 | (Setting.notified_events.include?('issue_note_added') && journal.notes.present?) || | |
22 | (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) || |
|
23 | (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) || | |
23 | (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?) |
|
24 | (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?) | |
|
25 | ) | |||
24 | Mailer.deliver_issue_edit(journal) |
|
26 | Mailer.deliver_issue_edit(journal) | |
25 | end |
|
27 | end | |
26 | end |
|
28 | end |
@@ -112,6 +112,19 class IssueMovesControllerTest < ActionController::TestCase | |||||
112 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
112 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
|
115 | ||||
|
116 | should "allow adding a note when copying" do | |||
|
117 | @request.session[:user_id] = 2 | |||
|
118 | assert_difference 'Issue.count', 1 do | |||
|
119 | post :create, :ids => [1], :copy_options => {:copy => '1'}, :notes => 'Copying one issue', :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31' | |||
|
120 | end | |||
|
121 | ||||
|
122 | issue = Issue.first(:order => 'id DESC') | |||
|
123 | assert_equal 1, issue.journals.size | |||
|
124 | journal = issue.journals.first | |||
|
125 | assert_equal 0, journal.details.size | |||
|
126 | assert_equal 'Copying one issue', journal.notes | |||
|
127 | end | |||
115 | end |
|
128 | end | |
116 |
|
129 | |||
117 | def test_copy_to_another_project_should_follow_when_needed |
|
130 | def test_copy_to_another_project_should_follow_when_needed |
@@ -523,6 +523,11 class IssueTest < ActiveSupport::TestCase | |||||
523 | @copy = nil |
|
523 | @copy = nil | |
524 | end |
|
524 | end | |
525 |
|
525 | |||
|
526 | should "not create a journal" do | |||
|
527 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) | |||
|
528 | assert_equal 0, @copy.reload.journals.size | |||
|
529 | end | |||
|
530 | ||||
526 | should "allow assigned_to changes" do |
|
531 | should "allow assigned_to changes" do | |
527 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) |
|
532 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) | |
528 | assert_equal 3, @copy.assigned_to_id |
|
533 | assert_equal 3, @copy.assigned_to_id | |
@@ -552,6 +557,19 class IssueTest < ActiveSupport::TestCase | |||||
552 |
|
557 | |||
553 | assert_equal User.current, @copy.author |
|
558 | assert_equal User.current, @copy.author | |
554 | end |
|
559 | end | |
|
560 | ||||
|
561 | should "keep journal notes" do | |||
|
562 | date = Date.today | |||
|
563 | notes = "Notes added when copying" | |||
|
564 | User.current = User.find(9) | |||
|
565 | @issue.init_journal(User.current, notes) | |||
|
566 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}}) | |||
|
567 | ||||
|
568 | assert_equal 1, @copy.journals.size | |||
|
569 | journal = @copy.journals.first | |||
|
570 | assert_equal 0, journal.details.size | |||
|
571 | assert_equal notes, journal.notes | |||
|
572 | end | |||
555 | end |
|
573 | end | |
556 | end |
|
574 | end | |
557 |
|
575 |
@@ -1,5 +1,5 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -36,6 +36,17 class JournalObserverTest < ActiveSupport::TestCase | |||||
36 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
36 | assert_equal 1, ActionMailer::Base.deliveries.size | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
|
39 | def test_create_should_not_send_email_notification_with_notify_set_to_false | |||
|
40 | Setting.notified_events = ['issue_updated'] | |||
|
41 | issue = Issue.find(:first) | |||
|
42 | user = User.find(:first) | |||
|
43 | journal = issue.init_journal(user, issue) | |||
|
44 | journal.notify = false | |||
|
45 | ||||
|
46 | assert journal.save | |||
|
47 | assert_equal 0, ActionMailer::Base.deliveries.size | |||
|
48 | end | |||
|
49 | ||||
39 | def test_create_should_not_send_email_notification_without_issue_updated |
|
50 | def test_create_should_not_send_email_notification_without_issue_updated | |
40 | Setting.notified_events = [] |
|
51 | Setting.notified_events = [] | |
41 | issue = Issue.find(:first) |
|
52 | issue = Issue.find(:first) |
General Comments 0
You need to be logged in to leave comments.
Login now