From 5b0738a4cb0c7f5479e99e4481db848dd3264b84 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 29 Sep 2015 09:45:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8C=BF=E8=AF=84=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5:?= =?UTF-8?q?=E5=AE=9E=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 From f4e2f6c4ffe2a1c1c23f38bfb272402896c579c8 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 29 Sep 2015 10:03:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=88=AA=E6=AD=A2?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E6=B6=88=E6=81=AF=E6=97=B6=E9=97=B4=E8=B0=83?= =?UTF-8?q?=E6=95=B4=EF=BC=8C=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/homework_endtime.rake | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/tasks/homework_endtime.rake b/lib/tasks/homework_endtime.rake index 1a400dc32..d5d894122 100644 --- a/lib/tasks/homework_endtime.rake +++ b/lib/tasks/homework_endtime.rake @@ -3,16 +3,14 @@ namespace :homework_endtime do desc "send a message for Job deadline" task :message => :environment do - current_day = Date.today.day - homework_commons = HomeworkCommon.where("end_time >=?",Date.today) + contrast_time = Time.now - 86400 + homework_commons = HomeworkCommon.where("end_time >=? and end_time <=?",contrast_time, Time.now) homework_commons.each do |homework_common| if CourseMessage.where("course_message_type =? and course_message_id =? and status =?", "HomeworkCommon", homework_common.id, 1).first.nil? - if homework_common.end_time.day - Date.today.day < 2 && homework_common.end_time.year == Date.today.year - homework_common.course.student.each do |s| - homework_common.course_messages << CourseMessage.new(:user_id => s.student_id, :course_id => homework_common.course_id, :viewed => false, :status => true) - # 发送邮件通知 - Mailer.homework_endtime__added(homework_common, s.student_id).deliver - end + homework_common.course.student.each do |s| + homework_common.course_messages << CourseMessage.new(:user_id => s.student_id, :course_id => homework_common.course_id, :viewed => false, :status => true) + # 发送邮件通知 + Mailer.homework_endtime__added(homework_common, s.student_id).deliver end end end