diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-04-21 12:08:31 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-04-21 12:08:31 +0000 |
commit | 2fb84af3e91dc17aa0f84a8fa0e02cabe2ac712c (patch) | |
tree | 5d90bc5dec82cac5531dd7b14c65f9d35ee64dec /lib | |
parent | 907f906ec6e0fb60cbbd4abe7b579c59d78405d4 (diff) | |
download | redmine-2fb84af3e91dc17aa0f84a8fa0e02cabe2ac712c.tar.gz redmine-2fb84af3e91dc17aa0f84a8fa0e02cabe2ac712c.zip |
Added "Watch" functionality on issues. It allows users to receive mail notifications about issue changes.
For now, it's only usefull for users who are not members of the project, since members receive notifications for each issue (this behaviour will change).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@453 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine.rb | 13 | ||||
-rw-r--r-- | lib/redmine/acts_as_watchable/init.rb | 3 | ||||
-rw-r--r-- | lib/redmine/acts_as_watchable/lib/acts_as_watchable.rb | 53 | ||||
-rw-r--r-- | lib/redmine/version.rb | 11 |
4 files changed, 69 insertions, 11 deletions
diff --git a/lib/redmine.rb b/lib/redmine.rb index 20b30c037..cfcccccf9 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -1,11 +1,2 @@ -module Redmine
- module VERSION #:nodoc:
- MAJOR = 0
- MINOR = 5
- TINY = 0
-
- STRING= [MAJOR, MINOR, TINY].join('.')
-
- def self.to_s; STRING end
- end
-end
\ No newline at end of file +require 'redmine/version' +require 'redmine/acts_as_watchable/init' diff --git a/lib/redmine/acts_as_watchable/init.rb b/lib/redmine/acts_as_watchable/init.rb new file mode 100644 index 000000000..f39cc7d18 --- /dev/null +++ b/lib/redmine/acts_as_watchable/init.rb @@ -0,0 +1,3 @@ +# Include hook code here +require File.dirname(__FILE__) + '/lib/acts_as_watchable' +ActiveRecord::Base.send(:include, Redmine::Acts::Watchable) diff --git a/lib/redmine/acts_as_watchable/lib/acts_as_watchable.rb b/lib/redmine/acts_as_watchable/lib/acts_as_watchable.rb new file mode 100644 index 000000000..d62742cac --- /dev/null +++ b/lib/redmine/acts_as_watchable/lib/acts_as_watchable.rb @@ -0,0 +1,53 @@ +# ActsAsWatchable +module Redmine + module Acts + module Watchable + def self.included(base) + base.extend ClassMethods + end + + 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 + end + end + end + + module InstanceMethods + def self.included(base) + base.extend ClassMethods + end + + def add_watcher(user) + self.watchers << Watcher.new(:user => user) + end + + 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 + + def watched_by?(user) + !self.watchers.find(:first, + :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]).nil? + end + + def watcher_recipients + self.watchers.collect { |w| w.user.mail if w.user.mail_notification }.compact + end + + module ClassMethods + def watched_by(user) + find(:all, + :include => :watchers, + :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]) + end + end + end + end + end +end
\ No newline at end of file diff --git a/lib/redmine/version.rb b/lib/redmine/version.rb new file mode 100644 index 000000000..630fb1ff8 --- /dev/null +++ b/lib/redmine/version.rb @@ -0,0 +1,11 @@ +module Redmine + module VERSION #:nodoc: + MAJOR = 0 + MINOR = 5 + TINY = 0 + + STRING= [MAJOR, MINOR, TINY].join('.') + + def self.to_s; STRING end + end +end |