Reputation: 31
Am planning on using declarative authorization in a Rails 3 app. I have the following model relationships:
class Role < ActiveRecord::Base
has_many :permissions, :dependent => :destroy
has_many :users, :through => :permissions, :uniq => true
end
class Permission < ActiveRecord::Base
belongs_to :user
belongs_to :role
belongs_to :context
end
class User < ActiveRecord::Base
has_many :permissions, :dependent => :destroy
has_many :roles, :through => :permissions
roles.map do |role|
role.name.underscore.to_sym
end
end
class Context < ActiveRecord::Base
has_many :contexts, :dependent => :destroy
end
The concept here is that I am going to segment various datasets into different contexts. However, a given user may have different roles for each context -- maybe an admin in one context and a basic user in another. I have implemented current_user and current_context for use in controllers and views.
I plan on using the if_attribute to reference the right permission on the right dataset. However, the question is how do I make the def role_symbols only return the roles associated with the user in a particular context when I cannot/should not reference current_context in a model (where role_symbols is defined).
Any ideas?
Upvotes: 2
Views: 577
Reputation: 31
Was luck enough to find the answer here:
http://blog.drivingthevortex.nl/2010/01/24/using-declarative_authorization-with-subdomains/
Upvotes: 1