##// END OF EJS Templates
Notify project members when a message is posted if they want to receive notifications for everything on the project (#1079)....
Jean-Philippe Lang -
r1353:e55c1d82e633
parent child
Show More
@@ -1,27 +1,29
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class MessageObserver < ActiveRecord::Observer
18 class MessageObserver < ActiveRecord::Observer
19 def after_create(message)
19 def after_create(message)
20 # send notification to the authors of the thread
20 # send notification to the authors of the thread
21 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?}
21 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?}
22 # send notification to the board watchers
22 # send notification to the board watchers
23 recipients += message.board.watcher_recipients
23 recipients += message.board.watcher_recipients
24 # send notification to project members who want to be notified
25 recipients += message.board.project.recipients
24 recipients = recipients.compact.uniq
26 recipients = recipients.compact.uniq
25 Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted')
27 Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted')
26 end
28 end
27 end
29 end
@@ -1,99 +1,111
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'messages_controller'
19 require 'messages_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class MessagesController; def rescue_action(e) raise e end; end
22 class MessagesController; def rescue_action(e) raise e end; end
23
23
24 class MessagesControllerTest < Test::Unit::TestCase
24 class MessagesControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules
25 fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules
26
26
27 def setup
27 def setup
28 @controller = MessagesController.new
28 @controller = MessagesController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_show
34 def test_show
35 get :show, :board_id => 1, :id => 1
35 get :show, :board_id => 1, :id => 1
36 assert_response :success
36 assert_response :success
37 assert_template 'show'
37 assert_template 'show'
38 assert_not_nil assigns(:board)
38 assert_not_nil assigns(:board)
39 assert_not_nil assigns(:project)
39 assert_not_nil assigns(:project)
40 assert_not_nil assigns(:topic)
40 assert_not_nil assigns(:topic)
41 end
41 end
42
42
43 def test_show_message_not_found
43 def test_show_message_not_found
44 get :show, :board_id => 1, :id => 99999
44 get :show, :board_id => 1, :id => 99999
45 assert_response 404
45 assert_response 404
46 end
46 end
47
47
48 def test_get_new
48 def test_get_new
49 @request.session[:user_id] = 2
49 @request.session[:user_id] = 2
50 get :new, :board_id => 1
50 get :new, :board_id => 1
51 assert_response :success
51 assert_response :success
52 assert_template 'new'
52 assert_template 'new'
53 end
53 end
54
54
55 def test_post_new
55 def test_post_new
56 @request.session[:user_id] = 2
56 @request.session[:user_id] = 2
57 ActionMailer::Base.deliveries.clear
58 Setting.notified_events << 'message_posted'
59
57 post :new, :board_id => 1,
60 post :new, :board_id => 1,
58 :message => { :subject => 'Test created message',
61 :message => { :subject => 'Test created message',
59 :content => 'Message body'}
62 :content => 'Message body'}
60 assert_redirected_to 'messages/show'
63 assert_redirected_to 'messages/show'
61 message = Message.find_by_subject('Test created message')
64 message = Message.find_by_subject('Test created message')
62 assert_not_nil message
65 assert_not_nil message
63 assert_equal 'Message body', message.content
66 assert_equal 'Message body', message.content
64 assert_equal 2, message.author_id
67 assert_equal 2, message.author_id
65 assert_equal 1, message.board_id
68 assert_equal 1, message.board_id
69
70 mail = ActionMailer::Base.deliveries.last
71 assert_kind_of TMail::Mail, mail
72 assert_equal "[#{message.board.project.name} - #{message.board.name}] Test created message", mail.subject
73 assert mail.body.include?('Message body')
74 # author
75 assert mail.bcc.include?('jsmith@somenet.foo')
76 # project member
77 assert mail.bcc.include?('dlopper@somenet.foo')
66 end
78 end
67
79
68 def test_get_edit
80 def test_get_edit
69 @request.session[:user_id] = 2
81 @request.session[:user_id] = 2
70 get :edit, :board_id => 1, :id => 1
82 get :edit, :board_id => 1, :id => 1
71 assert_response :success
83 assert_response :success
72 assert_template 'edit'
84 assert_template 'edit'
73 end
85 end
74
86
75 def test_post_edit
87 def test_post_edit
76 @request.session[:user_id] = 2
88 @request.session[:user_id] = 2
77 post :edit, :board_id => 1, :id => 1,
89 post :edit, :board_id => 1, :id => 1,
78 :message => { :subject => 'New subject',
90 :message => { :subject => 'New subject',
79 :content => 'New body'}
91 :content => 'New body'}
80 assert_redirected_to 'messages/show'
92 assert_redirected_to 'messages/show'
81 message = Message.find(1)
93 message = Message.find(1)
82 assert_equal 'New subject', message.subject
94 assert_equal 'New subject', message.subject
83 assert_equal 'New body', message.content
95 assert_equal 'New body', message.content
84 end
96 end
85
97
86 def test_reply
98 def test_reply
87 @request.session[:user_id] = 2
99 @request.session[:user_id] = 2
88 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
100 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
89 assert_redirected_to 'messages/show'
101 assert_redirected_to 'messages/show'
90 assert Message.find_by_subject('Test reply')
102 assert Message.find_by_subject('Test reply')
91 end
103 end
92
104
93 def test_destroy_topic
105 def test_destroy_topic
94 @request.session[:user_id] = 2
106 @request.session[:user_id] = 2
95 post :destroy, :board_id => 1, :id => 1
107 post :destroy, :board_id => 1, :id => 1
96 assert_redirected_to 'boards/show'
108 assert_redirected_to 'boards/show'
97 assert_nil Message.find_by_id(1)
109 assert_nil Message.find_by_id(1)
98 end
110 end
99 end
111 end
General Comments 0
You need to be logged in to leave comments. Login now