@@ -36,7 +36,6 module Redmine | |||||
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[:permission] = "view_#{self.name.underscore.pluralize}".to_sym unless options.has_key?(:permission) |
|
|||
40 | options[:timestamp] ||= "#{table_name}.created_on" |
|
39 | options[:timestamp] ||= "#{table_name}.created_on" | |
41 | options[:find_options] ||= {} |
|
40 | options[:find_options] ||= {} | |
42 | options[:author_key] = "#{table_name}.#{options[:author_key]}" if options[:author_key].is_a?(Symbol) |
|
41 | options[:author_key] = "#{table_name}.#{options[:author_key]}" if options[:author_key].is_a?(Symbol) | |
@@ -60,20 +59,31 module Redmine | |||||
60 | if from && to |
|
59 | if from && to | |
61 | cond.add(["#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to]) |
|
60 | cond.add(["#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to]) | |
62 | end |
|
61 | end | |
|
62 | ||||
63 | if options[:author] |
|
63 | if options[:author] | |
64 | return [] if provider_options[:author_key].nil? |
|
64 | return [] if provider_options[:author_key].nil? | |
65 | cond.add(["#{provider_options[:author_key]} = ?", options[:author].id]) |
|
65 | cond.add(["#{provider_options[:author_key]} = ?", options[:author].id]) | |
66 | end |
|
66 | end | |
67 | cond.add(Project.allowed_to_condition(user, provider_options[:permission], options)) if provider_options[:permission] |
|
67 | ||
68 | scope_options[:conditions] = cond.conditions |
|
|||
69 | if options[:limit] |
|
68 | if options[:limit] | |
70 | # id and creation time should be in same order in most cases |
|
69 | # id and creation time should be in same order in most cases | |
71 | scope_options[:order] = "#{table_name}.id DESC" |
|
70 | scope_options[:order] = "#{table_name}.id DESC" | |
72 | scope_options[:limit] = options[:limit] |
|
71 | scope_options[:limit] = options[:limit] | |
73 | end |
|
72 | end | |
74 |
|
73 | |||
|
74 | scope = self | |||
|
75 | if provider_options.has_key?(:permission) | |||
|
76 | cond.add(Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options)) | |||
|
77 | elsif respond_to?(:visible) | |||
|
78 | scope = scope.visible(user, options) | |||
|
79 | else | |||
|
80 | 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." | |||
|
81 | cond.add(Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) | |||
|
82 | end | |||
|
83 | scope_options[:conditions] = cond.conditions | |||
|
84 | ||||
75 | with_scope(:find => scope_options) do |
|
85 | with_scope(:find => scope_options) do | |
76 | find(:all, provider_options[:find_options].dup) |
|
86 | scope.find(:all, provider_options[:find_options].dup) | |
77 | end |
|
87 | end | |
78 | end |
|
88 | end | |
79 | end |
|
89 | end |
General Comments 0
You need to be logged in to leave comments.
Login now