添加《邮件周日发送》功能,修改《贴吧》邮件发送策略

Signed-off-by: alan <547533434@qq.com>
email_verify
alan 12 years ago
parent 7442cc1ca4
commit 4bfc4493eb

@ -20,13 +20,8 @@ gem "builder", "3.0.0"
gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
<<<<<<< HEAD
gem 'email_verifier', path: 'lib/email_verifier'
=======
#gem 'email_verifier', path: 'lib/email_verifier'
gem 'rufus-scheduler'
>>>>>>> szzh
group :development do
gem 'grape-swagger'
gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git'

@ -9,7 +9,7 @@ class BidsController < ApplicationController
menu_item :homework_statistics, :only => :homework_statistics
menu_item :edit, :only => :edit
before_filter :auth_login1, :only => [:show_courseEx]
before_filter :can_show_course,only: []
before_filter :can_show_contest,only: []

@ -5,7 +5,7 @@ class CoursesController < ApplicationController
helper :members
helper :words
before_filter :authorize1, :only => [:show, :feedback]
before_filter :auth_login1, :only => [:show, :feedback]
menu_item :overview
menu_item :feedback, :only => :feedback
menu_item :homework, :only => :homework

@ -20,7 +20,7 @@ class FilesController < ApplicationController
layout 'base_projects' #by young
menu_item :files
before_filter :auth_login1, :only => [:index]
before_filter :find_project_by_project_id#, :except => [:getattachtype]
before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search]

@ -18,7 +18,7 @@ class UsersController < ApplicationController
layout :setting_layout
#Added by young
before_filter :auth_login1, :only => [:show, :user_activities]
before_filter :auth_login1, :only => [:show, :user_activities, :user_newfeedback]
menu_item :activity
menu_item :user_information, :only => :info
menu_item :user_course, :only => :user_courses

@ -1,8 +1,8 @@
class ForumObserver < ActiveRecord::Observer
def after_create(forum)
Thread.start do
Mailer.forum_add(forum).deliver if Setting.notified_events.include?('forum_add')
end
end
# def after_create(forum)
# Thread.start do
# Mailer.forum_add(forum).deliver if Setting.notified_events.include?('forum_add')
# end
#
# end
end

