Fix send email language error.

This commit is contained in:
BoHung Chiu 2020-05-04 23:14:02 +08:00
parent 69682e9b79
commit 8ae48585ed
2 changed files with 16 additions and 16 deletions

View File

@ -170,14 +170,14 @@ class Admin::AnnouncementsController < OrbitAdminController
if user_can_approve? if user_can_approve?
bulletin.approved = true bulletin.approved = true
else else
send_notification_mail_to_managers(bulletin,"approval") send_notification_mail_to_managers(bulletin,"approval",I18n.locale)
end end
else else
bulletin.approved = true bulletin.approved = true
end end
bulletin.save bulletin.save
build_email(bulletin) build_email(bulletin,I18n.locale)
redirect_to params['referer_url'] redirect_to params['referer_url']
end end
@ -192,7 +192,7 @@ class Admin::AnnouncementsController < OrbitAdminController
bulletin.rejected = true bulletin.rejected = true
bulletin.reapproval = false bulletin.reapproval = false
bulletin.rejection_reason = params["reason"] bulletin.rejection_reason = params["reason"]
send_rejection_email(bulletin) send_rejection_email(bulletin,I18n.locale)
end end
bulletin.save bulletin.save
redirect_to admin_announcements_path redirect_to admin_announcements_path
@ -233,11 +233,11 @@ class Admin::AnnouncementsController < OrbitAdminController
if bulletin.rejected if bulletin.rejected
bulletin.reapproval = true bulletin.reapproval = true
bulletin.save bulletin.save
send_notification_mail_to_managers(bulletin,"reapproval") send_notification_mail_to_managers(bulletin,"reapproval",I18n.locale)
else else
bulletin.save bulletin.save
end end
build_email(bulletin) build_email(bulletin,I18n.locale)
now_bulletin_page = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]) now_bulletin_page = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil])
.order_by(sort).map(&:id).map.with_index.select{|v,i| v==bulletin.id}[0][1] rescue nil .order_by(sort).map(&:id).map.with_index.select{|v,i| v==bulletin.id}[0][1] rescue nil
now_bulletin_page = now_bulletin_page.nil? ? 0 : ((now_bulletin_page+1).to_f/10).ceil now_bulletin_page = now_bulletin_page.nil? ? 0 : ((now_bulletin_page+1).to_f/10).ceil
@ -331,7 +331,7 @@ class Admin::AnnouncementsController < OrbitAdminController
render :json=>{'destroy'=>bulletin.id.to_s} render :json=>{'destroy'=>bulletin.id.to_s}
end end
def build_email(bulletin) def build_email(bulletin,locale)
if bulletin.email_sent and !bulletin.email_addresses.blank? if bulletin.email_sent and !bulletin.email_addresses.blank?
if bulletin.email.nil? if bulletin.email.nil?
email = Email.new email = Email.new
@ -343,14 +343,14 @@ class Admin::AnnouncementsController < OrbitAdminController
is_sent = bulletin.email.is_sent is_sent = bulletin.email.is_sent
is_sent = !params[:resend_mail].eql?("true") if !params[:resend_mail].blank? is_sent = !params[:resend_mail].eql?("true") if !params[:resend_mail].blank?
doc = Nokogiri::HTML(bulletin.title) doc = Nokogiri::HTML(bulletin.title_translations[locale])
title = doc.text.empty? ? 'no content' : doc.text title = doc.text.empty? ? 'no content' : doc.text
bulletin.email.update_attributes( bulletin.email.update_attributes(
:create_user=>current_user, :create_user=>current_user,
:mail_sentdate=>bulletin.email_sentdate, :mail_sentdate=>bulletin.email_sentdate,
:module_app=>@module_app, :module_app=>@module_app,
:mail_lang => I18n.locale, :mail_lang => locale,
:mail_to=>bulletin.email_addresses, :mail_to=>bulletin.email_addresses,
:mail_subject=>title, :mail_subject=>title,
:template=>'announcements/email', :template=>'announcements/email',

View File

@ -119,21 +119,21 @@ module Admin::AnnouncementsHelper
anns.save anns.save
end end
def send_rejection_email(announcement) def send_rejection_email(announcement,locale)
user = User.find(announcement.create_user_id) rescue nil user = User.find(announcement.create_user_id) rescue nil
if !user.nil? if !user.nil?
email = user.member_profile.email email = user.member_profile.email
if !email.nil? && email != "" if !email.nil? && email != ""
url = "http://#{request.host_with_port}/admin/announcements/#{announcement.id}/edit" url = "http://#{request.host_with_port}/admin/announcements/#{announcement.id}/edit"
datatosend = "<h3>Hello #{user.name},</h3><p>#{current_user.name} #{t("announcement.rejected_annoucement")} : #{announcement.rejection_reason} <a href='#{url}'> #{t("announcement.click_here_to_see")}</a></p>" datatosend = "<h3>Hello #{user.name},</h3><p>#{current_user.name} #{t("announcement.rejected_annoucement")} : #{announcement.rejection_reason} <a href='#{url}'> #{t("announcement.click_here_to_see")}</a></p>"
mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected公告未通過 : #{announcement.title}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend}) mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected公告未通過 : #{announcement.title_translations[locale]}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend})
mail.save mail.save
mail.deliver rescue nil mail.deliver rescue nil
end end
end end
end end
def send_notification_mail_to_managers(announcement, type) def send_notification_mail_to_managers(announcement, type, locale)
users = [] users = []
if @announcement_setting.email_to.include?("managers") if @announcement_setting.email_to.include?("managers")
authorizations = Authorization.where(:module_app_id => @module_app.id) authorizations = Authorization.where(:module_app_id => @module_app.id)
@ -155,22 +155,22 @@ module Admin::AnnouncementsHelper
users.each do |user| users.each do |user|
email = user.member_profile.email email = user.member_profile.email
if !email.nil? && email != "" if !email.nil? && email != ""
send_email(user.name, email, announcement, type) send_email(user.name, email, announcement, type, locale)
# sleep(1) # sleep(1)
end end
end end
end end
def send_email(name, useremail, announcement, type) def send_email(name, useremail, announcement, type, locale)
url = "http://#{request.host_with_port}/admin/announcements?url=#{page_for_bulletin(announcement).sub("http://" + request.host_with_port, "")}&id=#{announcement.id}" url = "http://#{request.host_with_port}/admin/announcements?url=#{page_for_bulletin(announcement).sub("http://" + request.host_with_port, "")}&id=#{announcement.id}"
case type case type
when "approval" when "approval"
datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.submitted_new_announcement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>" datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.submitted_new_announcement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title_translations[locale]} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>"
when "reapproval" when "reapproval"
datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.updated_annoucement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>" datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.updated_annoucement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title_translations[locale]} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>"
end end
email = Email.new(:mail_to => useremail, :mail_subject => " #{t("announcement.announcement_subject")} : #{announcement.title}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend}) email = Email.new(:mail_to => useremail, :mail_subject => " #{t("announcement.announcement_subject")} : #{announcement.title_translations[locale]}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend})
email.save email.save
email.deliver rescue nil email.deliver rescue nil
end end