remove trailing white-spaces from vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9010 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
33d4821923
commit
8e899d9677
|
@ -2,19 +2,19 @@
|
||||||
module Redmine
|
module Redmine
|
||||||
module Acts
|
module Acts
|
||||||
module Watchable
|
module Watchable
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.extend ClassMethods
|
base.extend ClassMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def acts_as_watchable(options = {})
|
def acts_as_watchable(options = {})
|
||||||
return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods)
|
return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods)
|
||||||
send :include, Redmine::Acts::Watchable::InstanceMethods
|
send :include, Redmine::Acts::Watchable::InstanceMethods
|
||||||
|
|
||||||
class_eval do
|
class_eval do
|
||||||
has_many :watchers, :as => :watchable, :dependent => :delete_all
|
has_many :watchers, :as => :watchable, :dependent => :delete_all
|
||||||
has_many :watcher_users, :through => :watchers, :source => :user, :validate => false
|
has_many :watcher_users, :through => :watchers, :source => :user, :validate => false
|
||||||
|
|
||||||
named_scope :watched_by, lambda { |user_id|
|
named_scope :watched_by, lambda { |user_id|
|
||||||
{ :include => :watchers,
|
{ :include => :watchers,
|
||||||
:conditions => ["#{Watcher.table_name}.user_id = ?", user_id] }
|
:conditions => ["#{Watcher.table_name}.user_id = ?", user_id] }
|
||||||
|
@ -28,7 +28,7 @@ module Redmine
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.extend ClassMethods
|
base.extend ClassMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of users that are proposed as watchers
|
# Returns an array of users that are proposed as watchers
|
||||||
def addable_watcher_users
|
def addable_watcher_users
|
||||||
users = self.project.users.sort - self.watcher_users
|
users = self.project.users.sort - self.watcher_users
|
||||||
|
@ -37,33 +37,33 @@ module Redmine
|
||||||
end
|
end
|
||||||
users
|
users
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds user as a watcher
|
# Adds user as a watcher
|
||||||
def add_watcher(user)
|
def add_watcher(user)
|
||||||
self.watchers << Watcher.new(:user => user)
|
self.watchers << Watcher.new(:user => user)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Removes user from the watchers list
|
# Removes user from the watchers list
|
||||||
def remove_watcher(user)
|
def remove_watcher(user)
|
||||||
return nil unless user && user.is_a?(User)
|
return nil unless user && user.is_a?(User)
|
||||||
Watcher.delete_all "watchable_type = '#{self.class}' AND watchable_id = #{self.id} AND user_id = #{user.id}"
|
Watcher.delete_all "watchable_type = '#{self.class}' AND watchable_id = #{self.id} AND user_id = #{user.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds/removes watcher
|
# Adds/removes watcher
|
||||||
def set_watcher(user, watching=true)
|
def set_watcher(user, watching=true)
|
||||||
watching ? add_watcher(user) : remove_watcher(user)
|
watching ? add_watcher(user) : remove_watcher(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if object is watched by +user+
|
# Returns true if object is watched by +user+
|
||||||
def watched_by?(user)
|
def watched_by?(user)
|
||||||
!!(user && self.watcher_user_ids.detect {|uid| uid == user.id })
|
!!(user && self.watcher_user_ids.detect {|uid| uid == user.id })
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of watchers' email addresses
|
# Returns an array of watchers' email addresses
|
||||||
def watcher_recipients
|
def watcher_recipients
|
||||||
notified = watcher_users.active
|
notified = watcher_users.active
|
||||||
notified.reject! {|user| user.mail_notification == 'none'}
|
notified.reject! {|user| user.mail_notification == 'none'}
|
||||||
|
|
||||||
if respond_to?(:visible?)
|
if respond_to?(:visible?)
|
||||||
notified.reject! {|user| !visible?(user)}
|
notified.reject! {|user| !visible?(user)}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue