##// END OF EJS Templates
Merged r14030 and r14031....
Jean-Philippe Lang -
r13657:86c77bedd49a merge
parent child
Show More
@@ -1,11 +1,12
1 1 class Meeting < ActiveRecord::Base
2 2 belongs_to :project
3 3
4 4 acts_as_event :title => Proc.new {|o| "#{o.scheduled_on} Meeting"},
5 5 :datetime => :scheduled_on,
6 6 :author => nil,
7 7 :url => Proc.new {|o| {:controller => 'meetings', :action => 'show', :id => o.id}}
8 8
9 9 acts_as_activity_provider :timestamp => 'scheduled_on',
10 :find_options => { :include => :project }
10 :scope => includes(:project),
11 :permission => nil
11 12 end
@@ -1,88 +1,87
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module Redmine
19 19 module Acts
20 20 module ActivityProvider
21 21 def self.included(base)
22 22 base.extend ClassMethods
23 23 end
24 24
25 25 module ClassMethods
26 26 def acts_as_activity_provider(options = {})
27 27 unless self.included_modules.include?(Redmine::Acts::ActivityProvider::InstanceMethods)
28 28 cattr_accessor :activity_provider_options
29 29 send :include, Redmine::Acts::ActivityProvider::InstanceMethods
30 30 end
31 31
32 options.assert_valid_keys(:type, :permission, :timestamp, :author_key, :find_options, :scope)
32 options.assert_valid_keys(:type, :permission, :timestamp, :author_key, :scope)
33 33 self.activity_provider_options ||= {}
34 34
35 35 # One model can provide different event types
36 36 # We store these options in activity_provider_options hash
37 37 event_type = options.delete(:type) || self.name.underscore.pluralize
38 38
39 39 options[:timestamp] ||= "#{table_name}.created_on"
40 options[:find_options] ||= {}
41 40 options[:author_key] = "#{table_name}.#{options[:author_key]}" if options[:author_key].is_a?(Symbol)
42 41 self.activity_provider_options[event_type] = options
43 42 end
44 43 end
45 44
46 45 module InstanceMethods
47 46 def self.included(base)
48 47 base.extend ClassMethods
49 48 end
50 49
51 50 module ClassMethods
52 51 # Returns events of type event_type visible by user that occured between from and to
53 52 def find_events(event_type, user, from, to, options)
54 53 provider_options = activity_provider_options[event_type]
55 54 raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
56 55
57 56 scope = (provider_options[:scope] || self)
58 57
59 58 if from && to
60 59 scope = scope.where("#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to)
61 60 end
62 61
63 62 if options[:author]
64 63 return [] if provider_options[:author_key].nil?
65 64 scope = scope.where("#{provider_options[:author_key]} = ?", options[:author].id)
66 65 end
67 66
68 67 if options[:limit]
69 68 # id and creation time should be in same order in most cases
70 69 scope = scope.reorder("#{table_name}.id DESC").limit(options[:limit])
71 70 end
72 71
73 72 if provider_options.has_key?(:permission)
74 73 scope = scope.where(Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options))
75 74 elsif respond_to?(:visible)
76 75 scope = scope.visible(user, options)
77 76 else
78 77 ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option."
79 78 scope = scope.where(Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
80 79 end
81 80
82 81 scope.to_a
83 82 end
84 83 end
85 84 end
86 85 end
87 86 end
88 87 end
General Comments 0
You need to be logged in to leave comments. Login now