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:
Jean-Philippe Lang
2008-08-03 09:14:43 +00:00
parent 6034067d86
commit a332e0a4fe
38 changed files with 210 additions and 21 deletions
+17 -1
View File
@@ -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
+2 -2
View File
@@ -138,8 +138,8 @@ module ActionView #:nodoc:
def add_options(option_tags, options, value = nil)
option_tags = "<option value=\"\"></option>\n" + option_tags if options[:include_blank]
if value.blank? && options[:prompt]
("<option value=\"\">#{options[:prompt].kind_of?(String) ? options[:prompt] : l(:actionview_instancetag_blank_option)}</option>\n") + option_tags
if options[:prompt]
("<option value=\"\">--- #{options[:prompt].kind_of?(String) ? options[:prompt] : l(:actionview_instancetag_blank_option)} ---</option>\n") + option_tags
else
option_tags
end