Skip to content

Commit 28a8412

Browse files
juno-nishizakiRedmine Patch Meetup
authored andcommitted
第23回 mailer.rbの未実装だったメソッドを実装した
1 parent 1faa1c8 commit 28a8412

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

app/models/mailer.rb

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def self.deliver_document_added(document, author)
166166
end
167167

168168
# Builds a mail to user about new attachements.
169-
def attachments_added(user, attachments)
169+
def attachments_added(user, attachments, recipients=nil)
170170
container = attachments.first.container
171171
added_to = ''
172172
added_to_url = ''
@@ -185,6 +185,7 @@ def attachments_added(user, attachments)
185185
redmine_headers 'Project' => container.project.identifier
186186
@attachments = attachments
187187
@user = user
188+
@recipients = recipients
188189
@added_to = added_to
189190
@added_to_url = added_to_url
190191
mail :to => user,
@@ -205,18 +206,19 @@ def self.deliver_attachments_added(attachments)
205206
end
206207

207208
users.each do |user|
208-
attachments_added(user, attachments).deliver_later
209+
attachments_added(user, attachments, users).deliver_later
209210
end
210211
end
211212

212213
# Builds a mail to user about a new news.
213-
def news_added(user, news)
214+
def news_added(user, news, recipients=nil)
214215
redmine_headers 'Project' => news.project.identifier
215216
@author = news.author
216217
message_id news
217218
references news
218219
@news = news
219220
@user = user
221+
@recipients = recipients
220222
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
221223
mail :to => user,
222224
:subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
@@ -229,12 +231,12 @@ def news_added(user, news)
229231
def self.deliver_news_added(news)
230232
users = news.notified_users | news.notified_watchers_for_added_news
231233
users.each do |user|
232-
news_added(user, news).deliver_later
234+
news_added(user, news, users).deliver_later
233235
end
234236
end
235237

236238
# Builds a mail to user about a new news comment.
237-
def news_comment_added(user, comment)
239+
def news_comment_added(user, comment, recipients=nil)
238240
news = comment.commented
239241
redmine_headers 'Project' => news.project.identifier
240242
@author = comment.author
@@ -243,6 +245,7 @@ def news_comment_added(user, comment)
243245
@news = news
244246
@comment = comment
245247
@user = user
248+
@recipients = recipients
246249
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
247250
mail :to => user,
248251
:subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
@@ -256,19 +259,20 @@ def self.deliver_news_comment_added(comment)
256259
news = comment.commented
257260
users = news.notified_users | news.notified_watchers
258261
users.each do |user|
259-
news_comment_added(user, comment).deliver_later
262+
news_comment_added(user, comment, users).deliver_later
260263
end
261264
end
262265

263266
# Builds a mail to user about a new message.
264-
def message_posted(user, message)
267+
def message_posted(user, message, recipients=nil)
265268
redmine_headers 'Project' => message.project.identifier,
266269
'Topic-Id' => (message.parent_id || message.id)
267270
@author = message.author
268271
message_id message
269272
references message.root
270273
@message = message
271274
@user = user
275+
@recipients = recipients
272276
@message_url = url_for(message.event_url)
273277
mail :to => user,
274278
:subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
@@ -284,18 +288,19 @@ def self.deliver_message_posted(message)
284288
users |= message.board.notified_watchers
285289

286290
users.each do |user|
287-
message_posted(user, message).deliver_later
291+
message_posted(user, message, users).deliver_later
288292
end
289293
end
290294

