Use scopes instead of ARCondition.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8088 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
0a92e382fa
commit
4485745dc6
@ -54,37 +54,32 @@ module Redmine
|
|||||||
provider_options = activity_provider_options[event_type]
|
provider_options = activity_provider_options[event_type]
|
||||||
raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
|
raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
|
||||||
|
|
||||||
scope_options = {}
|
scope = self
|
||||||
cond = ARCondition.new
|
|
||||||
if from && to
|
if from && to
|
||||||
cond.add(["#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to])
|
scope = scope.scoped(:conditions => ["#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to])
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:author]
|
if options[:author]
|
||||||
return [] if provider_options[:author_key].nil?
|
return [] if provider_options[:author_key].nil?
|
||||||
cond.add(["#{provider_options[:author_key]} = ?", options[:author].id])
|
scope = scope.scoped(:conditions => ["#{provider_options[:author_key]} = ?", options[:author].id])
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:limit]
|
if options[:limit]
|
||||||
# id and creation time should be in same order in most cases
|
# id and creation time should be in same order in most cases
|
||||||
scope_options[:order] = "#{table_name}.id DESC"
|
scope = scope.scoped(:order => "#{table_name}.id DESC", :limit => options[:limit])
|
||||||
scope_options[:limit] = options[:limit]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scope = self
|
|
||||||
if provider_options.has_key?(:permission)
|
if provider_options.has_key?(:permission)
|
||||||
cond.add(Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options))
|
scope = scope.scoped(:conditions => Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options))
|
||||||
elsif respond_to?(:visible)
|
elsif respond_to?(:visible)
|
||||||
scope = scope.visible(user, options)
|
scope = scope.visible(user, options)
|
||||||
else
|
else
|
||||||
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."
|
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."
|
||||||
cond.add(Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
|
scope = scope.scoped(:conditions => Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
|
||||||
end
|
end
|
||||||
scope_options[:conditions] = cond.conditions
|
|
||||||
|
|
||||||
with_scope(:find => scope_options) do
|
scope.all(provider_options[:find_options].dup)
|
||||||
scope.find(:all, provider_options[:find_options].dup)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user