declarative authorization and has_and_belongs_to_many

Posted by Michael Balsiger on Stack Overflow See other posts from Stack Overflow or by Michael Balsiger
Published on 2011-02-16T14:39:27Z Indexed on 2011/02/16 15:25 UTC
Read the original article Hit count: 303

Hi, I have a little problem with declarative-authorization. I have a User and Role Model with a has_and_belongs_to_many association.

I've created a Role named :moderator in my authorization_rules.rb

Is it possible that a User with the Role Moderator only gets the Users that have the Moderator Role assigned to it?? --> User.with_permissions_to(:index)

I thought it would be possible like that:

role :moderator do
  has_permission_on :users, :to => :index do
    if_attribute :roles => contains { ????? }
  end
end

I also created a named_scope in my User Model because I thought it would help...

class User
  has_and_belongs_to_many :roles
  named_scope :by_role, lambda { |role|
    {
      :include => :roles,
      :conditions => {"roles.name" => role}
    }
  }
end

Does anyone knows if it's possible to do this with declarative_authorization?

Thanks for your help!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about declarative-authorization