rosa-build/app/mailers/user_mailer.rb

93 lines
2.8 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
2011-09-15 18:56:20 +01:00
2011-03-10 21:48:15 +00:00
class UserMailer < ActionMailer::Base
2013-03-14 15:31:13 +00:00
default :from => "#{APP_CONFIG['project_name']} <#{APP_CONFIG['do-not-reply-email']}>"
2012-09-24 14:02:21 +01:00
default_url_options.merge!(:protocol => 'https') if APP_CONFIG['mailer_https_url']
2011-03-10 21:48:15 +00:00
include Resque::Mailer # send email async
2012-06-09 13:52:29 +01:00
2011-03-10 21:48:15 +00:00
def new_user_notification(user)
@user = user
2013-03-14 15:31:13 +00:00
mail(
:to => email_with_name(user, user.email),
:subject => I18n.t("notifications.subjects.new_user_notification",
:project_name => APP_CONFIG['project_name'])
) do |format|
format.html
end
2012-09-11 09:36:33 +01:00
end
def new_comment_notification(comment, user)
@user, @comment = user, comment
2013-03-13 12:11:42 +00:00
subject = @comment.issue_comment? ? subject_for_issue(@comment.commentable) :
I18n.t('notifications.subjects.new_commit_comment_notification')
mail(
2013-03-14 15:31:13 +00:00
:to => email_with_name(user, user.email),
:subject => subject,
2013-03-14 15:31:13 +00:00
:from => email_with_name(comment.user)
) do |format|
format.html
end
2012-09-11 09:36:33 +01:00
end
def new_issue_notification(issue, user)
@user, @issue = user, issue
mail(
2013-03-14 15:31:13 +00:00
:to => email_with_name(user, user.email),
:subject => subject_for_issue(issue, true),
2013-03-14 15:31:13 +00:00
:from => email_with_name(issue.user)
) do |format|
format.html
end
2012-09-11 09:36:33 +01:00
end
def issue_assign_notification(issue, user)
@user, @issue = user, issue
2013-03-14 15:31:13 +00:00
mail(
:to => email_with_name(user, user.email),
:subject => subject_for_issue(@issue)
) do |format|
2011-03-31 13:21:43 +01:00
format.html
2011-03-30 23:11:37 +01:00
end
2012-09-11 09:36:33 +01:00
end
2012-09-16 18:29:45 +01:00
def build_list_notification(build_list, user)
I18n.locale = user.language if user.language
@user, @build_list = user, build_list
2012-09-16 18:29:45 +01:00
subject = "[№ #{build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")}] "
2012-09-16 19:02:28 +01:00
subject << (build_list.project ? build_list.project.name_with_owner : t("layout.projects.unexisted_project"))
subject << " - #{build_list.human_status} "
subject << I18n.t("notifications.subjects.for_arch", :arch => @build_list.arch.name)
mail(
2013-03-14 15:31:13 +00:00
:to => email_with_name(user, user.email),
:subject => subject,
2013-03-14 15:31:13 +00:00
:from => email_with_name(build_list.user)
) do |format|
2012-09-16 18:29:45 +01:00
format.html
end
end
def invite_approve_notification(register_request)
I18n.locale = register_request.language if register_request.language
@register_request = register_request
2013-03-14 15:31:13 +00:00
mail(
:to => register_request.email,
:subject => I18n.t("notifications.subjects.invite_approve_notification")
) do |format|
format.html
end
2012-09-11 09:36:33 +01:00
end
2013-03-13 12:11:42 +00:00
protected
2013-03-14 15:31:13 +00:00
def email_with_name(user, email = APP_CONFIG['do-not-reply-email'])
"#{user.user_appeal} <#{email}>"
end
2013-03-13 12:14:24 +00:00
def subject_for_issue(issue, new_issue = false)
subject = new_issue ? '' : 'Re: '
2013-03-13 12:11:42 +00:00
subject << "[#{issue.project.name}] #{issue.title} (##{issue.serial_id})"
end
2012-09-11 09:36:33 +01:00
end