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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user