Skip to content

Commit 0fa35c8

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

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
@@ -164,7 +164,7 @@ def self.deliver_document_added(document, author)
164164
end
165165

166166
# Builds a mail to user about new attachements.
167-
def attachments_added(user, attachments)
167+
def attachments_added(user, attachments, recipients=nil)
168168
container = attachments.first.container
169169
added_to = ''
170170
added_to_url = ''
@@ -183,6 +183,7 @@ def attachments_added(user, attachments)
183183
redmine_headers 'Project' => container.project.identifier
184184
@attachments = attachments
185185
@user = user
186+
@recipients = recipients
186187
@added_to = added_to
187188
@added_to_url = added_to_url
188189
mail :to => user,
@@ -203,18 +204,19 @@ def self.deliver_attachments_added(attachments)
203204
end
204205

205206
users.each do |user|
206-
attachments_added(user, attachments).deliver_later
207+
attachments_added(user, attachments, users).deliver_later
207208
end
208209
end
209210

210211
# Builds a mail to user about a new news.
211-
def news_added(user, news)
212+
def news_added(user, news, recipients=nil)
212213
redmine_headers 'Project' => news.project.identifier
213214
@author = news.author
214215
message_id news
215216
references news
216217
@news = news
217218
@user = user
219+
@recipients = recipients
218220
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
219221
mail :to => user,
220222
:subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
@@ -227,12 +229,12 @@ def news_added(user, news)
227229
def self.deliver_news_added(news)
228230
users = news.notified_users | news.notified_watchers_for_added_news
229231
users.each do |user|
230-
news_added(user, news).deliver_later
232+
news_added(user, news, users).deliver_later
231233
end
232234
end
233235

234236
# Builds a mail to user about a new news comment.
235-
def news_comment_added(user, comment)
237+
def news_comment_added(user, comment, recipients=nil)
236238
news = comment.commented
237239
redmine_headers 'Project' => news.project.identifier
238240
@author = comment.author
@@ -241,6 +243,7 @@ def news_comment_added(user, comment)
241243
@news = news
242244
@comment = comment
243245
@user = user
246+
@recipients = recipients
244247
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
245248
mail :to => user,
246249
:subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
@@ -254,19 +257,20 @@ def self.deliver_news_comment_added(comment)
254257
news = comment.commented
255258
users = news.notified_users | news.notified_watchers
256259
users.each do |user|
257-
news_comment_added(user, comment).deliver_later
260+
news_comment_added(user, comment, users).deliver_later
258261
end
259262
end
260263

261264
# Builds a mail to user about a new message.
262-
def message_posted(user, message)
265+
def message_posted(user, message, recipients=nil)
263266
redmine_headers 'Project' => message.project.identifier,
264267
'Topic-Id' => (message.parent_id || message.id)
265268
@author = message.author
266269
message_id message
267270
references message.root
268271
@message = message
269272
@user = user
273+
@recipients = recipients
270274
@message_url = url_for(message.event_url)
271275
mail :to => user,
272276
:subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
@@ -282,18 +286,19 @@ def self.deliver_message_posted(message)
282286
users |= message.board.notified_watchers
283287

284288
users.each do |user|
285-
message_posted(user, message).deliver_later
289+
message_posted(user, message, users).deliver_later
286290
end
287291
end
288292

289293
# Builds a mail to user about a new wiki content.
290-
def wiki_content_added(user, wiki_content)
294+
def wiki_content_added(user, wiki_content, recipients=nil)
291295
redmine_headers 'Project' => wiki_content.project.identifier,
292296
'Wiki-Page-Id' => wiki_content.page.id
293297
@author = wiki_content.author
294298
message_id wiki_content
295299
@wiki_content = wiki_content
296300
@user = user
301+
@recipients = recipients
297302
@wiki_content_url = url_for(:controller => 'wiki', :action => 'show',
298303
:project_id => wiki_content.project,
299304
:id => wiki_content.page.title)
@@ -311,18 +316,19 @@ def wiki_content_added(user, wiki_content)
311316
def self.deliver_wiki_content_added(wiki_content)
312317
users = wiki_content.notified_users | wiki_content.page.wiki.notified_watchers | wiki_content.notified_mentions
313318
users.each do |user|
314-
wiki_content_added(user, wiki_content).deliver_later
319+
wiki_content_added(user, wiki_content, users).deliver_later
315320
end
316321
end
317322

318323
# Builds a mail to user about an update of the specified wiki content.
319-
def wiki_content_updated(user, wiki_content)
324+
def wiki_content_updated(user, wiki_content, recipients=nil)
320325
redmine_headers 'Project' => wiki_content.project.identifier,
321326
'Wiki-Page-Id' => wiki_content.page.id
322327
@author = wiki_content.author
323328
message_id wiki_content
324329
@wiki_content = wiki_content
325330
@user = user
331+
@recipients = recipients
326332
@wiki_content_url =
327333
url_for(:controller => 'wiki', :action => 'show',
328334
:project_id => wiki_content.project,
@@ -349,7 +355,7 @@ def self.deliver_wiki_content_updated(wiki_content)
349355
users |= wiki_content.notified_mentions
350356

351357
users.each do |user|
352-
wiki_content_updated(user, wiki_content).deliver_later
358+
wiki_content_updated(user, wiki_content, users).deliver_later
353359
end
354360
end
355361

@@ -368,8 +374,9 @@ def self.deliver_account_information(user, password)
368374
end
369375

370376
# Builds a mail to user about an account activation request.
371-
def account_activation_request(user, new_user)
377+
def account_activation_request(user, new_user, recipients=nil)
372378
@new_user = new_user
379+
@recipients = recipients
373380
@url = url_for(:controller => 'users', :action => 'index',
374381
:status => User::STATUS_REGISTERED,
375382
:sort_key => 'created_on', :sort_order => 'desc')
@@ -386,7 +393,7 @@ def self.deliver_account_activation_request(new_user)
386393
# Send the email to all active administrators
387394
users = User.active.where(:admin => true)
388395
users.each do |user|
389-
account_activation_request(user, new_user).deliver_later
396+
account_activation_request(user, new_user, users.to_a).deliver_later
390397
end
391398
end
392399

@@ -470,7 +477,8 @@ def self.deliver_register(user, token)
470477
# field: :field_mail,
471478
# value: address
472479
# ) => Mail::Message object
473-
def security_notification(user, sender, options={})
480+
def security_notification(user, sender, options={}, recipients=nil)
481+
@recipients = recipients
474482
@sender = sender
475483
redmine_headers 'Sender' => sender.login
476484
@message =
@@ -507,12 +515,13 @@ def self.deliver_security_notification(users, sender, options={})
507515
options[:remote_ip] ||= sender.remote_ip
508516

509517
Array.wrap(users).each do |user|
510-
security_notification(user, sender, options).deliver_later
518+
security_notification(user, sender, options, users).deliver_later
511519
end
512520
end
513521

514522
# Build a mail to user about application settings changes made by sender.
515-
def settings_updated(user, sender, changes, options={})
523+
def settings_updated(user, sender, changes, options={}, recipients=nil)
524+
@recipients = recipients
516525
@sender = sender
517526
redmine_headers 'Sender' => sender.login
518527
@changes = changes
@@ -539,7 +548,7 @@ def self.deliver_settings_updated(sender, changes, options={})
539548

540549
users = User.active.where(admin: true).to_a
541550
users.each do |user|
542-
settings_updated(user, sender, changes, options).deliver_later
551+
settings_updated(user, sender, changes, options, users).deliver_later
543552
end
544553
end
545554

0 commit comments

Comments
 (0)