2011-03-10 21:48:15 +00:00
|
|
|
class UserMailer < ActionMailer::Base
|
2013-11-26 17:41:59 +00:00
|
|
|
add_template_helper ActivityFeedsHelper
|
2013-11-26 17:57:02 +00:00
|
|
|
add_template_helper CommitHelper
|
2013-11-26 17:41:59 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
default from: "\"#{APP_CONFIG['project_name']}\" <#{APP_CONFIG['do-not-reply-email']}>"
|
|
|
|
default_url_options.merge!(protocol: 'https') if APP_CONFIG['mailer_https_url']
|
2011-03-10 21:48:15 +00:00
|
|
|
|
2012-06-16 23:51:02 +01: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(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: email_with_name(user, user.email),
|
|
|
|
subject: I18n.t("notifications.subjects.new_user_notification",
|
|
|
|
project_name: APP_CONFIG['project_name'])
|
2013-03-14 15:31:13 +00:00
|
|
|
) do |format|
|
2011-12-26 15:48:57 +00:00
|
|
|
format.html
|
|
|
|
end
|
2012-09-11 09:36:33 +01:00
|
|
|
end
|
2011-12-26 15:48:57 +00:00
|
|
|
|
|
|
|
def new_comment_notification(comment, user)
|
2013-03-14 14:55:59 +00:00
|
|
|
@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')
|
2013-03-14 14:55:59 +00:00
|
|
|
mail(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: email_with_name(user, user.email),
|
|
|
|
subject: subject,
|
|
|
|
from: email_with_name(comment.user)
|
2013-03-14 14:55:59 +00:00
|
|
|
) do |format|
|
2011-12-26 15:48:57 +00:00
|
|
|
format.html
|
|
|
|
end
|
2012-09-11 09:36:33 +01:00
|
|
|
end
|
2011-12-26 15:48:57 +00:00
|
|
|
|
|
|
|
def new_issue_notification(issue, user)
|
2013-03-14 14:55:59 +00:00
|
|
|
@user, @issue = user, issue
|
|
|
|
mail(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: email_with_name(user, user.email),
|
|
|
|
subject: subject_for_issue(issue, true),
|
|
|
|
from: email_with_name(issue.user)
|
2013-03-14 14:55:59 +00:00
|
|
|
) do |format|
|
2011-12-26 15:48:57 +00:00
|
|
|
format.html
|
|
|
|
end
|
2012-09-11 09:36:33 +01:00
|
|
|
end
|
2011-12-26 15:48:57 +00:00
|
|
|
|
|
|
|
def issue_assign_notification(issue, user)
|
2013-04-09 13:57:29 +01:00
|
|
|
@issue = issue
|
2013-03-14 15:31:13 +00:00
|
|
|
mail(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: email_with_name(user, user.email),
|
|
|
|
subject: subject_for_issue(@issue)
|
2013-03-14 15:31:13 +00:00
|
|
|
) 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-02-10 16:33:16 +00:00
|
|
|
|
2012-09-16 18:29:45 +01:00
|
|
|
def build_list_notification(build_list, user)
|
2013-11-26 17:21:50 +00:00
|
|
|
set_locale user
|
2012-09-17 17:17:43 +01:00
|
|
|
@user, @build_list = user, build_list
|
2012-09-16 18:29:45 +01:00
|
|
|
|
2013-07-01 13:20:38 +01:00
|
|
|
subject = "[№ #{build_list.id}] "
|
2012-09-16 19:02:28 +01:00
|
|
|
subject << (build_list.project ? build_list.project.name_with_owner : t("layout.projects.unexisted_project"))
|
2012-09-18 13:03:10 +01:00
|
|
|
subject << " - #{build_list.human_status} "
|
2014-01-21 04:51:49 +00:00
|
|
|
subject << I18n.t("notifications.subjects.for_arch", arch: @build_list.arch.name)
|
2013-03-14 14:55:59 +00:00
|
|
|
mail(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: email_with_name(user, user.email),
|
|
|
|
subject: subject,
|
|
|
|
from: email_with_name(build_list.publisher || build_list.user)
|
2013-03-14 14:55:59 +00:00
|
|
|
) do |format|
|
2012-09-16 18:29:45 +01:00
|
|
|
format.html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-11 21:28:32 +00:00
|
|
|
def metadata_regeneration_notification(platform, user)
|
|
|
|
set_locale user
|
|
|
|
@user, @platform = user, platform
|
|
|
|
|
|
|
|
subject = "[#{platform.name}] "
|
|
|
|
subject << I18n.t("notifications.subjects.metadata_regeneration", status: I18n.t("layout.regeneration_statuses.last_regenerated_statuses.#{platform.human_regeneration_status}"))
|
|
|
|
mail(
|
|
|
|
to: email_with_name(user, user.email),
|
|
|
|
subject: subject,
|
|
|
|
from: email_with_name(platform.owner)
|
|
|
|
) do |format|
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-10 16:33:16 +00:00
|
|
|
def invite_approve_notification(register_request)
|
2013-11-26 17:21:50 +00:00
|
|
|
set_locale register_request
|
2012-02-10 16:33:16 +00:00
|
|
|
@register_request = register_request
|
2013-03-14 15:31:13 +00:00
|
|
|
mail(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: register_request.email,
|
|
|
|
subject: I18n.t("notifications.subjects.invite_approve_notification")
|
2013-03-14 15:31:13 +00:00
|
|
|
) do |format|
|
2012-09-10 12:08:53 +01:00
|
|
|
format.html
|
|
|
|
end
|
2012-09-11 09:36:33 +01:00
|
|
|
end
|
2013-03-13 12:11:42 +00:00
|
|
|
|
2013-11-26 17:21:50 +00:00
|
|
|
def git_delete_branch_notification(user, options)
|
|
|
|
set_locale user
|
|
|
|
mail(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: user.email,
|
|
|
|
subject: I18n.t('notifications.subjects.update_code', project_name: "#{options[:project_owner]}/#{options[:project_name]}")
|
2013-11-26 17:21:50 +00:00
|
|
|
) do |format|
|
2014-01-21 04:51:49 +00:00
|
|
|
format.html { render 'git_delete_branch_notification', locals: options }
|
2013-11-26 17:21:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def git_new_push_notification(user, options)
|
|
|
|
set_locale user
|
|
|
|
mail(
|
2014-01-21 04:51:49 +00:00
|
|
|
to: user.email,
|
|
|
|
subject: I18n.t('notifications.subjects.update_code', project_name: "#{options[:project_owner]}/#{options[:project_name]}")
|
2013-11-26 17:21:50 +00:00
|
|
|
) do |format|
|
2014-01-21 04:51:49 +00:00
|
|
|
format.html { render 'git_new_push_notification', locals: options }
|
2013-11-26 17:21:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-13 12:11:42 +00:00
|
|
|
protected
|
|
|
|
|
2013-11-26 17:21:50 +00:00
|
|
|
def set_locale(user)
|
|
|
|
I18n.locale = user.language if user.language
|
|
|
|
end
|
|
|
|
|
2013-03-14 15:31:13 +00:00
|
|
|
def email_with_name(user, email = APP_CONFIG['do-not-reply-email'])
|
2013-03-14 17:40:32 +00:00
|
|
|
"\"#{user.user_appeal}\" <#{email}>"
|
2013-03-14 14:55:59 +00:00
|
|
|
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
|