[#802] Allow Groups to be added as a Watcher

This commit is contained in:
Eric Davis 2011-04-19 11:34:21 -07:00
parent 10054cfd8f
commit e6e6a06fff
4 changed files with 45 additions and 3 deletions

View File

@ -22,6 +22,11 @@ class Group < Principal
validates_uniqueness_of :lastname, :case_sensitive => false
validates_length_of :lastname, :maximum => 30
# Returns an array of all of the email addresses of the group's users
def mails
users.collect(&:mail)
end
def to_s
lastname.to_s
end

View File

@ -14,8 +14,8 @@
class Watcher < ActiveRecord::Base
belongs_to :watchable, :polymorphic => true
belongs_to :user
belongs_to :user, :class_name => 'Principal', :foreign_key => 'user_id'
validates_presence_of :user
validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id]

View File

@ -125,4 +125,34 @@ class WatcherTest < ActiveSupport::TestCase
assert Issue.find(1).watched_by?(user)
assert !Issue.find(4).watched_by?(user)
end
context "group watch" do
setup do
@group = Group.generate!
Member.generate!(:project => Project.find(1), :roles => [Role.find(1)], :principal => @group)
@group.users << @user = User.find(1)
@group.users << @user2 = User.find(2)
end
should "be valid" do
assert @issue.add_watcher(@group)
@issue.reload
assert @issue.watchers.detect { |w| w.user == @group }
end
should "add all group members to recipients" do
@issue.watchers.delete_all
@issue.reload
assert @issue.watcher_recipients.empty?
assert @issue.add_watcher(@group)
@user.save
@issue.reload
assert @issue.watcher_recipients.include?(@user.mail)
assert @issue.watcher_recipients.include?(@user2.mail)
end
end
end

View File

@ -64,7 +64,14 @@ module Redmine
if respond_to?(:visible?)
notified.reject! {|user| !visible?(user)}
end
notified.collect(&:mail).compact
notified.collect {|w|
if w.respond_to?(:mail) && w.mail.present? # Single mail
w.mail
elsif w.respond_to?(:mails) && w.mails.present? # Multiple mail
w.mails
end
}.flatten.compact
end
module ClassMethods; end