diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 03d1454ef..54b8c6305 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -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 } diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 95b049dc2..22eb9bfae 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -112,7 +112,7 @@ module CoursesHelper # end #获取课程所有成员 - def course_member course + def course_all_member course course.members end # 学生人数计算 diff --git a/app/models/forum.rb b/app/models/forum.rb index 61ba528a0..eb8bb19d2 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -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 diff --git a/app/models/forum_observer.rb b/app/models/forum_observer.rb new file mode 100644 index 000000000..1c514d6ab --- /dev/null +++ b/app/models/forum_observer.rb @@ -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 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index a2e742ee3..23ac36054 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -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. # 留言分为直接留言,和对留言人留言的回复 @@ -62,7 +92,7 @@ class Mailer < ActionMailer::Base course = journals_for_message.jour @author = journals_for_message.user #课程的教师 - @members = course_member journals_for_message.jour + @members = course_all_member journals_for_message.jour #收件人邮箱 @recipients ||= [] @members.each do |teacher| @@ -117,8 +147,10 @@ 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)) - - cc = issue.watcher_recipients - issue.recipients + cc = nil + if recipients == issue.recipients[0] + cc = issue.watcher_recipients - issue.recipients + end subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}" mail(:to => recipients, :cc => cc, @@ -167,8 +199,11 @@ class Mailer < ActionMailer::Base # Watchers in cc + cc = nil + if recipients == journal.recipients[0] + cc = journal.watcher_recipients - journal.recipients + end - cc = journal.watcher_recipients - journal.recipients s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] " s << "(#{issue.status.name}) " if journal.new_value_for('status_id') s << issue.subject @@ -282,7 +317,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 +358,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 +386,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 +416,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. diff --git a/app/models/memo.rb b/app/models/memo.rb index cfc509923..f9482911a 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -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 diff --git a/app/models/memo_observer.rb b/app/models/memo_observer.rb new file mode 100644 index 000000000..66cabe923 --- /dev/null +++ b/app/models/memo_observer.rb @@ -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 diff --git a/app/views/layouts/_base_feedback.html.erb b/app/views/layouts/_base_feedback.html.erb index 52006e94d..ae85d9479 100644 --- a/app/views/layouts/_base_feedback.html.erb +++ b/app/views/layouts/_base_feedback.html.erb @@ -1,49 +1,122 @@ - - - - -意见反馈浮窗 + - + + + + +意见反馈 + + + - - -
-
- - <% get_memo %> - <%= form_for(@new_memo, :url => create_feedback_forum_path(@public_forum)) do |f| %> -
-

- <%= f.text_area :subject, :class => "opnionText",:placeholder => "有什么想说的,尽管来咆哮吧~~"%> -

-

- <%= f.hidden_field :content, :required => true ,:value=>'该贴来自用户反馈!'%> -

- <%#= f.submit :value => l(:label_memo_create), :class => "opnionButton", :id => "button1" %> - 提  交 - <% end %> -
- - - -
+ + +
+
+
+ +
+
+ <% get_memo %> + <%= form_for(@new_memo, :url => create_feedback_forum_path(@public_forum)) do |f| %> + <%= f.text_area :subject, :class => "opnionText",:placeholder => "有什么想说的,尽管来咆哮吧~~"%> + <%= f.hidden_field :content, :required => true ,:value=>'该贴来自用户反馈!'%> + <%#= f.submit :value => l(:label_memo_create), :class => "opnionButton", :id => "button1" %> + 提  交 + <% end %> +
+ +
+
+
+
+
提交
- -
-
技术支持:
-

<%= l(:label_course_adcolick) %>黄井泉
- <%= l(:label_course_adcolick) %>白羽

-
- -
+ + - - - + \ No newline at end of file diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index b80206728..a05eacbd1 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -11,7 +11,7 @@ div,html,img,ul,li,p,body,h1,h2,h3,h4,p,a,table,tr,td,fieldset,input,span,ol{ ma div,img,tr,td,table{ border:0;} table,tr,td{border:0;cellspacing:0; cellpadding:0;} ol,ul,li{ list-style-type:none} -.cl{ clear:both; overflow:hidden; } +.cl{ clear:both; overflow:hidden; margin-top: 30px;} a{ text-decoration:none; } a:hover{ text-decoration:underline; } .mail_box,ul,li{ list-style-type:none} @@ -35,7 +35,7 @@ a:hover.mail_reply{ background:#06a9bc; text-decoration:none;}
-

亲爱的Trustie用户,您好!

+

<%= l(:mail_issue_greetings)%>

<%= yield %>
diff --git a/app/views/mailer/_issue.html.erb b/app/views/mailer/_issue.html.erb index 5979877a3..c97c82426 100644 --- a/app/views/mailer/_issue.html.erb +++ b/app/views/mailer/_issue.html.erb @@ -2,19 +2,19 @@

<%= link_to(h("#{@issue.author}(#{@issue.author.show_name})"), @issue_author_url) %> - 在 - <%= link_to(h("#{@issue.project.name}"),@project_url) %>中有了一个与您相关的最新活动,请您关注!

+ <%= l(:mail_issue_title_userin)%> + <%= link_to(h("#{@issue.project.name}"),@project_url) %><%= l(:mail_issue_title_active)%>

    -
  • 标题:<%= link_to(issue.subject, issue_url) %>
  • -
  • 来源:<%= issue.project.name %>项目<%= issue.tracker.name%>
  • -
  • 内容: +
  • <%= l(:mail_issue_subject)%><%= link_to(issue.subject, issue_url) %>
  • +
  • <%= l(:mail_issue_sent_from)%><%= issue.project.name %><%= l(:mail_issue_from_project)%>
  • +
  • <%= l(:mail_issue_content)%> <%= issue.description %>
  • <% unless @issue.attachments.nil? %> - 附件: + <%= l(:mail_issue_attachments)%> <% @issue.attachments.each do |attach| %>

    <%= link_to_attachment(attach, :download => true, :token => @token.value, :only_path => false) %>

    @@ -25,7 +25,7 @@
- +