From 45d17db8b69ba9defd4f9ddf6a25ab5d168e76e1 Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 30 May 2014 09:49:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=BB=99=E6=95=99=E5=B8=88?= =?UTF-8?q?=E5=8F=91=E8=AF=BE=E7=A8=8B=E7=95=99=E8=A8=80=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E6=A0=B9=E6=8D=AE=E6=95=99=E5=B8=88=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E5=8F=91=E9=80=81=E9=82=AE?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/mailer.rb | 5 ++++- app/models/user.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 8ecd58eb1..bb7a2424f 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -63,7 +63,10 @@ class Mailer < ActionMailer::Base #收件人邮箱 @recipients ||= [] @teachers.each do |teacher| - @recipients << teacher.user.mail + if teacher.user.notify_about? journals_for_message + @recipients << teacher.user.mail + end + end mail :to => @recipients, :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} " diff --git a/app/models/user.rb b/app/models/user.rb index edf703873..6fb975375 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -645,6 +645,7 @@ class User < Principal end end + # Return true if the user is allowed to do the specified action on a specific context # Action can be: # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') @@ -748,7 +749,36 @@ class User < Principal when News # always send to project members except when mail_notification is set to 'none' true + #判定用户是否接受留言提醒邮件 + when JournalsForMessage + ##如果是直接留言并且留言对象是Project并且Project类型是课程(课程留言) + if !object.at_user && object.jour.class.to_s.to_sym == :Project && object.jour.project_type == 1 + #根据用户设置邮件接收模式判定当前用户是否接受邮件提醒 + is_notified_project object.jour + end + + end + end + end + + #用户是否接收project的消息提醒 + def is_notified_project arg + if arg.is_a?(Project) + case mail_notification + when 'selected' + notified_projects_ids.include?(arg.id) + when 'only_my_events' + projects.include?(arg) + when 'only_assigned' + false + when 'only_owner' + course = Course.find_by_extra(arg.identifier) + course.teacher == self end + #勾选的项目或用户的项目 TODO:需改 + #notified_projects_ids.include?(arg) || projects.include?(arg) + else + false end end