summaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-07-27 17:54:09 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-07-27 17:54:09 +0000
commita774c5c48b5e596770340b6ac27ea9f0a1e1141f (patch)
tree7c0ab261c09324cbef711cba9ab3400d3c610cc2 /vendor
parent1721376542af256263d605a16c3981eca9e3733a (diff)
downloadredmine-a774c5c48b5e596770340b6ac27ea9f0a1e1141f.tar.gz
redmine-a774c5c48b5e596770340b6ac27ea9f0a1e1141f.zip
Activity refactoring.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1701 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor')
-rw-r--r--vendor/plugins/acts_as_activity_provider/init.rb2
-rw-r--r--vendor/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb68
2 files changed, 70 insertions, 0 deletions
diff --git a/vendor/plugins/acts_as_activity_provider/init.rb b/vendor/plugins/acts_as_activity_provider/init.rb
new file mode 100644
index 000000000..5bf05da2c
--- /dev/null
+++ b/vendor/plugins/acts_as_activity_provider/init.rb
@@ -0,0 +1,2 @@
+require File.dirname(__FILE__) + '/lib/acts_as_activity_provider'
+ActiveRecord::Base.send(:include, Redmine::Acts::ActivityProvider)
diff --git a/vendor/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb b/vendor/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
new file mode 100644
index 000000000..7c4fac8b1
--- /dev/null
+++ b/vendor/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
@@ -0,0 +1,68 @@
+# redMine - project management software
+# Copyright (C) 2006-2008 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module Redmine
+ module Acts
+ module ActivityProvider
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+ def acts_as_activity_provider(options = {})
+ unless self.included_modules.include?(Redmine::Acts::ActivityProvider::InstanceMethods)
+ cattr_accessor :activity_provider_options
+ send :include, Redmine::Acts::ActivityProvider::InstanceMethods
+ end
+
+ options.assert_valid_keys(:type, :permission, :timestamp, :find_options)
+ self.activity_provider_options ||= {}
+
+ # One model can provide different event types
+ # We store these options in activity_provider_options hash
+ event_type = options.delete(:type) || self.name.underscore.pluralize
+
+ options[:permission] = "view_#{self.name.underscore.pluralize}".to_sym unless options.has_key?(:permission)
+ options[:timestamp] ||= "#{table_name}.created_on"
+ options[:find_options] ||= {}
+ self.activity_provider_options[event_type] = options
+ end
+ end
+
+ module InstanceMethods
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+ # Returns events of type event_type visible by user that occured between from and to
+ def find_events(event_type, user, from, to, options)
+ provider_options = activity_provider_options[event_type]
+ raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
+
+ cond = ARCondition.new(["#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to])
+ cond.add(Project.allowed_to_condition(user, provider_options[:permission], options)) if provider_options[:permission]
+
+ with_scope(:find => { :conditions => cond.conditions }) do
+ find(:all, provider_options[:find_options])
+ end
+ end
+ end
+ end
+ end
+ end
+end