mirror of
https://github.com/redmine/redmine.git
synced 2025-11-15 17:56:03 +01:00
Adds permissions for viewing the watcher list and adding new watchers on the issue detail view (#398).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1712 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -13,6 +13,7 @@ module Redmine
|
||||
|
||||
class_eval do
|
||||
has_many :watchers, :as => :watchable, :dependent => :delete_all
|
||||
has_many :watcher_users, :through => :watchers, :source => :user
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -22,25 +23,40 @@ module Redmine
|
||||
base.extend ClassMethods
|
||||
end
|
||||
|
||||
# Returns an array of users that are proposed as watchers
|
||||
def addable_watcher_users
|
||||
self.project.users.sort - self.watcher_users
|
||||
end
|
||||
|
||||
# Adds user as a watcher
|
||||
def add_watcher(user)
|
||||
self.watchers << Watcher.new(:user => user)
|
||||
end
|
||||
|
||||
# Removes user from the watchers list
|
||||
def remove_watcher(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}"
|
||||
end
|
||||
|
||||
# Adds/removes watcher
|
||||
def set_watcher(user, watching=true)
|
||||
watching ? add_watcher(user) : remove_watcher(user)
|
||||
end
|
||||
|
||||
# Returns if object is watched by user
|
||||
def watched_by?(user)
|
||||
!self.watchers.find(:first,
|
||||
:conditions => ["#{Watcher.table_name}.user_id = ?", user.id]).nil?
|
||||
end
|
||||
|
||||
# Returns an array of watchers' email addresses
|
||||
def watcher_recipients
|
||||
self.watchers.collect { |w| w.user.mail if w.user.active? }.compact
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Returns the objects that are watched by user
|
||||
def watched_by(user)
|
||||
find(:all,
|
||||
:include => :watchers,
|
||||
@@ -50,4 +66,4 @@ module Redmine
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user