From 5b0738a4cb0c7f5479e99e4481db848dd3264b84 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 29 Sep 2015 09:45:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BF=E8=AF=84=E5=90=AF=E5=8A=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5:=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=A8=8B=E5=BA=8F=E5=8F=8A=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/mailer.rb | 30 ++++++++++++++----- .../send_mail_anonymous_comment_fail.html.erb | 10 +++++++ config/locales/mailers/zh.yml | 3 +- lib/tasks/homework_evaluation.rake | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 1b510b54a..52b7242dd 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -53,7 +53,7 @@ class Mailer < ActionMailer::Base recipients ||= [] course.members.each do |member| user = User.find(member.user_id) - @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" + # @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" @token = Token.get_token_from_user(user, 'autologin') @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) @anonymous_comment_close_name = homework_common.name @@ -62,7 +62,7 @@ class Mailer < ActionMailer::Base recipients << user.mail end mail :to => recipients, - :subject => @subject + :subject => "[#{l(:mail_homework)}#{homework_common.name}] #{l(:mail_anonymous_comment_open)}" end # 作业匿评关闭 @@ -71,7 +71,7 @@ class Mailer < ActionMailer::Base recipients ||= [] course.members.each do |member| user = User.find(member.user_id) - @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" + #@subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" @token = Token.get_token_from_user(user, 'autologin') @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) @anonymous_comment_close_name = homework_common.name @@ -80,12 +80,28 @@ class Mailer < ActionMailer::Base recipients << user.mail end mail :to => recipients, - :subject => @subject + :subject => "[#{l(:mail_homework)}#{homework_common.name}] #{l(:mail_anonymous_comment_open)}" end # 匿评失败给老师发送邮件通知 - def send_mail_anonymous_comment_fail - + def send_mail_anonymous_comment_fail(homework_common) + course = homework_common.course + recipients ||= [] + # 只给该课程的老师发送邮件提醒 + course.members.each do |member| + if m.user.allowed_to?(:as_teacher,course) + user = User.find(member.user_id) + #@subject = "[#{l(:mail_homework)} #{homework_common.name}] #{l(:mail_anonymous_comment_failed)}" + @token = Token.get_token_from_user(user, 'autologin') + @anonymous_comment_fail_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @anonymous_comment_fail_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipients << user.mail + end + end + mail :to => recipients, + :subject => "[#{l(:mail_homework)} #{homework_common.name}] #{l(:mail_anonymous_comment_failed)}" end # author: alan @@ -269,7 +285,7 @@ class Mailer < ActionMailer::Base #收件人邮箱 recipient = user.mail mail :to => recipient, - :subject => "#{l(:mail_homework)}#{homework_common.name}#{l(:mail_homework_endtime)} " + :subject => @subject end # 公共讨论区发帖、回帖添加邮件发送信息 diff --git a/app/views/mailer/send_mail_anonymous_comment_fail.html.erb b/app/views/mailer/send_mail_anonymous_comment_fail.html.erb index e69de29bb..60f86ba18 100644 --- a/app/views/mailer/send_mail_anonymous_comment_fail.html.erb +++ b/app/views/mailer/send_mail_anonymous_comment_fail.html.erb @@ -0,0 +1,10 @@ +
+ +
+
\ No newline at end of file diff --git a/config/locales/mailers/zh.yml b/config/locales/mailers/zh.yml index c2dd5c7e0..1d432cbff 100644 --- a/config/locales/mailers/zh.yml +++ b/config/locales/mailers/zh.yml @@ -27,4 +27,5 @@ zh: mail_homework_endtime: "作业截止时间快到了!" mail_homework: "作业:" mail_anonymous_comment_close: "作业匿评已经关闭!" - mail_anonymous_comment_open: "作业匿评已经开启!" \ No newline at end of file + mail_anonymous_comment_open: "作业匿评已经开启!" + mail_anonymous_comment_failed: "作业匿评开启失败!" \ No newline at end of file diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index c8f9408a0..b4753f9b2 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -40,7 +40,7 @@ namespace :homework_evaluation do end end # 邮件通知 - # Mailer.send_mail_anonymous_comment_close(homework_common).deliver + Mailer.send_mail_anonymous_comment_fail(homework_common).deliver end end end