Always notify project members about news unless they turned off all notifications (#4700).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11271 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
9c1077841e
commit
134b66cb29
|
@ -49,6 +49,10 @@ class News < ActiveRecord::Base
|
|||
user.allowed_to?(:comment_news, project)
|
||||
end
|
||||
|
||||
def recipients
|
||||
project.users.select {|user| user.notify_about?(self)}.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
|
||||
|
|
|
@ -563,38 +563,26 @@ class User < Principal
|
|||
#
|
||||
# TODO: only supports Issue events currently
|
||||
def notify_about?(object)
|
||||
case mail_notification
|
||||
when 'all'
|
||||
if mail_notification == 'all'
|
||||
true
|
||||
when 'selected'
|
||||
# user receives notifications for created/assigned issues on unselected projects
|
||||
if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when 'none'
|
||||
elsif mail_notification.blank? || mail_notification == 'none'
|
||||
false
|
||||
when 'only_my_events'
|
||||
if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when 'only_assigned'
|
||||
if object.is_a?(Issue) && (is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when 'only_owner'
|
||||
if object.is_a?(Issue) && object.author == self
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
else
|
||||
false
|
||||
case object
|
||||
when Issue
|
||||
case mail_notification
|
||||
when 'selected', 'only_my_events'
|
||||
# user receives notifications for created/assigned issues on unselected projects
|
||||
object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was)
|
||||
when 'only_assigned'
|
||||
is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was)
|
||||
when 'only_owner'
|
||||
object.author == self
|
||||
end
|
||||
when News
|
||||
# always send to project members except when mail_notification is set to 'none'
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1018,9 +1018,15 @@ class UserTest < ActiveSupport::TestCase
|
|||
assert ! @user.notify_about?(@issue)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "other events" do
|
||||
should 'be added and tested'
|
||||
def test_notify_about_news
|
||||
user = User.generate!
|
||||
news = News.new
|
||||
|
||||
User::MAIL_NOTIFICATION_OPTIONS.map(&:first).each do |option|
|
||||
user.mail_notification = option
|
||||
assert_equal (option != 'none'), user.notify_about?(news)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue