Skip to content

accessible_by and mongoid: should use $nin instead of $ne #842

Open
thehappycoder opened this Issue Mar 22, 2013 · 1 comment

2 participants

@thehappycoder

class Ability
include CanCan::Ability

SUPERADMIN_CLIENTS = %w[radionet xf miscxf]

def initialize(user)
user ||= User.new

if user.superadmin?
  can :manage, :all
elsif user.admin?
  can :read, [Device, Transport]
end

if user.admin?
  can :index, Client
  can [:show], Client, :name.nin => SUPERADMIN_CLIENTS
  cannot [:manage], Client, name: SUPERADMIN_CLIENTS
  cannot :create, Client
end

end

Client.accessible_by(current_ability).asc(:created_at) at controller's index action generates this:
MOPED: 192.168.0.100:27017 QUERY database=mon_development collection=clients selector={"$query"=>{"name"=>{"$ne"=>["radionet", "xf", "miscxf"]}}, "$orderby"=>{"created_at"=>1}} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.6049ms)

But in reality it should be using $nin

@xhoy
xhoy commented Apr 10, 2014

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still.
Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!

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.