2

アプリケーションへのアクセスを制御するために、authlogic(2.1.3)とdeclarative_authorization(0.4.1)を使用しています。

編集者の役割が割り当てられているユーザーが(authlogicによって提供されるcurrent_user)プロファイル設定(ユーザーモデルの一部)を変更できないことを除いて、すべての承認は期待どおりに機能します。

「ゲスト」の役割は、「管理者」と同様に期待どおりに機能します。

編集者の役割が割り当てられているユーザー(「bob」という名前)を使用しています。データベースおよびIRBセッションで検証されました。

authentication_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:user=>{user}に関連していると思います。if_attributeは、:userが、モノ自体ではなく、テスト対象のモノ(この場合はユーザーモデル)の属性(またはプロパティ)であることを示唆しているようです。if_selfメソッドなどを探しましたが、何も見つかりませんでした。

ヘルプをいただければ幸いです。

4

1 に答える 1

3

解決策を見つけました。私が思ったように、それは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
于 2010-05-27T19:46:54.153 に答える