Return empty set early if no can rules are present.
Thanks dkubb!
This commit is contained in:
		
							parent
							
								
									d6851debd4
								
							
						
					
					
						commit
						16bdb8d42e
					
				@ -17,6 +17,7 @@ module CanCan
 | 
				
			|||||||
      def database_records
 | 
					      def database_records
 | 
				
			||||||
        scope = @model_class.all(:conditions => ["0 = 1"])
 | 
					        scope = @model_class.all(:conditions => ["0 = 1"])
 | 
				
			||||||
        cans, cannots = @rules.partition { |r| r.base_behavior }
 | 
					        cans, cannots = @rules.partition { |r| r.base_behavior }
 | 
				
			||||||
 | 
					        return scope if cans.empty?
 | 
				
			||||||
        # apply unions first, then differences. this mean cannot overrides can
 | 
					        # apply unions first, then differences. this mean cannot overrides can
 | 
				
			||||||
        cans.each    { |r| scope += @model_class.all(:conditions => r.conditions) }
 | 
					        cans.each    { |r| scope += @model_class.all(:conditions => r.conditions) }
 | 
				
			||||||
        cannots.each { |r| scope -= @model_class.all(:conditions => r.conditions) }
 | 
					        cannots.each { |r| scope -= @model_class.all(:conditions => r.conditions) }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user