Adds ability to use Scope query with Mongoid

Same limitations apply as with active record
* can not be OR'd with other rules for same ability/controller
This commit is contained in:
Ryan Ahearn
2011-04-15 16:58:19 -04:00
parent b1424dfa49
commit 2b6204117f
2 changed files with 11 additions and 1 deletions
+3 -1
View File
@@ -18,6 +18,8 @@ module CanCan
def database_records
if @rules.size == 0
@model_class.where(:_id => {'$exists' => false, '$type' => 7}) # return no records in Mongoid
elsif @rules.size == 1 && @rules[0].conditions.is_a?(Mongoid::Criteria)
@rules[0].conditions
else
@rules.inject(@model_class.all) do |records, rule|
if rule.conditions.empty?
@@ -37,4 +39,4 @@ end
# simplest way to add `accessible_by` to all Mongoid Documents
module Mongoid::Document::ClassMethods
include CanCan::ModelAdditions::ClassMethods
end
end