实现给教师发课程留言邮件时根据教师设置判断是否发送邮件

president
z9hang 11 years ago
parent 866ae3a38d
commit 45d17db8b6

@ -63,8 +63,11 @@ class Mailer < ActionMailer::Base
#收件人邮箱 #收件人邮箱
@recipients ||= [] @recipients ||= []
@teachers.each do |teacher| @teachers.each do |teacher|
if teacher.user.notify_about? journals_for_message
@recipients << teacher.user.mail @recipients << teacher.user.mail
end end
end
mail :to => @recipients, mail :to => @recipients,
:subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} " :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} "
else else

@ -645,6 +645,7 @@ class User < Principal
end end
end end
# Return true if the user is allowed to do the specified action on a specific context # Return true if the user is allowed to do the specified action on a specific context
# Action can be: # Action can be:
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
@ -748,8 +749,37 @@ class User < Principal
when News when News
# always send to project members except when mail_notification is set to 'none' # always send to project members except when mail_notification is set to 'none'
true 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
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 end
def self.current=(user) def self.current=(user)

Loading…
Cancel
Save