簡體   English   中英

聲明性授權和用戶上下文

[英]declarative_authorization and user context

我正在計划在Rails 3應用程序中使用聲明性授權。 我具有以下模型關系:

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

這里的概念是,我將把各種數據集划分為不同的上下文。 但是,給定的用戶在每種情況下可能具有不同的角色-可能是一個背景下的管理員,而另一個背景下的基本用戶。 我已經實現了current_user和current_context以便在控制器和視圖中使用。

我計划使用if_attribute在正確的數據集上引用正確的權限。 但是,問題是當我不能/不應該在模型(定義了role_symbols的模型)中引用current_context時,如何使def role_symbols僅返回特定上下文中與用戶關聯的角色。

有任何想法嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM