base_mailer.rb 865 Bytes
Newer Older
Douwe Maan's avatar
Douwe Maan committed
1
class BaseMailer < ActionMailer::Base
2 3
  around_action :render_with_default_locale

4
  helper ApplicationHelper
5
  helper MarkupHelper
6 7 8 9

  attr_accessor :current_user
  helper_method :current_user, :can?

10 11
  default from:     proc { default_sender_address.format }
  default reply_to: proc { default_reply_to_address.format }
12 13

  def can?
14
    Ability.allowed?(current_user, action, subject)
15 16 17 18
  end

  private

19 20 21 22
  def render_with_default_locale(&block)
    Gitlab::I18n.with_default_locale(&block)
  end

23 24 25 26 27 28 29 30 31 32 33 34
  def default_sender_address
    address = Mail::Address.new(Gitlab.config.gitlab.email_from)
    address.display_name = Gitlab.config.gitlab.email_display_name
    address
  end

  def default_reply_to_address
    address = Mail::Address.new(Gitlab.config.gitlab.email_reply_to)
    address.display_name = Gitlab.config.gitlab.email_display_name
    address
  end
end