Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for multiparameter attributes

Multiparameter attributes, like those used with datetime_select and
time_select are understood, and the parenthesized portion is stripped
when checking permissions.

For example:
  @ability.can :update, :article, :date
will allow
  @ability.can? :update, :article, 'date(1i)'
  @ability.can? :update, :article, 'date(2i)'
  @ability.can? :update, :article, 'date(3i)'
  • Loading branch information...
commit 1728080452c65e1ae6fbbf7ad72b0857c6d497bd 1 parent aed9f26
@jhawthorn jhawthorn authored
Showing with 17 additions and 0 deletions.
  1. +3 −0  lib/cancan/ability.rb
  2. +14 −0 spec/cancan/ability_spec.rb
View
3  lib/cancan/ability.rb
@@ -306,6 +306,9 @@ def rules
# Returns an array of Rule instances which match the action and subject
# This does not take into consideration any hash conditions or block statements
def relevant_rules(action, subject, attribute = nil)
+ if attribute
+ attribute = attribute.to_s.split('(').first.to_sym
+ end
specificity = 0
rules.reverse.each_with_object([]) do |rule, relevant_rules|
rule.expanded_actions = expand_aliases(:actions, rule.actions)
View
14 spec/cancan/ability_spec.rb
@@ -224,6 +224,20 @@
@ability.can?(:update, :users, "name").should be_true
end
+ it "understands multiparameter attributes as strings" do
+ @ability.can :update, :users, :date
+ @ability.can?(:update, :users, "date(i1)").should be_true
+ @ability.can?(:update, :users, "date(i2)").should be_true
+ @ability.can?(:update, :users, "date(i3)").should be_true
+ end
+
+ it "understands multiparameter attributes as symbols" do
+ @ability.can :update, :users, :date
+ @ability.can?(:update, :users, :"date(i1)").should be_true
+ @ability.can?(:update, :users, :"date(i2)").should be_true
+ @ability.can?(:update, :users, :"date(i3)").should be_true
+ end
+
it "combines attribute check with conditions hash" do
@ability.can :update, :ranges, :begin => 1
@ability.can :update, :ranges, :name, :begin => 2
Please sign in to comment.
Something went wrong with that request. Please try again.