Rails的基于对象的许可/授权引擎? [英] Rails object based permission/authorization engine?
问题描述
我要添加共享文件功能,我的应用程序,比如在谷歌文档服务。因为我看到:
I want to add "Sharing documents" feature to my app, like in google documents service. As i see:
用户可以:
- 可以列出/查看/创建/编辑/删除自己的文件
- 分享自己的文档给大家 - 它的一份公开文件
- 分享自己的文档,以具有只读访问权限的用户
- 分享自己的文档具有读写访问权限的用户
- 查看自己的文件和用户名单的人,他给了允许读取和写入
- 查看外国文件列表
- 查看/编辑外地文件具有读/写权限
请告诉我,这准许/授权解决方案是preffered我的任务是什么?
Please tell me, which permission/authorization solution is preffered for my task?
推荐答案
您可以看一下这里提供一些授权的插件:
You can look at some authorization plugins available here:
http://www.ruby-toolbox.com/categories/rails_authorization.html
至于对象级别的授权/许可,它看起来像 canable 可以做到这一点:
As for object level authorization/permission, it looks like canable can do this:
http://github.com/jnunemaker/canable
从自述文件中的例子:
class Article
include MongoMapper::Document
include Canable::Ables
userstamps! # adds creator and updater
def updatable_by?(user)
creator == user
end
def destroyable_by?(user)
updatable_by?(user)
end
end
您也可以定义一个viewable_by?方法。你仍然需要某种权限字段或文档模型关联的,但之后,你可以使用canable简化控制器/视图授权。
You could also define a viewable_by? method. You would still need some kind of permission fields or association on the document model, but after that you could use canable to simplify authorization in your controller/views.
这篇关于Rails的基于对象的许可/授权引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!