291295
# Builds a mail to user about a new wiki content.
292-
def wiki_content_added(user, wiki_content)
296+
def wiki_content_added(user, wiki_content, recipients=nil)
293297
redmine_headers 'Project' => wiki_content.project.identifier,
294298
'Wiki-Page-Id' => wiki_content.page.id
295299
@author = wiki_content.author
296300
message_id wiki_content
297301
@wiki_content = wiki_content
298302
@user = user
303+
@recipients = recipients
299304
@wiki_content_url = url_for(:controller => 'wiki', :action => 'show',
300305
:project_id => wiki_content.project,
301306
:id => wiki_content.page.title)
@@ -313,18 +318,19 @@ def wiki_content_added(user, wiki_content)
313318
def self.deliver_wiki_content_added(wiki_content)
314319
users = wiki_content.notified_users | wiki_content.page.wiki.notified_watchers | wiki_content.notified_mentions
315320
users.each do |user|
316-
wiki_content_added(user, wiki_content).deliver_later
321+
wiki_content_added(user, wiki_content, users).deliver_later
317322
end
318323
end
319324

320325
# Builds a mail to user about an update of the specified wiki content.
321-
def wiki_content_updated(user, wiki_content)
326+
def wiki_content_updated(user, wiki_content, recipients=nil)
322327
redmine_headers 'Project' => wiki_content.project.identifier,
323328
'Wiki-Page-Id' => wiki_content.page.id
324329
@author = wiki_content.author
325330
message_id wiki_content
326331
@wiki_content = wiki_content
327332
@user = user
333+
@recipients = recipients
328334
@wiki_content_url =
329335
url_for(:controller => 'wiki', :action => 'show',
330336
:project_id => wiki_content.project,
@@ -351,7 +357,7 @@ def self.deliver_wiki_content_updated(wiki_content)
351357
users |= wiki_content.notified_mentions
352358

353359
users.each do |user|
354-
wiki_content_updated(user, wiki_content).deliver_later
360+
wiki_content_updated(user, wiki_content, users).deliver_later
355361
end
356362
end
357363

@@ -370,8 +376,9 @@ def self.deliver_account_information(user, password)
370376
end
371377

372378
# Builds a mail to user about an account activation request.
373-
def account_activation_request(user, new_user)
379+
def account_activation_request(user, new_user, recipients=nil)
374380
@new_user = new_user
381+
@recipients = recipients
375382
@url = url_for(:controller => 'users', :action => 'index',
376383
:status => User::STATUS_REGISTERED,
377384
:sort_key => 'created_on', :sort_order => 'desc')
@@ -388,7 +395,7 @@ def self.deliver_account_activation_request(new_user)
388395
# Send the email to all active administrators
389396
users = User.active.where(:admin => true)
390397
users.each do |user|
391-
account_activation_request(user, new_user).deliver_later
398+
account_activation_request(user, new_user, users.to_a).deliver_later
392399
end
393400
end
394401

@@ -472,7 +479,8 @@ def self.deliver_register(user, token)
472479
# field: :field_mail,
473480
# value: address
474481
# ) => Mail::Message object
475-
def security_notification(user, sender, options={})
482+
def security_notification(user, sender, options={}, recipients=nil)
483+
@recipients = recipients
476484
@sender = sender
477485
redmine_headers 'Sender' => sender.login
478486
@message =
@@ -509,12 +517,13 @@ def self.deliver_security_notification(users, sender, options={})
509517
options[:remote_ip] ||= sender.remote_ip
510518

511519
Array.wrap(users).each do |user|
512-
security_notification(user, sender, options).deliver_later
520+
security_notification(user, sender, options, users).deliver_later
513521
end
514522
end
515523

516524
# Build a mail to user about application settings changes made by sender.
517-
def settings_updated(user, sender, changes, options={})
525+
def settings_updated(user, sender, changes, options={}, recipients=nil)
526+
@recipients = recipients
518527
@sender = sender
519528
redmine_headers 'Sender' => sender.login
520529
@changes = changes
@@ -541,7 +550,7 @@ def self.deliver_settings_updated(sender, changes, options={})
541550

542551
users = User.active.where(admin: true).to_a
543552
users.each do |user|
544-
settings_updated(user, sender, changes, options).deliver_later
553+
settings_updated(user, sender, changes, options, users).deliver_later
545554
end
546555
end
547556

0 commit comments

Comments
 (0)