diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 648108e47..06bc1fd38 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -3,7 +3,6 @@ class HomeworkCommonController < ApplicationController before_filter :find_course, :only => [:index,:new,:create] before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy] before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment] - after_create :send_mail def index homeworks = @course.homework_commons.order("created_at desc") @@ -184,10 +183,6 @@ class HomeworkCommonController < ApplicationController end end - def send_mail - Mailer.run.homework_added(self) - end - private #获取课程 def find_course diff --git a/app/models/document.rb b/app/models/document.rb index 6bfb4b8ff..37983d6d4 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -85,7 +85,7 @@ class Document < ActiveRecord::Base # Description 新创建的document要在公共表ForgeActivity中记录 def act_as_forge_activity self.forge_acts << ForgeActivity.new(:user_id => self.user_id, - :project_id => self.project_id) + :project_id => self.project_id) end def send_mail diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index ac10b2516..291c14563 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -18,7 +18,7 @@ class HomeworkCommon < ActiveRecord::Base :description => :description, :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} - after_create :act_as_activity + after_create :act_as_activity, :send_mail after_destroy :delete_kindeditor_assets def act_as_activity @@ -28,4 +28,9 @@ class HomeworkCommon < ActiveRecord::Base def delete_kindeditor_assets delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::HOMEWORKCOMMON end + + def send_mail + Mailer.run.homework_added(self) + end + end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 8d027da12..164e2b2ae 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -517,13 +517,46 @@ class Mailer < ActionMailer::Base end end + + + def forum_message_added(memo) + @memo = memo + redmine_headers 'Memo' => memo.id + @forum = memo.forum + @author = memo.author + @forum_url = url_for(:controller => 'forums', :action => 'show', :id => @forum.id) + @issue_author_url = url_for(user_activities_url(@author)) + recipients ||= [] + #将帖子创建者邮箱地址加入数组 + recipients << @forum.creator.mail + #回复人邮箱地址加入数组 + recipients << @author.mail + # cc = wiki_content.page.wiki.watcher_recipients - recipients + + @memo_url = url_for(forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))) + mail :to => recipients, + :subject => "[ #{l(:label_message_plural)} : #{memo.subject} #{l(:label_memo_create_succ)}]", + :filter => true + end + # Builds a Mail::Message object used to email recipients of a course when an homework are posted. # # Example: # attachments_added(attachments) => Mail::Message object # Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients - def homework_added - + def homework_added(homework_common) + @homework_common = homework_common + @author = homework_common.user + @homework_common_url = url_for(:controller => "homework_common", :action =>"index", :homework => @homework_common.id) + @homework_author_url = url_for(user_activities_url(@author)) + recipients ||= [] + #将帖子创建者邮箱地址加入数组 + @homework_common.course.members.each do |member| + recipients << member.user.mail + end + mail :to => recipients, + :subject => "[ #{l(:label_user_homework)} : #{homework_common.name} #{l(:label_memo_create_succ)}]", + :filter => true end # Builds a Mail::Message object used to email recipients of a news' project when a news item is added. diff --git a/app/views/mailer/forum_message_added.html.erb b/app/views/mailer/forum_message_added.html.erb index 58657d46b..ddd93c5b5 100644 --- a/app/views/mailer/forum_message_added.html.erb +++ b/app/views/mailer/forum_message_added.html.erb @@ -1,25 +1,25 @@ -
- - <%= link_to(h("#{@author.login}(#{@author.show_name})"), @issue_author_url , :style=>'color:#1b55a7; font-weight:bold;') %> - <%= l(:mail_issue_title_userin)%> - <%= link_to(h(@forum.name), @forum_url,:style=>'color:#1b55a7; font-weight:bold;') %> - - <%= l(:mail_issue_title_active)%>
+ <%= link_to(h("#{@author.login}(#{@author.show_name})"), @issue_author_url , :style=>'color:#1b55a7; font-weight:bold;') %> + + <%= l(:mail_issue_title_userin)%> + + <%= link_to(h(@forum.name), @forum_url,:style=>'color:#1b55a7; font-weight:bold;') %> + + <%= l(:mail_issue_title_active) %> +