Railsプロジェクトのアクセス許可に宣言型承認gemを使用しており、ユーザーのアクセス許可に基づいてモデルからの出力を制限しようとしています。
私の省略された認証ファイルは次のようになります。
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またはpermited_toを使用したドキュメントのAuthorizationInModelオブジェクトを使用してこれがサポートされているようです。ドキュメントに基づいてこれらの関数を使用する方法や、現在のモデルに対する現在のユーザーの特権のリストを返す方法を理解できませんでした。
何か案は?