declarative authorization and has_and_belongs_to_many
- by Michael Balsiger
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!