@@ -29,6 +29,10 class Document < ActiveRecord::Base | |||||
29 | validates_presence_of :project, :title, :category |
|
29 | validates_presence_of :project, :title, :category | |
30 | validates_length_of :title, :maximum => 60 |
|
30 | validates_length_of :title, :maximum => 60 | |
31 |
|
31 | |||
|
32 | def visible?(user=User.current) | |||
|
33 | !user.nil? && user.allowed_to?(:view_documents, project) | |||
|
34 | end | |||
|
35 | ||||
32 | def after_initialize |
|
36 | def after_initialize | |
33 | if new_record? |
|
37 | if new_record? | |
34 | self.category ||= DocumentCategory.default |
|
38 | self.category ||= DocumentCategory.default | |
@@ -42,4 +46,11 class Document < ActiveRecord::Base | |||||
42 | end |
|
46 | end | |
43 | @updated_on |
|
47 | @updated_on | |
44 | end |
|
48 | end | |
|
49 | ||||
|
50 | # Returns the mail adresses of users that should be notified | |||
|
51 | def recipients | |||
|
52 | notified = project.notified_users | |||
|
53 | notified.reject! {|user| !visible?(user)} | |||
|
54 | notified.collect(&:mail) | |||
|
55 | end | |||
45 | end |
|
56 | end |
@@ -94,7 +94,7 class Mailer < ActionMailer::Base | |||||
94 | # Mailer.deliver_document_added(document) => sends an email to the document's project recipients |
|
94 | # Mailer.deliver_document_added(document) => sends an email to the document's project recipients | |
95 | def document_added(document) |
|
95 | def document_added(document) | |
96 | redmine_headers 'Project' => document.project.identifier |
|
96 | redmine_headers 'Project' => document.project.identifier | |
97 |
recipients document. |
|
97 | recipients document.recipients | |
98 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" |
|
98 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" | |
99 | body :document => document, |
|
99 | body :document => document, | |
100 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) |
|
100 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) | |
@@ -114,15 +114,17 class Mailer < ActionMailer::Base | |||||
114 | when 'Project' |
|
114 | when 'Project' | |
115 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container) |
|
115 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container) | |
116 | added_to = "#{l(:label_project)}: #{container}" |
|
116 | added_to = "#{l(:label_project)}: #{container}" | |
|
117 | recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} | |||
117 | when 'Version' |
|
118 | when 'Version' | |
118 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) |
|
119 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) | |
119 | added_to = "#{l(:label_version)}: #{container.name}" |
|
120 | added_to = "#{l(:label_version)}: #{container.name}" | |
|
121 | recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} | |||
120 | when 'Document' |
|
122 | when 'Document' | |
121 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) |
|
123 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) | |
122 | added_to = "#{l(:label_document)}: #{container.title}" |
|
124 | added_to = "#{l(:label_document)}: #{container.title}" | |
|
125 | recipients container.recipients | |||
123 | end |
|
126 | end | |
124 | redmine_headers 'Project' => container.project.identifier |
|
127 | redmine_headers 'Project' => container.project.identifier | |
125 | recipients container.project.recipients |
|
|||
126 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" |
|
128 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" | |
127 | body :attachments => attachments, |
|
129 | body :attachments => attachments, | |
128 | :added_to => added_to, |
|
130 | :added_to => added_to, | |
@@ -138,24 +140,25 class Mailer < ActionMailer::Base | |||||
138 | def news_added(news) |
|
140 | def news_added(news) | |
139 | redmine_headers 'Project' => news.project.identifier |
|
141 | redmine_headers 'Project' => news.project.identifier | |
140 | message_id news |
|
142 | message_id news | |
141 |
recipients news. |
|
143 | recipients news.recipients | |
142 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
144 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" | |
143 | body :news => news, |
|
145 | body :news => news, | |
144 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
146 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) | |
145 | render_multipart('news_added', body) |
|
147 | render_multipart('news_added', body) | |
146 | end |
|
148 | end | |
147 |
|
149 | |||
148 |
# Builds a tmail object used to email the |
|
150 | # Builds a tmail object used to email the recipients of the specified message that was posted. | |
149 | # |
|
151 | # | |
150 | # Example: |
|
152 | # Example: | |
151 |
# message_posted(message |
|
153 | # message_posted(message) => tmail object | |
152 |
# Mailer.deliver_message_posted(message |
|
154 | # Mailer.deliver_message_posted(message) => sends an email to the recipients | |
153 |
def message_posted(message |
|
155 | def message_posted(message) | |
154 | redmine_headers 'Project' => message.project.identifier, |
|
156 | redmine_headers 'Project' => message.project.identifier, | |
155 | 'Topic-Id' => (message.parent_id || message.id) |
|
157 | 'Topic-Id' => (message.parent_id || message.id) | |
156 | message_id message |
|
158 | message_id message | |
157 | references message.parent unless message.parent.nil? |
|
159 | references message.parent unless message.parent.nil? | |
158 | recipients(recipients) |
|
160 | recipients(message.recipients) | |
|
161 | cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients) | |||
159 | subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" |
|
162 | subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" | |
160 | body :message => message, |
|
163 | body :message => message, | |
161 | :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) |
|
164 | :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) | |
@@ -171,7 +174,7 class Mailer < ActionMailer::Base | |||||
171 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
174 | redmine_headers 'Project' => wiki_content.project.identifier, | |
172 | 'Wiki-Page-Id' => wiki_content.page.id |
|
175 | 'Wiki-Page-Id' => wiki_content.page.id | |
173 | message_id wiki_content |
|
176 | message_id wiki_content | |
174 |
recipients wiki_content. |
|
177 | recipients wiki_content.recipients | |
175 | cc(wiki_content.page.wiki.watcher_recipients - recipients) |
|
178 | cc(wiki_content.page.wiki.watcher_recipients - recipients) | |
176 | subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :page => wiki_content.page.pretty_title)}" |
|
179 | subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :page => wiki_content.page.pretty_title)}" | |
177 | body :wiki_content => wiki_content, |
|
180 | body :wiki_content => wiki_content, | |
@@ -188,7 +191,7 class Mailer < ActionMailer::Base | |||||
188 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
191 | redmine_headers 'Project' => wiki_content.project.identifier, | |
189 | 'Wiki-Page-Id' => wiki_content.page.id |
|
192 | 'Wiki-Page-Id' => wiki_content.page.id | |
190 | message_id wiki_content |
|
193 | message_id wiki_content | |
191 |
recipients wiki_content. |
|
194 | recipients wiki_content.recipients | |
192 | cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients) |
|
195 | cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients) | |
193 | subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :page => wiki_content.page.pretty_title)}" |
|
196 | subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :page => wiki_content.page.pretty_title)}" | |
194 | body :wiki_content => wiki_content, |
|
197 | body :wiki_content => wiki_content, |
@@ -90,6 +90,13 class Message < ActiveRecord::Base | |||||
90 | usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) |
|
90 | usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
|
93 | # Returns the mail adresses of users that should be notified | |||
|
94 | def recipients | |||
|
95 | notified = project.notified_users | |||
|
96 | notified.reject! {|user| !visible?(user)} | |||
|
97 | notified.collect(&:mail) | |||
|
98 | end | |||
|
99 | ||||
93 | private |
|
100 | private | |
94 |
|
101 | |||
95 | def add_author_as_watcher |
|
102 | def add_author_as_watcher |
@@ -17,14 +17,6 | |||||
17 |
|
17 | |||
18 | class MessageObserver < ActiveRecord::Observer |
|
18 | class MessageObserver < ActiveRecord::Observer | |
19 | def after_create(message) |
|
19 | def after_create(message) | |
20 | recipients = [] |
|
20 | Mailer.deliver_message_posted(message) if Setting.notified_events.include?('message_posted') | |
21 | # send notification to the topic watchers |
|
|||
22 | recipients += message.root.watcher_recipients |
|
|||
23 | # send notification to the board watchers |
|
|||
24 | recipients += message.board.watcher_recipients |
|
|||
25 | # send notification to project members who want to be notified |
|
|||
26 | recipients += message.board.project.recipients |
|
|||
27 | recipients = recipients.compact.uniq |
|
|||
28 | Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted') |
|
|||
29 | end |
|
21 | end | |
30 | end |
|
22 | end |
@@ -29,6 +29,17 class News < ActiveRecord::Base | |||||
29 | acts_as_activity_provider :find_options => {:include => [:project, :author]}, |
|
29 | acts_as_activity_provider :find_options => {:include => [:project, :author]}, | |
30 | :author_key => :author_id |
|
30 | :author_key => :author_id | |
31 |
|
31 | |||
|
32 | def visible?(user=User.current) | |||
|
33 | !user.nil? && user.allowed_to?(:view_news, project) | |||
|
34 | end | |||
|
35 | ||||
|
36 | # Returns the mail adresses of users that should be notified | |||
|
37 | def recipients | |||
|
38 | notified = project.notified_users | |||
|
39 | notified.reject! {|user| !visible?(user)} | |||
|
40 | notified.collect(&:mail) | |||
|
41 | end | |||
|
42 | ||||
32 | # returns latest news for projects visible by user |
|
43 | # returns latest news for projects visible by user | |
33 | def self.latest(user = User.current, count = 5) |
|
44 | def self.latest(user = User.current, count = 5) | |
34 | find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
45 | find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
@@ -25,11 +25,22 class WikiContent < ActiveRecord::Base | |||||
25 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
25 | validates_length_of :comments, :maximum => 255, :allow_nil => true | |
26 |
|
26 | |||
27 | acts_as_versioned |
|
27 | acts_as_versioned | |
|
28 | ||||
|
29 | def visible?(user=User.current) | |||
|
30 | page.visible?(user) | |||
|
31 | end | |||
28 |
|
32 | |||
29 | def project |
|
33 | def project | |
30 | page.project |
|
34 | page.project | |
31 | end |
|
35 | end | |
32 |
|
36 | |||
|
37 | # Returns the mail adresses of users that should be notified | |||
|
38 | def recipients | |||
|
39 | notified = project.notified_users | |||
|
40 | notified.reject! {|user| !visible?(user)} | |||
|
41 | notified.collect(&:mail) | |||
|
42 | end | |||
|
43 | ||||
33 | class Version |
|
44 | class Version | |
34 | belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' |
|
45 | belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' | |
35 | belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' |
|
46 | belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' |
@@ -147,7 +147,7 class MailerTest < ActiveSupport::TestCase | |||||
147 | def test_message_posted_message_id |
|
147 | def test_message_posted_message_id | |
148 | ActionMailer::Base.deliveries.clear |
|
148 | ActionMailer::Base.deliveries.clear | |
149 | message = Message.find(1) |
|
149 | message = Message.find(1) | |
150 |
Mailer.deliver_message_posted(message |
|
150 | Mailer.deliver_message_posted(message) | |
151 | mail = ActionMailer::Base.deliveries.last |
|
151 | mail = ActionMailer::Base.deliveries.last | |
152 | assert_not_nil mail |
|
152 | assert_not_nil mail | |
153 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
153 | assert_equal Mailer.message_id_for(message), mail.message_id | |
@@ -157,13 +157,47 class MailerTest < ActiveSupport::TestCase | |||||
157 | def test_reply_posted_message_id |
|
157 | def test_reply_posted_message_id | |
158 | ActionMailer::Base.deliveries.clear |
|
158 | ActionMailer::Base.deliveries.clear | |
159 | message = Message.find(3) |
|
159 | message = Message.find(3) | |
160 |
Mailer.deliver_message_posted(message |
|
160 | Mailer.deliver_message_posted(message) | |
161 | mail = ActionMailer::Base.deliveries.last |
|
161 | mail = ActionMailer::Base.deliveries.last | |
162 | assert_not_nil mail |
|
162 | assert_not_nil mail | |
163 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
163 | assert_equal Mailer.message_id_for(message), mail.message_id | |
164 | assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s |
|
164 | assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
|
167 | context("#issue_add") do | |||
|
168 | setup do | |||
|
169 | ActionMailer::Base.deliveries.clear | |||
|
170 | Setting.bcc_recipients = '1' | |||
|
171 | @issue = Issue.find(1) | |||
|
172 | end | |||
|
173 | ||||
|
174 | should "notify project members" do | |||
|
175 | assert Mailer.deliver_issue_add(@issue) | |||
|
176 | assert last_email.bcc.include?('dlopper@somenet.foo') | |||
|
177 | end | |||
|
178 | ||||
|
179 | should "not notify project members that are not allow to view the issue" do | |||
|
180 | Role.find(2).remove_permission!(:view_issues) | |||
|
181 | assert Mailer.deliver_issue_add(@issue) | |||
|
182 | assert !last_email.bcc.include?('dlopper@somenet.foo') | |||
|
183 | end | |||
|
184 | ||||
|
185 | should "notify issue watchers" do | |||
|
186 | user = User.find(9) | |||
|
187 | Watcher.create!(:watchable => @issue, :user => user) | |||
|
188 | assert Mailer.deliver_issue_add(@issue) | |||
|
189 | assert last_email.bcc.include?(user.mail) | |||
|
190 | end | |||
|
191 | ||||
|
192 | should "not notify watchers not allowed to view the issue" do | |||
|
193 | user = User.find(9) | |||
|
194 | Watcher.create!(:watchable => @issue, :user => user) | |||
|
195 | Role.non_member.remove_permission!(:view_issues) | |||
|
196 | assert Mailer.deliver_issue_add(@issue) | |||
|
197 | assert !last_email.bcc.include?(user.mail) | |||
|
198 | end | |||
|
199 | end | |||
|
200 | ||||
167 | # test mailer methods for each language |
|
201 | # test mailer methods for each language | |
168 | def test_issue_add |
|
202 | def test_issue_add | |
169 | issue = Issue.find(1) |
|
203 | issue = Issue.find(1) | |
@@ -211,7 +245,7 class MailerTest < ActiveSupport::TestCase | |||||
211 | recipients = recipients.compact.uniq |
|
245 | recipients = recipients.compact.uniq | |
212 | valid_languages.each do |lang| |
|
246 | valid_languages.each do |lang| | |
213 | Setting.default_language = lang.to_s |
|
247 | Setting.default_language = lang.to_s | |
214 |
assert Mailer.deliver_message_posted(message |
|
248 | assert Mailer.deliver_message_posted(message) | |
215 | end |
|
249 | end | |
216 | end |
|
250 | end | |
217 |
|
251 | |||
@@ -256,4 +290,10 class MailerTest < ActiveSupport::TestCase | |||||
256 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
290 | assert mail.bcc.include?('dlopper@somenet.foo') | |
257 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
|
291 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') | |
258 | end |
|
292 | end | |
|
293 | ||||
|
294 | def last_email | |||
|
295 | mail = ActionMailer::Base.deliveries.last | |||
|
296 | assert_not_nil mail | |||
|
297 | ||||
|
298 | end | |||
259 | end |
|
299 | end |
General Comments 0
You need to be logged in to leave comments.
Login now