@ -34,6 +34,7 @@ class Mailer < ActionMailer::Base
date_from = date_to - days.days
# 生成token用于直接点击登录
@user = user
token = Token.new(:user =>user , :action => 'autologin')
token.save
@token = token
@ -49,72 +50,69 @@ class Mailer < ActionMailer::Base
@issues = Issue.find_by_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")
and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc")
# @bids 查询课程作业包括老师发布的作业以及user提交作业
# @attachments查询课程课件更新
@attachments ||= []
# 查询课程作业包括老师发布的作业以及user提交作业
@bids ||= [] # 老师发布的作业
courses.each do |course|
@bids << course.homeworks.where("created_at between #{date_from} and #{date_to} order by i.created_on desc")
unless courses.first.nil?
count = courses.count
count = count - 1
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
end
end
# user 提交的作业
@homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between #{date_from} and #{date_to})")
@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 author_id = #{user.id} and (created_on between #{date_from} and #{date_to}) order by i.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 ||= []
messages.each do |msg|
if msg.project
@project_messages << msg
elsif msg.course
@course_messages << msg
unless messages.first.nil?
messages.each do |msg|
if msg.project
@project_messages << msg
elsif msg.course
@course_messages << msg
end
end
end
# 查询user在课程中发布的通知项目中发的新闻
@course_news = 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 i.created_on desc")
and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
@project_news = 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 i.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
jour_type='Course' and user_id = #{user.id}
and (created_on between #{date_from} and #{date_to}) order by i.created_on desc")
@user_journal_messages = user.journals_for_messages.where("m_parent_id IS NULL and (created_on between #{date_from} and #{date_to})").order('created_on DESC')
and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
@user_journal_messages = user.journals_for_messages.where("m_parent_id IS NULL and (created_on between '#{date_from}' and '#{date_to}')").order('created_on DESC')
# 查询课程课件更新
@attachments ||= []
courses.each do |course|
@attachments << course.attachments.where("created_on between #{date_from} and #{date_to}").order('created_at DESC')
end
# 查询user新建贴吧或发布帖子
@forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between #{date_from} and #{date_to}) order by i.created_on desc")
@forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")
@memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id}))
and (created_at between #{date_from} and #{date_to}) order by i.created_on desc")
and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc")
if days == 1
subject = "[ #{user.show_name} : #{date_from} - #{l(:label_day_mail)}]"
subject = "[ #{user.show_name} : #{l(:label_day_mail)}]"
@subject = " #{user.show_name} : #{date_to - 1.days} #{l(:label_day_mail)}"
else
subject = "[ #{user.show_name} : #{l(:label_week_mail)}]"
@subject = "#{user.show_name} : #{l(:label_week_mail)}"
end
mail :to => user.mail,:subject => "[ #{user.show_name} : #{l(:notice_successful_create)}]"
mail :to => user.mail,:subject => subject
end
# 贴吧新建贴吧发送邮件
# example Mailer.forum(forum).deliver
def forum_add(forum)
redmine_headers 'Forum' => forum.id
@forum = forum
@author = forum.creator
recipients = forum.creator.mail
# cc = wiki_content.page.wiki.watcher_recipients - recipients
@issue_author_url = url_for(user_activities_url(@author))
@forum_url = url_for(:controller => 'forums', :action => 'show', :id => forum.id)
mail :to => recipients,:subject => "[ #{l(:label_forum)} : #{forum.name} #{l(:notice_successful_create)}]"
end
def forum_message_added(memo)
@memo = memo
@ -124,15 +122,12 @@ class Mailer < ActionMailer::Base
@forum_url = url_for(:controller => 'forums', :action => 'show', :id => @forum.id)
@issue_author_url = url_for(user_activities_url(@author))
recipients ||= []
# if !memo.parent_id.nil?
# mems = memo.self_and_siblings
# mems.each do |mem|
# recipients << mem.author.mail unless recipients.include? mem.author.mail
# end
# else
# recipients << memo.author.mail
# end
recipients << @author.mail
if @forum.author.mail_notification != 'day' && @forum.author.mail_notification != 'week'
recipients << @forum.author.mail
end
if @author.mail_notification != 'day' && @author.mail_notification != 'week'
recipients << @author.mail
end
# cc = wiki_content.page.wiki.watcher_recipients - recipients
@memo_url = url_for(forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id)))
@ -167,6 +162,17 @@ class Mailer < ActionMailer::Base
Rails.logger.error "[Builds a Mail::Message ERROR] journalsForMessage's jour is unkown type, journalsForMessage.id = #{journals_for_message.id}"
return -1
end
# 验证用户的收取邮件的方式
recipients ||= []
recipients1 ||= []
if @mail.mail_notification != 'week' && @mail.mail_notification != 'day'
recipients1 = @mail.mail
end
if journals_for_message.jour.author.mail_notification != 'week' && journals_for_message.jour.author.mail_notification != 'day'
recipients = journals_for_message.jour.author.mail
end
# modify by nwb
#如果是直接留言并且留言对象是课程
if !journals_for_message.at_user && journals_for_message.jour.class.to_s.to_sym == :Course
@ -177,7 +183,9 @@ class Mailer < ActionMailer::Base
#收件人邮箱
@recipients ||= []
@members.each do |teacher|
if teacher.user.mail_notification != 'week' && teacher.user.mail_notification != 'day'
@recipients << teacher.user.mail
end
end
mail :to => @recipients,
:subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} "
@ -185,14 +193,15 @@ class Mailer < ActionMailer::Base
if !journals_for_message.jour.author.notify_about? journals_for_message
return -1
end
mail :to => journals_for_message.jour.author.mail, :subject => @title
mail :to => recipients, :subject => @title
elsif journals_for_message.jour.class.to_s.to_sym == :Contest
if !journals_for_message.jour.author.notify_about? journals_for_message
return -1
end
mail :to => journals_for_message.jour.author.mail, :subject => @title
mail :to => recipients, :subject => @title
else
mail :to => @mail.mail, :subject => @title
mail :to => recipients1, :subject => @title
end
@ -269,12 +278,6 @@ class Mailer < ActionMailer::Base
@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)
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] "
s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
s << issue.subject

@ -3,6 +3,7 @@ class MemoObserver < ActiveRecord::Observer
thread1=Thread.new do
Mailer.forum_message_added(memo).deliver if Setting.notified_events.include?('forum_message_added')
end
end
end

