comparison vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 513646585e45
children
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
11 return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) 11 return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods)
12 send :include, Redmine::Acts::Watchable::InstanceMethods 12 send :include, Redmine::Acts::Watchable::InstanceMethods
13 13
14 class_eval do 14 class_eval do
15 has_many :watchers, :as => :watchable, :dependent => :delete_all 15 has_many :watchers, :as => :watchable, :dependent => :delete_all
16 has_many :watcher_users, :through => :watchers, :source => :user 16 has_many :watcher_users, :through => :watchers, :source => :user, :validate => false
17 17
18 named_scope :watched_by, lambda { |user_id| 18 named_scope :watched_by, lambda { |user_id|
19 { :include => :watchers, 19 { :include => :watchers,
20 :conditions => ["#{Watcher.table_name}.user_id = ?", user_id] } 20 :conditions => ["#{Watcher.table_name}.user_id = ?", user_id] }
21 } 21 }
29 base.extend ClassMethods 29 base.extend ClassMethods
30 end 30 end
31 31
32 # Returns an array of users that are proposed as watchers 32 # Returns an array of users that are proposed as watchers
33 def addable_watcher_users 33 def addable_watcher_users
34 self.project.users.sort - self.watcher_users 34 users = self.project.users.sort - self.watcher_users
35 if respond_to?(:visible?)
36 users.reject! {|user| !visible?(user)}
37 end
38 users
35 end 39 end
36 40
37 # Adds user as a watcher 41 # Adds user as a watcher
38 def add_watcher(user) 42 def add_watcher(user)
39 self.watchers << Watcher.new(:user => user) 43 self.watchers << Watcher.new(:user => user)
56 end 60 end
57 61
58 # Returns an array of watchers' email addresses 62 # Returns an array of watchers' email addresses
59 def watcher_recipients 63 def watcher_recipients
60 notified = watcher_users.active 64 notified = watcher_users.active
61 65 notified.reject! {|user| user.mail_notification == 'none'}
66
62 if respond_to?(:visible?) 67 if respond_to?(:visible?)
63 notified.reject! {|user| !visible?(user)} 68 notified.reject! {|user| !visible?(user)}
64 end 69 end
65 notified.collect(&:mail).compact 70 notified.collect(&:mail).compact
66 end 71 end