【问题标题】:declarative_authorization and user contextdeclarative_authorization 和用户上下文
【发布时间】:2011-05-27 10:08:42
【问题描述】:

我计划在 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 来引用正确数据集的正确权限。 但是,问题是当我不能/不应该在模型中引用 current_context(其中定义了 role_symbols)时,如何使 def role_symbols 仅返回与特定上下文中的用户关联的角色。

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails declarative-authorization


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 2010-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多