我試圖使用declarative_authorization來保護Rails3控制器。聲明性授權filter_access_to
該控制器具有7,REST風格的動作,三個自定義成員的行爲(激活,停用副本),和一個自定義集合操作(公共)。然而,'公開'行動只返回一條記錄。
只有自定義集合操作(公共)應當提供給身份驗證的用戶;其餘部分僅適用於current_user。
has_permission_on :foos, :to => :public
has_permission_on :foos, :to => [:full_control, :copy, :activate, :deactivate] do
if_attribute :user => is {user}
end
privilege :full_control, :includes => [:index, :show, :new, :create, :edit, :update, :destroy]
4個的自定義動作在routes.rb中文件中定義:
resources :users do
resources :foos do
collection do
get :public
end
member do
post :activate, :copy, :deactivate
end
end
end
A用戶:的has_many FOOS; Foo:belongs_to用戶。
FoosController中定義的'標準'訪問控制(filter_resource_access:nested_in =>:user)似乎控制對7個RESTful操作的訪問,但無法控制對其他4個訪問(如預期的那樣)。
當我改變FooController的到:
filter_access_to :all, :nested_in => :users, :attribute_check => true
我拿到寫着「無ID找不到富」的錯誤。
問題:
- 的文件似乎表明,一:的before_filter將自動被調用用於filter_access_to時加載富模型。我錯了嗎?我需要額外配置filter_access_to嗎?我是否需要手動配置:before_filter?
- 我是否還需要爲模型添加using_access_control以達到我的目的?當控制器中存在訪問控制時,需要將訪問控制添加到模型時,我有點不清楚。
- 該文檔描述了一個名爲'create'的特權 - 它被定義爲:privilege:create,:includes =>:new。另外,對於新行爲,這個特權是否會因爲其名稱而自動包含:create動作?
- 如果authentication_rules.rb文件改變時,這臺服務器需要重新啓動以應用新規則?
你找到這些問題的答案嗎?我面臨類似的問題。 – Shreyas 2011-01-19 12:32:05