From: Jean-Philippe Lang Date: Sun, 9 Feb 2014 11:54:21 +0000 (+0000) Subject: Enable the watching of news (#2549). X-Git-Tag: 2.5.0~42 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1ad33134d3005af9a1c8357a55e8c6ab9332d4fa;p=redmine.git Enable the watching of news (#2549). git-svn-id: http://svn.redmine.org/redmine/trunk@12866 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index f9de4a030..0096d8ac1 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -90,7 +90,13 @@ class WatchersController < ApplicationController klass = Object.const_get(params[:object_type].camelcase) rescue nil if klass && klass.respond_to?('watched_by') @watchables = klass.where(:id => Array.wrap(params[:object_id])).all - raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?} + raise Unauthorized if @watchables.any? {|w| + if w.respond_to?(:visible?) + !w.visible? + elsif w.respond_to?(:project) && w.project + !w.project.visible? + end + } end render_404 unless @watchables.present? end diff --git a/app/models/enabled_module.rb b/app/models/enabled_module.rb index 91a750ec8..1cc84aaa5 100644 --- a/app/models/enabled_module.rb +++ b/app/models/enabled_module.rb @@ -17,6 +17,7 @@ class EnabledModule < ActiveRecord::Base belongs_to :project + acts_as_watchable validates_presence_of :name validates_uniqueness_of :name, :scope => :project_id diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 052bb9aef..bfc39c0b3 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -158,6 +158,7 @@ class Mailer < ActionMailer::Base @news = news @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => news.recipients, + :cc => news.cc_for_added_news, :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}" end diff --git a/app/models/news.rb b/app/models/news.rb index d9b0f513e..c1f6655a5 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -54,6 +54,18 @@ class News < ActiveRecord::Base project.users.select {|user| user.notify_about?(self)}.map(&:mail) end + # Returns the email addresses that should be cc'd when a new news is added + def cc_for_added_news + cc = [] + if m = project.enabled_module('news') + cc = m.notified_watchers + unless project.is_public? + cc = cc.select {|user| project.users.include?(user)} + end + end + cc.map(&:mail) + end + # returns latest news for projects visible by user def self.latest(user = User.current, count = 5) visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all diff --git a/app/models/project.rb b/app/models/project.rb index a25513baf..c5392d7b0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -622,9 +622,16 @@ class Project < ActiveRecord::Base end end - def module_enabled?(module_name) - module_name = module_name.to_s - enabled_modules.detect {|m| m.name == module_name} + # Return the enabled module with the given name + # or nil if the module is not enabled for the project + def enabled_module(name) + name = name.to_s + enabled_modules.detect {|m| m.name == name} + end + + # Return true if the module with the given name is enabled + def module_enabled?(name) + enabled_module(name).present? end def enabled_module_names=(module_names) diff --git a/app/views/news/index.html.erb b/app/views/news/index.html.erb index 38eecd262..7fa75dc51 100644 --- a/app/views/news/index.html.erb +++ b/app/views/news/index.html.erb @@ -3,6 +3,7 @@ new_project_news_path(@project), :class => 'icon icon-add', :onclick => 'showAndScrollTo("add-news", "news_title"); return false;') if @project && User.current.allowed_to?(:manage_news, @project) %> +<%= watcher_link(@project.enabled_module('news'), User.current) %>