diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-19 22:00:41 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-19 22:00:41 +0400 |
commit | a3cdaeef6654edac27a07fac8189c581977827e5 (patch) | |
tree | 4b73e8662e5e03bbe19d2cf3ebb7db4b50f5ec55 /app/mailers | |
parent | 52d3fa191f570ddfad4549e848f45d90327e3df6 (diff) |
refactor emails a bit. Add email on ssh key creation
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/emails/issues.rb | 25 | ||||
-rw-r--r-- | app/mailers/emails/merge_requests.rb | 16 | ||||
-rw-r--r-- | app/mailers/emails/notes.rb | 31 | ||||
-rw-r--r-- | app/mailers/emails/projects.rb | 18 | ||||
-rw-r--r-- | app/mailers/notify.rb | 113 |
5 files changed, 99 insertions, 104 deletions
diff --git a/app/mailers/emails/issues.rb b/app/mailers/emails/issues.rb new file mode 100644 index 00000000000..5b69886f9ce --- /dev/null +++ b/app/mailers/emails/issues.rb @@ -0,0 +1,25 @@ +module Emails + module Issues + def new_issue_email(issue_id) + @issue = Issue.find(issue_id) + @project = @issue.project + mail(to: @issue.assignee_email, subject: subject("new issue ##{@issue.id}", @issue.title)) + end + + def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id) + @issue = Issue.find(issue_id) + @previous_assignee ||= User.find(previous_assignee_id) + @project = @issue.project + mail(to: recipient(recipient_id), subject: subject("changed issue ##{@issue.id}", @issue.title)) + end + + def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id) + @issue = Issue.find issue_id + @issue_status = status + @project = @issue.project + @updated_by = User.find updated_by_user_id + mail(to: recipient(recipient_id), + subject: subject("changed issue ##{@issue.id}", @issue.title)) + end + end +end diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb new file mode 100644 index 00000000000..35890460e05 --- /dev/null +++ b/app/mailers/emails/merge_requests.rb @@ -0,0 +1,16 @@ +module Emails + module MergeRequests + def new_merge_request_email(merge_request_id) + @merge_request = MergeRequest.find(merge_request_id) + @project = @merge_request.project + mail(to: @merge_request.assignee_email, subject: subject("new merge request !#{@merge_request.id}", @merge_request.title)) + end + + def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) + @merge_request = MergeRequest.find(merge_request_id) + @previous_assignee ||= User.find(previous_assignee_id) + @project = @merge_request.project + mail(to: recipient(recipient_id), subject: subject("changed merge request !#{@merge_request.id}", @merge_request.title)) + end + end +end diff --git a/app/mailers/emails/notes.rb b/app/mailers/emails/notes.rb new file mode 100644 index 00000000000..de51debfeb5 --- /dev/null +++ b/app/mailers/emails/notes.rb @@ -0,0 +1,31 @@ +module Emails + module Notes + def note_commit_email(recipient_id, note_id) + @note = Note.find(note_id) + @commit = @note.noteable + @commit = CommitDecorator.decorate(@commit) + @project = @note.project + mail(to: recipient(recipient_id), subject: subject("note for commit #{@commit.short_id}", @commit.title)) + end + + def note_issue_email(recipient_id, note_id) + @note = Note.find(note_id) + @issue = @note.noteable + @project = @note.project + mail(to: recipient(recipient_id), subject: subject("note for issue ##{@issue.id}")) + end + + def note_merge_request_email(recipient_id, note_id) + @note = Note.find(note_id) + @merge_request = @note.noteable + @project = @note.project + mail(to: recipient(recipient_id), subject: subject("note for merge request !#{@merge_request.id}")) + end + + def note_wall_email(recipient_id, note_id) + @note = Note.find(note_id) + @project = @note.project + mail(to: recipient(recipient_id), subject: subject("note on wall")) + end + end +end diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb new file mode 100644 index 00000000000..dcd894bb8ef --- /dev/null +++ b/app/mailers/emails/projects.rb @@ -0,0 +1,18 @@ +module Emails + module Projects + def project_access_granted_email(user_project_id) + @users_project = UsersProject.find user_project_id + @project = @users_project.project + mail(to: @users_project.user.email, + subject: subject("access to project was granted")) + end + + + def project_was_moved_email(user_project_id) + @users_project = UsersProject.find user_project_id + @project = @users_project.project + mail(to: @users_project.user.email, + subject: subject("project was moved")) + end + end +end diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 08f7e01aab1..a5aa97ab13d 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -1,4 +1,8 @@ class Notify < ActionMailer::Base + include Emails::Issues + include Emails::MergeRequests + include Emails::Notes + include Emails::Projects add_template_helper ApplicationHelper add_template_helper GitlabMarkdownHelper @@ -15,116 +19,17 @@ class Notify < ActionMailer::Base delay_for(2.seconds) end - - # - # Issue - # - - def new_issue_email(issue_id) - @issue = Issue.find(issue_id) - @project = @issue.project - mail(to: @issue.assignee_email, subject: subject("new issue ##{@issue.id}", @issue.title)) - end - - def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id) - @issue = Issue.find(issue_id) - @previous_assignee ||= User.find(previous_assignee_id) - @project = @issue.project - mail(to: recipient(recipient_id), subject: subject("changed issue ##{@issue.id}", @issue.title)) - end - - def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id) - @issue = Issue.find issue_id - @issue_status = status - @project = @issue.project - @updated_by = User.find updated_by_user_id - mail(to: recipient(recipient_id), - subject: subject("changed issue ##{@issue.id}", @issue.title)) - end - - - - # - # Merge Request - # - - def new_merge_request_email(merge_request_id) - @merge_request = MergeRequest.find(merge_request_id) - @project = @merge_request.project - mail(to: @merge_request.assignee_email, subject: subject("new merge request !#{@merge_request.id}", @merge_request.title)) - end - - def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) - @merge_request = MergeRequest.find(merge_request_id) - @previous_assignee ||= User.find(previous_assignee_id) - @project = @merge_request.project - mail(to: recipient(recipient_id), subject: subject("changed merge request !#{@merge_request.id}", @merge_request.title)) - end - - - - # - # Note - # - - def note_commit_email(recipient_id, note_id) - @note = Note.find(note_id) - @commit = @note.noteable - @commit = CommitDecorator.decorate(@commit) - @project = @note.project - mail(to: recipient(recipient_id), subject: subject("note for commit #{@commit.short_id}", @commit.title)) - end - - def note_issue_email(recipient_id, note_id) - @note = Note.find(note_id) - @issue = @note.noteable - @project = @note.project - mail(to: recipient(recipient_id), subject: subject("note for issue ##{@issue.id}")) - end - - def note_merge_request_email(recipient_id, note_id) - @note = Note.find(note_id) - @merge_request = @note.noteable - @project = @note.project - mail(to: recipient(recipient_id), subject: subject("note for merge request !#{@merge_request.id}")) - end - - def note_wall_email(recipient_id, note_id) - @note = Note.find(note_id) - @project = @note.project - mail(to: recipient(recipient_id), subject: subject("note on wall")) - end - - - # - # Project - # - - def project_access_granted_email(user_project_id) - @users_project = UsersProject.find user_project_id - @project = @users_project.project - mail(to: @users_project.user.email, - subject: subject("access to project was granted")) - end - - - def project_was_moved_email(user_project_id) - @users_project = UsersProject.find user_project_id - @project = @users_project.project - mail(to: @users_project.user.email, - subject: subject("project was moved")) - end - - # - # User - # - def new_user_email(user_id, password) @user = User.find(user_id) @password = password mail(to: @user.email, subject: subject("Account was created for you")) end + def new_ssh_key_email(key_id) + @key = Key.find(key_id) + @user = @key.user + mail(to: @user.email, subject: subject("SSH key was added to your account")) + end private |