notify.rb 2.49 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
class Notify < ActionMailer::Base
2
  include Resque::Mailer
gitlabhq's avatar
gitlabhq committed
3 4
  add_template_helper ApplicationHelper

5
  default_url_options[:host] = EMAIL_OPTS["host"]
6 7
  default_url_options[:protocol] = -> { EMAIL_OPTS["protocol"] ? EMAIL_OPTS["protocol"] : "http" }.call

8
  default from: EMAIL_OPTS["from"]
gitlabhq's avatar
gitlabhq committed
9 10 11 12

  def new_user_email(user, password)
    @user = user
    @password = password
13
    mail(:to => @user['email'], :subject => "gitlab | Account was created for you")
gitlabhq's avatar
gitlabhq committed
14 15 16
  end

  def new_issue_email(issue)
17 18 19
    @issue = Issue.find(issue['id'])
    @user = @issue.assignee
    @project = @issue.project
gitlabhq's avatar
gitlabhq committed
20

21
    mail(:to => @user.email, :subject => "gitlab | New Issue was created")
gitlabhq's avatar
gitlabhq committed
22 23 24 25
  end

  def note_wall_email(user, note)
    @user = user
26 27 28
    @note = Note.find(note['id'])
    @project = @note.project
    mail(:to => @user['email'], :subject => "gitlab | #{@note.project.name} ")
gitlabhq's avatar
gitlabhq committed
29 30 31 32
  end

  def note_commit_email(user, note)
    @user = user
33 34
    @note = Note.find(note['id'])
    @project = @note.project
35
    @commit = @note.target
36
    mail(:to => @user['email'], :subject => "gitlab | note for commit | #{@note.project.name} ")
37 38 39 40
  end
  
  def note_merge_request_email(user, note)
    @user = user
41 42 43 44
    @note = Note.find(note['id'])
    @project = @note.project
    @merge_request = @note.noteable
    mail(:to => @user['email'], :subject => "gitlab | note for merge request | #{@note.project.name} ")
gitlabhq's avatar
gitlabhq committed
45 46 47 48
  end

  def note_issue_email(user, note)
    @user = user
49 50 51 52
    @note = Note.find(note['id'])
    @project = @note.project
    @issue = @note.noteable
    mail(:to => @user['email'], :subject => "gitlab | note for issue #{@issue.id} | #{@note.project.name} ")
gitlabhq's avatar
gitlabhq committed
53
  end
54 55
  
  def new_merge_request_email(merge_request)
56 57 58
    @merge_request = MergeRequest.find(merge_request['id'])
    @user = @merge_request.assignee
    @project = @merge_request.project
59
    mail(:to => @user.email, :subject => "gitlab | new merge request | #{@merge_request.title} ")
60
  end
61 62 63
  
  def changed_merge_request_email(user, merge_request)
    @user = user
64 65 66 67
    @merge_request = MergeRequest(merge_request.id)
    @assignee_was ||= User.find(@merge_request.assignee_id_was)
    @project = @merge_request.project
    mail(:to => @user['email'], :subject => "gitlab | merge request changed | #{@merge_request.title} ")
68
  end
69 70
  
  def changed_issue_email(user, issue)
71
    @issue = Issue.find(issue['id'])
72
    @user = user
73 74 75
    @assignee_was ||= User.find(@issue.assignee_id_was)
    @project = @issue.project
    mail(:to => @user['email'], :subject => "gitlab | changed issue | #{@issue.title} ")
76
  end
gitlabhq's avatar
gitlabhq committed
77
end