Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

accessible_by w/ mongoid criteria #611

Closed
brewster1134 opened this Issue · 2 comments

1 participant

@brewster1134

EDITED to have a much simpler description of the problem :)

i have an ability defined with mongoid criteria, but it is not populating into the mongoid criteria selector attribute.

can :manage, Number, :issuer_id.in => user.owner_of.map{ |p| p.id }

returns

-> Number.accessible_by(Ability.new(user))
=> #<Mongoid::Criteria
  selector: {},
  options:  {},
  class:    Number,
  embedded: false>

if i query mongoid directly with the same criteria

-> Number.where(:issuer_id.in => user.owner_of.map{ |p| p.id })
=> #<Mongoid::Criteria
  selector: {:issuer_id=>{"$in"=>[BSON::ObjectId('4f9ae0f1e1607c7a67000002')]}},
  options:  {},
  class:    Number,
  embedded: false>

the ability instance returns...

-> Ability.new(user)
=>
#<Ability:0x007f8c9d0c1030 @rules=[
  #<CanCan::Rule:0x007f8c9a5b0210
    @match_all=false,
    @base_behavior=true,
    @actions=[:manage],
    @subjects=[Number],
    @conditions={issuer_id=>[BSON::ObjectId('4f9ae0f1e1607c7a67000002')]},
    @block=nil
  >
]>

i have tried defining my abilities a variety of ways

can :manage, Number, :issuer => { :owner_id => user.id }
can :manage, Number, :issuer_id.in => user.owner_of.map{ |p| p.id }
can :manage, Number, :issuer_id => { "$in" => user.owner_of.map{ |p| p.id }}
@brewster1134

using cancan (1.6.7) & mongoid (2.4.9)

@brewster1134

solved it. user.owner_of.map{ |p| p.id } was returning an array of BSON objects. i needed an array of strings. user.owner_of.map{ |p| p.id.to_s } solved it. gah!

would a check for this make sense in the mongoid adapter?

@brewster1134 brewster1134 reopened this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.