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,10 +749,39 @@ 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 + def self.current=(user) Thread.current[:current_user] = user end