增加贴吧创建,发帖时发送邮件功能,修改《邮件重发多次》bug
Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
parent
f01d164295
commit
432e3a05f2
|
@ -160,12 +160,15 @@ class ForumsController < ApplicationController
|
|||
def create
|
||||
@forum = Forum.new(params[:forum])
|
||||
@forum.creator_id = User.current.id
|
||||
if @forum.save
|
||||
respond_to do |format|
|
||||
|
||||
respond_to do |format|
|
||||
if @forum.save
|
||||
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
|
||||
format.json { render json: @forum, status: :created, location: @forum }
|
||||
else
|
||||
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
|
||||
format.json { render json: @forum, status: :created, location: @forum }
|
||||
end
|
||||
|
||||
else
|
||||
respond_to do |format|
|
||||
flash.now[:error] = "#{l :label_forum_create_fail}: #{@forum.errors.full_messages[0]}"
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @forum.errors, status: :unprocessable_entity }
|
||||
|
|
|
@ -18,7 +18,7 @@ class Forum < ActiveRecord::Base
|
|||
|
||||
acts_as_taggable
|
||||
scope :by_join_date, order("created_at DESC")
|
||||
|
||||
after_create :send_email
|
||||
def reset_counters!
|
||||
self.class.reset_counters!(id)
|
||||
end
|
||||
|
@ -33,6 +33,11 @@ class Forum < ActiveRecord::Base
|
|||
self.creator == user || user.admin?
|
||||
end
|
||||
|
||||
def send_email
|
||||
Thread.start do
|
||||
Mailer.forum_add(self).deliver if Setting.notified_events.include?('forum_add')
|
||||
end
|
||||
end
|
||||
# Updates topic_count, memo_count and last_memo_id attributes for +board_id+
|
||||
def self.reset_counters!(forum_id)
|
||||
forum_id = forum_id.to_i
|
||||
|
|
|
@ -0,0 +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
|
||||
end
|
|
@ -26,7 +26,37 @@ class Mailer < ActionMailer::Base
|
|||
def self.default_url_options
|
||||
{ :host => Setting.host_name, :protocol => Setting.protocol }
|
||||
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
|
||||
|
||||
@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
|
||||
redmine_headers 'Memo' => memo.id
|
||||
@forum = memo.forum
|
||||
@author = memo.author
|
||||
recipients ||= []
|
||||
mems = memo.self_and_siblings
|
||||
mems.each do |mem|
|
||||
recipients << mem.author.mail unless recipients.include? mem.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)))
|
||||
mail :to => recipients,:subject => "[ #{l(:label_message_plural)} : #{memo.subject} #{l(:label_memo_create_succ)}]"
|
||||
end
|
||||
# Builds a Mail::Message object used to email recipients of the added journals for message.
|
||||
|
||||
# 留言分为直接留言,和对留言人留言的回复
|
||||
|
@ -282,7 +312,7 @@ class Mailer < ActionMailer::Base
|
|||
recipients = container.notified_users.select { |user| user.allowed_to?(:view_files, container) }.collect { |u| u.mail }
|
||||
when 'Course'
|
||||
added_to_url = url_for(:controller => 'files', :action => 'index', :course_id => container)
|
||||
added_to = "#{l(:label_course)}: #{container}"
|
||||
added_to = "#{l(:label_course)}: #{container.name}"
|
||||
recipients = container.notified_users.select { |user| user.allowed_to?(:view_files, container) }.collect { |u| u.mail }
|
||||
when 'Version'
|
||||
added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
|
||||
|
@ -323,13 +353,25 @@ class Mailer < ActionMailer::Base
|
|||
# news_added(news) => Mail::Message object
|
||||
# Mailer.news_added(news).deliver => sends an email to the news' project recipients
|
||||
def news_added(news)
|
||||
redmine_headers 'Project' => news.project.identifier
|
||||
@author = news.author
|
||||
message_id news
|
||||
@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}"
|
||||
|
||||
if news.project
|
||||
redmine_headers 'Project' => news.project.identifier
|
||||
@author = news.author
|
||||
message_id news
|
||||
@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}"
|
||||
elsif news.course
|
||||
redmine_headers 'Course' => news.course.id
|
||||
@author = news.author
|
||||
message_id news
|
||||
@news = news
|
||||
recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail }
|
||||
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
|
||||
mail :to => recipients,
|
||||
:subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}"
|
||||
end
|
||||
end
|
||||
|
||||
# Builds a Mail::Message object used to email recipients of a news' project when a news comment is added.
|
||||
|
@ -339,15 +381,28 @@ class Mailer < ActionMailer::Base
|
|||
# Mailer.news_comment_added(comment) => sends an email to the news' project recipients
|
||||
def news_comment_added(comment)
|
||||
news = comment.commented
|
||||
redmine_headers 'Project' => news.project.identifier
|
||||
@author = comment.author
|
||||
message_id comment
|
||||
@news = news
|
||||
@comment = comment
|
||||
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
|
||||
mail :to => news.recipients,
|
||||
:cc => news.watcher_recipients,
|
||||
:subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
|
||||
if news.project
|
||||
redmine_headers 'Project' => news.project.identifier
|
||||
@author = comment.author
|
||||
message_id comment
|
||||
@news = news
|
||||
@comment = comment
|
||||
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
|
||||
mail :to => news.recipients,
|
||||
:cc => news.watcher_recipients,
|
||||
:subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
|
||||
elsif news.course
|
||||
redmine_headers 'Course' => news.course.id
|
||||
@author = comment.author
|
||||
message_id comment
|
||||
@news = news
|
||||
@comment = comment
|
||||
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
|
||||
recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail }
|
||||
|
||||
mail :to => recipients,
|
||||
:subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}"
|
||||
end
|
||||
end
|
||||
|
||||
# Builds a Mail::Message object used to email the recipients of the specified message that was posted.
|
||||
|
@ -356,18 +411,33 @@ class Mailer < ActionMailer::Base
|
|||
# message_posted(message) => Mail::Message object
|
||||
# Mailer.message_posted(message).deliver => sends an email to the recipients
|
||||
def message_posted(message)
|
||||
redmine_headers 'Project' => message.project.identifier,
|
||||
'Topic-Id' => (message.parent_id || message.id)
|
||||
@author = message.author
|
||||
message_id message
|
||||
references message.parent unless message.parent.nil?
|
||||
recipients = message.recipients
|
||||
cc = ((message.root.watcher_recipients + message.board.watcher_recipients).uniq - recipients)
|
||||
@message = message
|
||||
@message_url = url_for(message.event_url)
|
||||
mail :to => recipients,
|
||||
:cc => cc,
|
||||
:subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
|
||||
if message.project
|
||||
redmine_headers 'Project' => message.project.identifier,
|
||||
'Topic-Id' => (message.parent_id || message.id)
|
||||
@author = message.author
|
||||
message_id message
|
||||
references message.parent unless message.parent.nil?
|
||||
recipients = message.recipients
|
||||
cc = ((message.root.watcher_recipients + message.board.watcher_recipients).uniq - recipients)
|
||||
@message = message
|
||||
@message_url = url_for(message.event_url)
|
||||
mail :to => recipients,
|
||||
:cc => cc,
|
||||
:subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
|
||||
elsif message.course
|
||||
redmine_headers 'Course' => message.course.id,
|
||||
'Topic-Id' => (message.parent_id || message.id)
|
||||
@author = message.author
|
||||
message_id message
|
||||
references message.parent unless message.parent.nil?
|
||||
recipients = message.course.notified_users.select { |user| user.allowed_to?(:view_files, message.course) }.collect { |u| u.mail }
|
||||
cc = ((message.root.watcher_recipients + message.board.watcher_recipients).uniq - recipients)
|
||||
@message = message
|
||||
@message_url = url_for(message.event_url)
|
||||
mail :to => recipients,
|
||||
:cc => cc,
|
||||
:subject => "[#{message.board.course.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
|
||||
end
|
||||
end
|
||||
|
||||
# Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added.
|
||||
|
|
|
@ -43,7 +43,7 @@ class Memo < ActiveRecord::Base
|
|||
"parent_id",
|
||||
"replies_count"
|
||||
|
||||
after_create :add_author_as_watcher, :reset_counters!#,:be_user_score -- 公共区发帖暂不计入得分
|
||||
after_create :add_author_as_watcher, :reset_counters!, :sendmail#,:be_user_score -- 公共区发帖暂不计入得分
|
||||
# after_update :update_memos_forum
|
||||
after_destroy :reset_counters!#,:down_user_score -- 公共区发帖暂不计入得分
|
||||
# after_create :send_notification
|
||||
|
@ -54,6 +54,12 @@ class Memo < ActiveRecord::Base
|
|||
# includes(:forum => ).where()
|
||||
# }
|
||||
|
||||
def sendmail
|
||||
thread1=Thread.new do
|
||||
Mailer.forum_message_added(self).deliver if Setting.notified_events.include?('forum_message_added')
|
||||
end
|
||||
end
|
||||
|
||||
def cannot_reply_to_locked_topic
|
||||
errors.add :base, l(:label_memo_locked) if root.locked? && self != root
|
||||
end
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
class MemoObserver < ActiveRecord::Observer
|
||||
def after_create(memo)
|
||||
|
||||
thread1=Thread.new do
|
||||
Mailer.forum_message_added(memo).deliver if Setting.notified_events.include?('forum_message_added')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -600,7 +600,7 @@ class Project < ActiveRecord::Base
|
|||
# Returns the users that should be notified on project events
|
||||
def notified_users
|
||||
# TODO: User part should be extracted to User#notify_about?
|
||||
members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal}
|
||||
members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all' || m.principal.mail_notification == 'only_my_events' ||m.principal.mail_notification == 'selected')}.collect {|m| m.principal}
|
||||
end
|
||||
|
||||
# Returns an array of all custom fields enabled for project issues
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<h1><%= link_to(h(@forum.name), @forum_url) %></h1>
|
||||
<em><%=h @forum.creator.name %></em>
|
||||
|
||||
<%= @forum.description.html_safe %>
|
|
@ -0,0 +1,4 @@
|
|||
<%= @forum_url %>
|
||||
<%= @author.name %>
|
||||
|
||||
<%= @forum.description %>
|
|
@ -0,0 +1,4 @@
|
|||
<h1><%= link_to(h(@memo.subject), @memo_url) %></h1>
|
||||
<em><%=h @memo.author.name %></em>
|
||||
|
||||
<%= @memo.content.html_safe %>
|
|
@ -0,0 +1,5 @@
|
|||
<%= @memo_url %>
|
||||
<%= @author.name %>
|
||||
|
||||
<%= @memo.subject %>
|
||||
<%= @memo.content %>
|
|
@ -1,4 +1,10 @@
|
|||
<h1><%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to(h(@message.subject), @message_url) %></h1>
|
||||
<h1>
|
||||
<% if @message.project %>
|
||||
<%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to(h(@message.subject), @message_url) %>
|
||||
<% elsif @message.course %>
|
||||
<%=h @message.board.course.name %> - <%=h @message.board.name %>: <%= link_to(h(@message.subject), @message_url) %>
|
||||
<% end %>
|
||||
</h1>
|
||||
<em><%=h @message.author %></em>
|
||||
|
||||
<%= textilizable(@message, :content, :only_path => false) %>
|
||||
|
|
|
@ -568,6 +568,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_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
|
||||
|
|
|
@ -581,6 +581,8 @@ zh:
|
|||
label_document_new: 新建文档
|
||||
label_document_plural: 文档
|
||||
label_document_added: 文档已添加
|
||||
label_forum_message_added: 发帖成功
|
||||
label_forum_add: 贴吧创建成功
|
||||
label_document_public_info: (打钩为公开,不打钩则不公开,若不公开,仅项目成员可见该文档。)
|
||||
label_role: 角色
|
||||
label_role_plural: 角色
|
||||
|
|
|
@ -20,6 +20,8 @@ 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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ForumObserver do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe MemoObserver do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue