用户模型声明授权'if_attribute'问题

用户模型声明授权'if_attribute'问题

问题描述:

我正在使用authlogic(2.1.3)和declarative_authorization(0.4.1)来控制对我的应用程序的访问。用户模型声明授权'if_attribute'问题

所有授权按预期工作被分配编辑者角色的用户不能更改他们(由authlogic提供的current_user)配置文件设置(用户模型的一部分)。

“访客”角色的工作方式与“管理员”一样。

我正在使用已分配编辑器角色的用户(名为'bob')。在数据库和IRB会话中验证。

authorization_rules.rb文件的相关内容:

role :guest do 

    # allow anonymous 'user' to create an account 
    has_permission_on :users, :to => [:new, :create] 

    # allow anonymous 'user' 'read-only' actions 
    has_permission_on :users, :to => [:index, :show] 

    end 

    role :editor do 

    # allow authenticated User to see other users 
    has_permission_on :users, :to => [:index, :show] 

    # allow authenticated User to update profile; doesn't work 
    has_permission_on :user, :to => [:edit, :update] do 
     if_attribute :user => is { user } 
    end 

    end 

    role :administrator do 

    # 'full control'  
    has_permission_on :users, :to => [:index, :show, :new, :create, :edit, :update, :destroy] 

    end 

我相信问题涉及if_attribute:用户=> {用户}。 if_attribute似乎暗示:用户应该是测试对象的属性(或属性),在这种情况下是用户模型,而不是事物本身。我寻找一个if_self方法或类似的东西,但我什么也没看到。

帮助表示赞赏。

找到解决方案;它确实与我怀疑的if_attribute方法有关。正确的角色设置是:

role :editor do 

    # allow authenticated user to see other users 
    has_permission_on :users, :to => [:index, :show] 

    # allow authenticated user to update profile 
    has_permission_on :users, :to => [:edit,:update] do 
    if_attribute :id => is { user.id } 
    end 

end