Commit c5b13cc9897d9b7175722589e6f0c3b66ded143d
1 parent
652d955c
Exists in
master
and in
4 other branches
Remove more duplication in the Notify mailer
Showing
1 changed file
with
18 additions
and
14 deletions
Show diff stats
app/mailers/notify.rb
@@ -22,43 +22,38 @@ class Notify < ActionMailer::Base | @@ -22,43 +22,38 @@ class Notify < ActionMailer::Base | ||
22 | end | 22 | end |
23 | 23 | ||
24 | def note_wall_email(recipient_id, note_id) | 24 | def note_wall_email(recipient_id, note_id) |
25 | - recipient = User.find(recipient_id) | ||
26 | @note = Note.find(note_id) | 25 | @note = Note.find(note_id) |
27 | @project = @note.project | 26 | @project = @note.project |
28 | - mail(to: recipient.email, subject: subject) | 27 | + mail(to: recipient(recipient_id), subject: subject) |
29 | end | 28 | end |
30 | 29 | ||
31 | def note_commit_email(recipient_id, note_id) | 30 | def note_commit_email(recipient_id, note_id) |
32 | - recipient = User.find(recipient_id) | ||
33 | @note = Note.find(note_id) | 31 | @note = Note.find(note_id) |
34 | @commit = @note.target | 32 | @commit = @note.target |
35 | @commit = CommitDecorator.decorate(@commit) | 33 | @commit = CommitDecorator.decorate(@commit) |
36 | @project = @note.project | 34 | @project = @note.project |
37 | - mail(to: recipient.email, subject: subject("note for commit #{@commit.short_id}", @commit.title)) | 35 | + mail(to: recipient(recipient_id), subject: subject("note for commit #{@commit.short_id}", @commit.title)) |
38 | end | 36 | end |
39 | 37 | ||
40 | def note_merge_request_email(recipient_id, note_id) | 38 | def note_merge_request_email(recipient_id, note_id) |
41 | - recipient = User.find(recipient_id) | ||
42 | @note = Note.find(note_id) | 39 | @note = Note.find(note_id) |
43 | @merge_request = @note.noteable | 40 | @merge_request = @note.noteable |
44 | @project = @note.project | 41 | @project = @note.project |
45 | - mail(to: recipient.email, subject: subject("note for merge request !#{@merge_request.id}")) | 42 | + mail(to: recipient(recipient_id), subject: subject("note for merge request !#{@merge_request.id}")) |
46 | end | 43 | end |
47 | 44 | ||
48 | def note_issue_email(recipient_id, note_id) | 45 | def note_issue_email(recipient_id, note_id) |
49 | - recipient = User.find(recipient_id) | ||
50 | @note = Note.find(note_id) | 46 | @note = Note.find(note_id) |
51 | @issue = @note.noteable | 47 | @issue = @note.noteable |
52 | @project = @note.project | 48 | @project = @note.project |
53 | - mail(to: recipient.email, subject: subject("note for issue ##{@issue.id}")) | 49 | + mail(to: recipient(recipient_id), subject: subject("note for issue ##{@issue.id}")) |
54 | end | 50 | end |
55 | 51 | ||
56 | def note_wiki_email(recipient_id, note_id) | 52 | def note_wiki_email(recipient_id, note_id) |
57 | - recipient = User.find(recipient_id) | ||
58 | @note = Note.find(note_id) | 53 | @note = Note.find(note_id) |
59 | @wiki = @note.noteable | 54 | @wiki = @note.noteable |
60 | @project = @note.project | 55 | @project = @note.project |
61 | - mail(to: recipient.email, subject: subject("note for wiki")) | 56 | + mail(to: recipient(recipient_id), subject: subject("note for wiki")) |
62 | end | 57 | end |
63 | 58 | ||
64 | def new_merge_request_email(merge_request_id) | 59 | def new_merge_request_email(merge_request_id) |
@@ -68,23 +63,32 @@ class Notify < ActionMailer::Base | @@ -68,23 +63,32 @@ class Notify < ActionMailer::Base | ||
68 | end | 63 | end |
69 | 64 | ||
70 | def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) | 65 | def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) |
71 | - recipient = User.find(recipient_id) | ||
72 | @merge_request = MergeRequest.find(merge_request_id) | 66 | @merge_request = MergeRequest.find(merge_request_id) |
73 | @previous_assignee ||= User.find(previous_assignee_id) | 67 | @previous_assignee ||= User.find(previous_assignee_id) |
74 | @project = @merge_request.project | 68 | @project = @merge_request.project |
75 | - mail(to: recipient.email, subject: subject("changed merge request !#{@merge_request.id}", @merge_request.title)) | 69 | + mail(to: recipient(recipient_id), subject: subject("changed merge request !#{@merge_request.id}", @merge_request.title)) |
76 | end | 70 | end |
77 | 71 | ||
78 | def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id) | 72 | def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id) |
79 | - recipient = User.find(recipient_id) | ||
80 | @issue = Issue.find(issue_id) | 73 | @issue = Issue.find(issue_id) |
81 | @previous_assignee ||= User.find(previous_assignee_id) | 74 | @previous_assignee ||= User.find(previous_assignee_id) |
82 | @project = @issue.project | 75 | @project = @issue.project |
83 | - mail(to: recipient.email, subject: subject("changed issue ##{@issue.id}", @issue.title)) | 76 | + mail(to: recipient(recipient_id), subject: subject("changed issue ##{@issue.id}", @issue.title)) |
84 | end | 77 | end |
85 | 78 | ||
86 | private | 79 | private |
87 | 80 | ||
81 | + # Look up a User by their ID and return their email address | ||
82 | + # | ||
83 | + # recipient_id - User ID | ||
84 | + # | ||
85 | + # Returns a String containing the User's email address. | ||
86 | + def recipient(recipient_id) | ||
87 | + if recipient = User.find(recipient_id) | ||
88 | + recipient.email | ||
89 | + end | ||
90 | + end | ||
91 | + | ||
88 | # Formats arguments into a String suitable for use as an email subject | 92 | # Formats arguments into a String suitable for use as an email subject |
89 | # | 93 | # |
90 | # extra - Extra Strings to be inserted into the subject | 94 | # extra - Extra Strings to be inserted into the subject |