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