@ -66,10 +66,8 @@ class User < Principal
MAIL_NOTIFICATION_OPTIONS = [
['all', :label_user_mail_option_all],
['selected', :label_user_mail_option_selected],
['only_my_events', :label_user_mail_option_only_my_events],
['only_assigned', :label_user_mail_option_only_assigned],
['only_owner', :label_user_mail_option_only_owner],
['week', :label_user_mail_option_week],
['day', :label_user_mail_option_day],
['none', :label_user_mail_option_none]
]
@ -188,7 +186,7 @@ class User < Principal
validates_confirmation_of :password, :allow_nil => true
validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
validate :validate_password_length
validates_email_realness_of :mail
# validates_email_realness_of :mail
before_create :set_mail_notification
before_save :update_hashed_password
before_destroy :remove_references_before_destroy

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -17,9 +17,7 @@ module RedmineApp
# -- all .rb files in that directory are automatically loaded.
#verifier if email is real
EmailVerifier.config do |config|
config.verifier_email = "alanlong9278@126.com"
end
config.generators do |g|
g.test_framework :rspec,

@ -6,18 +6,22 @@ require 'rufus-scheduler'
#users = User.where("mail_notification = 'week' or mail_notification = 'day'")
scheduler = Rufus::Scheduler.new
scheduler.cron('*/1 * * * *') do
users = User.where("login like '%alan%'")
scheduler.cron('0 0 * * 1') do
users = User.where("mail_notification = 'week'")
users.each do |user|
# if user.mail_notification == "week"
# cycle = '*/1 * * * *'
# else
# cycle = '*/2 * * * *'
# end
Rails.logger.info "send mail to #{user.show_name}(#{user.mail}) at #{Time.now}"
#Rails.logger.info "send mail to #{user.show_name}(#{user.mail}) at #{Time.now}"
Thread.start do
Mailer.send_for_user_activities(user, Date.today, 7).deliver
end
end
end
scheduler.cron('0 0 * * *') do
users = User.where("mail_notification = 'day'")
users.each do |user|
#Rails.logger.info "send mail to #{user.show_name}(#{user.mail}) at #{Time.now}"
Thread.start do
Mailer.send_for_user_activities(user, Date.today, 1).deliver
end
end
end

@ -616,8 +616,8 @@ en:
label_document_new: New document
label_document_plural: Documents
label_document_added: Document added
label_forum_message_added: Message added
label_forum_add: Forum added
label_forum_message_added: Forum's message added
#label_forum_add: Forum added
label_document_public_info: "If you don't choose public, only the project's members can see the document."
label_role: Role
label_role_plural: Roles
@ -2089,4 +2089,4 @@ en:
label_anonymous: Anonymous
label_submit_comments: Submit_comments
label_course_empty_select: You have not selected course
label_enterprise_page_made: enterprise_page
label_enterprise_page_made: enterprise_page

@ -573,7 +573,7 @@ zh:
label_document_new: 新建文档
label_document_plural: 文档
label_document_added: 文档已添加
label_forum_message_added: 发帖成功
label_forum_message_added: 贴吧发帖成功
label_forum_add: 贴吧创建成功
label_message_reply: 回帖人
label_document_public_info: (打钩为公开,不打钩则不公开,若不公开,仅项目成员可见该文档。)
@ -664,6 +664,8 @@ zh:
label_user_login_attending_contest: 您还没有登录,请登录后参赛
label_user_login_score_and_comment: 您还没有登录,请登录后对作品进行打分评价
label_user_login_notificationcomment: 您还没有登录,请登录后参加评论
label_user_forum: 您的贴吧
label_user_message_forum: 您的帖子
label_user_message: 您的留言
label_show_your_message: 给您的留言
#end
@ -755,7 +757,8 @@ zh:
label_settings: 配置
label_overview: 近期动态
label_course_overview: "课程动态"
label_project_overview: "项目动态"
label_project_overview_new: "项目动态"
label_forums_overview: "贴吧动态"
label_homework_overview: 作业动态
label_question_student: 作业交流 #bai
label_homework_commit: 提交作业 #huang
@ -968,7 +971,9 @@ zh:
label_theme: 主题
label_default: 默认
label_search_titles_only: 仅在标题中搜索
label_user_mail_option_all: "收取我的项目的所有通知"
label_user_mail_option_all: "收取我的所有通知"
label_user_mail_option_week: "按周收取我的所有通知"
label_user_mail_option_day: "按天收取我的所有通知"
label_must_answer: "必答"
label_poll_title: 问卷调查_问卷页面
#huang

@ -20,9 +20,7 @@ module Redmine
notifications << Notifiable.new('message_posted')
notifications << Notifiable.new('wiki_content_added')
notifications << Notifiable.new('wiki_content_updated')
notifications << Notifiable.new('forum_add')
notifications << Notifiable.new('forum_message_added', 'forum_add')
notifications
notifications << Notifiable.new('forum_message_added')
end
end
end

Loading…
Cancel
Save