diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-03-25 19:52:24 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-03-25 19:52:24 +0000 |
commit | 706f8b1691cdf401d0c135afa5ec9d9f22d04838 (patch) | |
tree | 9b1a58aee4877522263dabfcc0c7cd2285468cf2 /vendor/plugins/acts_as_watchable | |
parent | 6115a079ec0085bd84aefa8dc48e38ed3a7d23c0 (diff) | |
download | redmine-706f8b1691cdf401d0c135afa5ec9d9f22d04838.tar.gz redmine-706f8b1691cdf401d0c135afa5ec9d9f22d04838.zip |
Override watcher_user_ids= to make ids uniq (#10538).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9269 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor/plugins/acts_as_watchable')
-rw-r--r-- | vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb index 96cb3a157..5420da0fe 100644 --- a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb +++ b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb @@ -9,8 +9,6 @@ module Redmine module ClassMethods def acts_as_watchable(options = {}) return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) - send :include, Redmine::Acts::Watchable::InstanceMethods - class_eval do has_many :watchers, :as => :watchable, :dependent => :delete_all has_many :watcher_users, :through => :watchers, :source => :user, :validate => false @@ -21,6 +19,8 @@ module Redmine } attr_protected :watcher_ids, :watcher_user_ids end + send :include, Redmine::Acts::Watchable::InstanceMethods + alias_method_chain :watcher_user_ids=, :uniq_ids end end @@ -54,6 +54,14 @@ module Redmine watching ? add_watcher(user) : remove_watcher(user) end + # Overrides watcher_user_ids= to make user_ids uniq + def watcher_user_ids_with_uniq_ids=(user_ids) + if user_ids.is_a?(Array) + user_ids = user_ids.uniq + end + send :watcher_user_ids_without_uniq_ids=, user_ids + end + # Returns true if object is watched by +user+ def watched_by?(user) !!(user && self.watcher_user_ids.detect {|uid| uid == user.id }) |