adding fully_authorized? method to Ability to check if conditions are considered in authorize! call
This commit is contained in:
@@ -219,6 +219,8 @@ module CanCan
|
||||
if cannot?(action, subject, *args)
|
||||
message ||= unauthorized_message(action, subject)
|
||||
raise AccessDenied.new(message, action, subject)
|
||||
else
|
||||
fully_authorized!(action, subject) unless subject.kind_of?(Symbol) && has_instance_conditions?(action, subject)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -246,6 +248,20 @@ module CanCan
|
||||
relevant_rules(action, subject).any?(&:only_raw_sql?)
|
||||
end
|
||||
|
||||
def has_instance_conditions?(action, subject)
|
||||
relevant_rules(action, subject).any?(&:instance_conditions?)
|
||||
end
|
||||
|
||||
def fully_authorized?(action, subject)
|
||||
@fully_authorized ||= []
|
||||
@fully_authorized.include? [action, subject]
|
||||
end
|
||||
|
||||
def fully_authorized!(action, subject)
|
||||
@fully_authorized ||= []
|
||||
@fully_authorized << [action, subject]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unauthorized_message_keys(action, subject)
|
||||
|
||||
@@ -51,6 +51,10 @@ module CanCan
|
||||
@block.nil? && !conditions_empty? && !@conditions.kind_of?(Hash)
|
||||
end
|
||||
|
||||
def instance_conditions?
|
||||
@block || !conditions_empty?
|
||||
end
|
||||
|
||||
def conditions_empty?
|
||||
@conditions == {} || @conditions.nil?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user