removing skipping feature in ControllerResource for now

This commit is contained in:
Ryan Bates
2011-03-25 16:29:04 -07:00
parent 35fbee578f
commit 5d68caefd0
4 changed files with 84 additions and 91 deletions
+1 -1
View File
@@ -261,7 +261,7 @@ module CanCan
break if options[:if] && !controller.send(options[:if])
break if options[:unless] && controller.send(options[:unless])
unless controller.current_ability.fully_authorized? controller.params[:action], controller.params[:controller]
raise CanCan::InsufficientAuthorizationCheck, "Authorization check is not sufficient for this action. This is probably because you have a conditions or attributes defined in Ability and are not checking for them in the action."
raise CanCan::InsufficientAuthorizationCheck, "Authorization check is not sufficient for this action. This is probably because you have conditions or attributes defined in Ability and are not checking for them in the action. One way to solve this is adding load_and_authorize_resource to this controller."
end
end
rescue_from(CanCan::Unauthorized, &block) if block
+17 -24
View File
@@ -16,9 +16,6 @@ module CanCan
@params = controller.params
@options = args.extract_options!
@name = args.first
raise CanCan::ImplementationRemoved, "The :nested option is no longer supported, instead use :through with separate load/authorize call." if @options[:nested]
raise CanCan::ImplementationRemoved, "The :name option is no longer supported, instead pass the name as the first argument." if @options[:name]
raise CanCan::ImplementationRemoved, "The :resource option has been renamed back to :class, use false if no class." if @options[:resource]
end
def load_and_authorize_resource
@@ -27,37 +24,33 @@ module CanCan
end
def load_resource
unless skip?(:load)
if load_instance?
self.resource_instance ||= load_resource_instance
elsif load_collection?
self.collection_instance ||= load_collection
end
if load_instance?
self.resource_instance ||= load_resource_instance
elsif load_collection?
self.collection_instance ||= load_collection
end
end
def authorize_resource
unless skip?(:authorize)
@controller.authorize!(authorization_action, resource_instance || subject_name_with_parent)
end
@controller.authorize!(authorization_action, resource_instance || subject_name_with_parent)
end
def parent?
@options.has_key?(:parent) ? @options[:parent] : @name && @name != name_from_controller.to_sym
end
def skip?(behavior) # This could probably use some refactoring
options = @controller.class.cancan_skipper[behavior][@name]
if options.nil?
false
elsif options == {}
true
elsif options[:except] && ![options[:except]].flatten.include?(@params[:action].to_sym)
true
elsif [options[:only]].flatten.include?(@params[:action].to_sym)
true
end
end
# def skip?(behavior) # This could probably use some refactoring
# options = @controller.class.cancan_skipper[behavior][@name]
# if options.nil?
# false
# elsif options == {}
# true
# elsif options[:except] && ![options[:except]].flatten.include?(@params[:action].to_sym)
# true
# elsif [options[:only]].flatten.include?(@params[:action].to_sym)
# true
# end
# end
protected