diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 7be526f41..e0726599b 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -45,6 +45,7 @@ class Mailer < ActionMailer::Base MailerProxy.new(self) end + # author: alan # 发送邀请未注册用户加入项目邮件 # 功能: 在加入项目的同时自动注册用户 def send_invite_in_project(email, project, invitor) @@ -88,7 +89,7 @@ class Mailer < ActionMailer::Base date_from = "#{date_from} 17:59:59" date_to = "#{date_to} 17:59:59" - + # 生成token用于直接点击登录 @user = user @token = Token.get_token_from_user(user, 'autologin') @@ -100,16 +101,14 @@ class Mailer < ActionMailer::Base course_ids = courses.map {|course| course.id}.join(",") # 查询user的缺陷,包括发布的,跟踪的以及被指派的缺陷 - # sql = "select DISTINCT i.* from issues i, watchers w - # where (i.assigned_to_id = #{user.id} or i.author_id = #{user.id} - # or (w.watchable_type = 'Issue' and w.watchable_id = i.id and w.user_id = #{user.id})) - # and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc" - sql = "select DISTINCT i.* from issues i where (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc" + sql = "select * from members m, issues i where i.project_id = m.project_id and m.user_id='#{user.id}' + and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc" @issues = Issue.find_by_sql(sql) # @bids 查询课程作业,包括老师发布的作业,以及user提交作业 # @attachments查询课程课件更新 @attachments ||= [] + @bids ||= [] # 老师发布的作业 unless courses.first.nil? @@ -118,15 +117,15 @@ class Mailer < ActionMailer::Base for i in 0..count do bids = courses[i].homeworks.where("bids.created_on between '#{date_from}' and '#{date_to}'").order("bids.created_on desc") attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'").order('attachments.created_on DESC') - @bids += bids if bids.count > 0 - @attachments += attachments if attachments.count > 0 + @bids += bids if bids.count > 0 + @attachments += attachments if attachments.count > 0 end end # user 提交的作业 @homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc") # 查询user在课程。项目中发布的讨论帖子 - messages = Message.find_by_sql("select DISTINCT * from messages where (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + messages = Message.find_by_sql("select DISTINCT * from messages where author_id = #{user.id} and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") @course_messages ||= [] @project_messages ||= [] unless messages.first.nil? @@ -141,9 +140,9 @@ class Mailer < ActionMailer::Base # 查询user在课程中发布的通知,项目中发的新闻 @course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.course_id in (#{course_ids}) - and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] @project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids}) - and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] # 查询user在课程及个人中留言 @course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT * from journals_for_messages where @@ -160,11 +159,11 @@ class Mailer < ActionMailer::Base has_content = [@issues,@homeworks,@course_messages,@project_messages,@course_news,@project_news, @course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o| - !o.empty? - } + !o.empty? + } mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}" #有内容才发,没有不发 - mail :to => user.mail, :subject => subject if has_content + mail :to => user.mail,:subject => subject if has_content end # 公共讨论区发帖、回帖添加邮件发送信息 @@ -187,8 +186,8 @@ class Mailer < ActionMailer::Base :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 the added journals for message. + # 留言分为直接留言,和对留言人留言的回复 # 字段说明在JournalsForMessage.rb # 直接留言后 reply_id,m_parent_id 为空,相对应的at_user取值为nil @@ -276,11 +275,11 @@ class Mailer < ActionMailer::Base @token = Token.get_token_from_user(user, 'autologin') @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :token => @token.value) - # edit - @issue_author_url = url_for(user_activities_url(@author,:token => @token.value)) - @project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id, :token => @token.value) + # edit + @issue_author_url = url_for(user_activities_url(@author,:token => @token.value)) + @project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id, :token => @token.value) - @user_url = url_for(my_account_url(user,:token => @token.value)) + @user_url = url_for(my_account_url(user,:token => @token.value)) subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}" @@ -288,13 +287,13 @@ class Mailer < ActionMailer::Base :subject => subject, :filter => true end - # issue.attachments.each do |attach| - # attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}") - # end - # cc = issue.watcher_recipients - recipients - #mail.attachments['test'] = File.read("#{RAILS.root}/files/2015/01/150114094010_libegl.dll") + # issue.attachments.each do |attach| + # attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}") + # end + # cc = issue.watcher_recipients - recipients + #mail.attachments['test'] = File.read("#{RAILS.root}/files/2015/01/150114094010_libegl.dll") + - # Builds a Mail::Message object used to email recipients of the edited issue. @@ -323,13 +322,13 @@ class Mailer < ActionMailer::Base @project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id, :token => @token.value) @user_url = url_for(my_account_url(user,:token => @token.value)) - @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}", :token => @token.value) + @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}", :token => @token.value) s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] " s << "(#{issue.status.name}) " if journal.new_value_for('status_id') s << issue.subject @issue = issue @journal = journal - # @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") + # @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") mail :to => recipients, :subject => s, :filter => true @@ -359,10 +358,10 @@ class Mailer < ActionMailer::Base @issues = issues @days = days @issues_url = url_for(:controller => 'issues', :action => 'index', - :set_filter => 1, :assigned_to_id => user.id, - :sort => 'due_date:asc') + :set_filter => 1, :assigned_to_id => user.id, + :sort => 'due_date:asc') mail :to => user.mail, - :subject => l(:mail_subject_reminder, :count => issues.size, :days => days) + :subject => l(:mail_subject_reminder, :count => issues.size, :days => days) end #缺陷到期邮件通知 @@ -493,8 +492,8 @@ class Mailer < ActionMailer::Base @news = news @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => news.recipients, - :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}", - :filter => true + :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}", + :filter => true elsif news.course redmine_headers 'Course' => news.course.id @author = news.author @@ -510,7 +509,7 @@ class Mailer < ActionMailer::Base end # Builds a Mail::Message object used to email recipients of a news' project when a news comment is added. - # 新增新闻评论时邮件通知 + # # Example: # news_comment_added(comment) => Mail::Message object # Mailer.news_comment_added(comment) => sends an email to the news' project recipients @@ -597,12 +596,12 @@ class Mailer < ActionMailer::Base cc = wiki_content.page.wiki.watcher_recipients - recipients @wiki_content = wiki_content @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', - :project_id => wiki_content.project, - :id => wiki_content.page.title) + :project_id => wiki_content.project, + :id => wiki_content.page.title) mail :to => recipients, - :cc => cc, - :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}", - :filter => true + :cc => cc, + :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}", + :filter => true end # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated. @@ -619,15 +618,15 @@ class Mailer < ActionMailer::Base cc = wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients @wiki_content = wiki_content @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', - :project_id => wiki_content.project, - :id => wiki_content.page.title) + :project_id => wiki_content.project, + :id => wiki_content.page.title) @wiki_diff_url = url_for(:controller => 'wiki', :action => 'diff', - :project_id => wiki_content.project, :id => wiki_content.page.title, - :version => wiki_content.version) + :project_id => wiki_content.project, :id => wiki_content.page.title, + :version => wiki_content.version) mail :to => recipients, - :cc => cc, - :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}", - :filter => true + :cc => cc, + :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}", + :filter => true end # Builds a Mail::Message object used to email the specified user their account information. @@ -641,7 +640,7 @@ class Mailer < ActionMailer::Base @password = password @login_url = url_for(:controller => 'account', :action => 'login') mail :to => user.mail, - :subject => l(:mail_subject_register, Setting.app_title) + :subject => l(:mail_subject_register, Setting.app_title) end # Builds a Mail::Message object used to email all active administrators of an account activation request. @@ -654,10 +653,10 @@ class Mailer < ActionMailer::Base recipients = User.active.where(:admin => true).all.collect { |u| u.mail }.compact @user = user @url = url_for(:controller => 'users', :action => 'index', - :status => User::STATUS_REGISTERED, - :sort_key => 'created_on', :sort_order => 'desc') + :status => User::STATUS_REGISTERED, + :sort_key => 'created_on', :sort_order => 'desc') mail :to => recipients, - :subject => l(:mail_subject_account_activation_request, Setting.app_title) + :subject => l(:mail_subject_account_activation_request, Setting.app_title) end # Builds a Mail::Message object used to email the specified user that their account was activated by an administrator. @@ -670,7 +669,7 @@ class Mailer < ActionMailer::Base @user = user @login_url = url_for(:controller => 'account', :action => 'login') mail :to => user.mail, - :subject => l(:mail_subject_register, Setting.app_title) + :subject => l(:mail_subject_register, Setting.app_title) end def lost_password(token) @@ -678,7 +677,7 @@ class Mailer < ActionMailer::Base @token = token @url = url_for(:controller => 'account', :action => 'lost_password', :token => token.value) mail :to => token.user.mail, - :subject => l(:mail_subject_lost_password, Setting.app_title) + :subject => l(:mail_subject_lost_password, Setting.app_title) end def register(token) @@ -686,14 +685,14 @@ class Mailer < ActionMailer::Base @token = token @url = url_for(:controller => 'account', :action => 'activate', :token => token.value) mail :to => token.user.mail, - :subject => l(:mail_subject_register, Setting.app_title) + :subject => l(:mail_subject_register, Setting.app_title) end def test_email(user) set_language_if_valid(user.language) @url = url_for(:controller => 'welcome') mail :to => user.mail, - :subject => 'forge test' + :subject => 'forge test' end # Overrides default deliver! method to prevent from sending an email @@ -701,8 +700,8 @@ class Mailer < ActionMailer::Base def deliver!(mail = @mail) set_language_if_valid @initial_language return false if (recipients.nil? || recipients.empty?) && - (cc.nil? || cc.empty?) && - (bcc.nil? || bcc.empty?) + (cc.nil? || cc.empty?) && + (bcc.nil? || bcc.empty?) # Log errors when raise_delivery_errors is set to false, Rails does not @@ -734,8 +733,8 @@ class Mailer < ActionMailer::Base user_ids = options[:users] scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" + - " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" + - " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date + " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" + + " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date ) scope = scope.where(:assigned_to_id => user_ids) if user_ids.present? scope = scope.where(:project_id => project.id) if project @@ -799,12 +798,12 @@ class Mailer < ActionMailer::Base def mail(headers={}) headers.merge! 'X-Mailer' => 'Redmine', - 'X-Redmine-Host' => Setting.host_name, - 'X-Redmine-Site' => Setting.app_title, - 'X-Auto-Response-Suppress' => 'OOF', - 'Auto-Submitted' => 'auto-generated', - 'From' => Setting.mail_from, - 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" + 'X-Redmine-Host' => Setting.host_name, + 'X-Redmine-Site' => Setting.app_title, + 'X-Auto-Response-Suppress' => 'OOF', + 'Auto-Submitted' => 'auto-generated', + 'From' => Setting.mail_from, + 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" # Removes the author from the recipients and cc # if he doesn't want to receive notifications about what he does @@ -850,7 +849,7 @@ class Mailer < ActionMailer::Base set_language_if_valid Setting.default_language super end - + def self.deliver_mail(mail) return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank? Thread.new do @@ -897,7 +896,7 @@ class Mailer < ActionMailer::Base end def mylogger - if Setting.delayjob_enabled? + if Setting.delayjob_enabled? Delayed::Worker.logger else Rails.logger @@ -908,11 +907,10 @@ class Mailer < ActionMailer::Base if email.attachments && email.attachments.any? email.attachments.each do |attachment| obj.attachments << Attachment.create(:container => obj, - :file => attachment.decoded, - :filename => attachment.filename, - :author => user, - - :content_type => attachment.mime_type) + :file => attachment.decoded, + :filename => attachment.filename, + :author => user, + :content_type => attachment.mime_type) end end end