我正在使用聲明性授權gem來獲取rails項目中的權限,我試圖根據用戶權限限制模型的輸出。使用declarative_authorization來限制模型中的結果
我的縮寫授權文件看起來是這樣的:
roles do
role :supervisor
has_permission_on :people, :to => :manage_all
end
role :basic_user
has_permission_on :people, :to => :manage_subordinates
end
end
privileges do
privilege :manage_subordinates do
includes :subordinate_records
end
privilege :manage_all do
includes :all_records
end
end
在我的人的模型,我有我想這個樣子
def self.supervised_by(user)
if user.permitted_to? :all_records
#return all of the records
elsif user.permitted_to? :subordinate_records
#return some of the records
else
#return none of the records
end
end
它看起來像有支持靜態方法這在使用with_permissions_to或allowed_to的文檔中使用AuthorizationInModel對象。我一直無法知道如何根據文檔使用這些函數,或者如何在當前模型中返回當前用戶的權限列表。
任何想法?