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 | 22 | end |
23 | 23 | |
24 | 24 | def note_wall_email(recipient_id, note_id) |
25 | - recipient = User.find(recipient_id) | |
26 | 25 | @note = Note.find(note_id) |
27 | 26 | @project = @note.project |
28 | - mail(to: recipient.email, subject: subject) | |
27 | + mail(to: recipient(recipient_id), subject: subject) | |
29 | 28 | end |
30 | 29 | |
31 | 30 | def note_commit_email(recipient_id, note_id) |
32 | - recipient = User.find(recipient_id) | |
33 | 31 | @note = Note.find(note_id) |
34 | 32 | @commit = @note.target |
35 | 33 | @commit = CommitDecorator.decorate(@commit) |
36 | 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 | 36 | end |
39 | 37 | |
40 | 38 | def note_merge_request_email(recipient_id, note_id) |
41 | - recipient = User.find(recipient_id) | |
42 | 39 | @note = Note.find(note_id) |
43 | 40 | @merge_request = @note.noteable |
44 | 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 | 43 | end |
47 | 44 | |
48 | 45 | def note_issue_email(recipient_id, note_id) |
49 | - recipient = User.find(recipient_id) | |
50 | 46 | @note = Note.find(note_id) |
51 | 47 | @issue = @note.noteable |
52 | 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 | 50 | end |
55 | 51 | |
56 | 52 | def note_wiki_email(recipient_id, note_id) |
57 | - recipient = User.find(recipient_id) | |
58 | 53 | @note = Note.find(note_id) |
59 | 54 | @wiki = @note.noteable |
60 | 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 | 57 | end |
63 | 58 | |
64 | 59 | def new_merge_request_email(merge_request_id) |
... | ... | @@ -68,23 +63,32 @@ class Notify < ActionMailer::Base |
68 | 63 | end |
69 | 64 | |
70 | 65 | def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) |
71 | - recipient = User.find(recipient_id) | |
72 | 66 | @merge_request = MergeRequest.find(merge_request_id) |
73 | 67 | @previous_assignee ||= User.find(previous_assignee_id) |
74 | 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 | 70 | end |
77 | 71 | |
78 | 72 | def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id) |
79 | - recipient = User.find(recipient_id) | |
80 | 73 | @issue = Issue.find(issue_id) |
81 | 74 | @previous_assignee ||= User.find(previous_assignee_id) |
82 | 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 | 77 | end |
85 | 78 | |
86 | 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 | 92 | # Formats arguments into a String suitable for use as an email subject |
89 | 93 | # |
90 | 94 | # extra - Extra Strings to be inserted into the subject | ... | ... |