if_attribute 关于声明性授权
我有这样的多对多关系: 用户通过隶属关系拥有多个组织,反之亦然。
我正在使用声明性组织,并且我只希望用户在有隶属关系并且隶属关系的 affiliationtype 属性是特定值的情况下编辑特定组织。
因此,从属关系有 3 列,user_id、organization_id 和 affiliationtype_id
我可以这样做:
o = Organization.find(:first)
o.affiliatons[0].user and get the user
现在我希望这样做:
has_permission_on [:organizations], :to => :edit do
if_attribute (...)
end
if_attribute 应该查看当前用户是否是organization.affiliation[?].user 以及organization.affiliation[?]。 affiliationtype_id = "3"
我希望这是语法问题......我真的需要让它工作。
I have a many-to-many relationship like this:
A user has_many organizations through affiliations and vice-versa.
I'm using declarative organizations and I only want a user to edit a particular organization if he is affiliated and the affiliationtype attribute of affiliation is a particular value.
So affiliations has 3 columns , user_id, organization_id and affiliationtype_id
I can do:
o = Organization.find(:first)
o.affiliatons[0].user and get the user
now I wish to do this:
has_permission_on [:organizations], :to => :edit do
if_attribute (...)
end
That if_attribute should see if the current user is the organization.affiliation[?].user and if the organization.affiliation[?].affiliationtype_id = "3"
I hope this is syntax issue ... I really need to get this working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
您可以使用intersects_with(&block)限制从属关系类型:
为什么不创建一个named_scope来查找affiliationtype_id = 3的从属关系?
来自 declarative_authorization 文档:
减少 has_permission_on 中的冗余块,规则可能取决于关联对象的权限:
EDIT:
You can restrict the type of affiliation with intersects_with(&block) :
Why not create a named_scope to find affiliations whose affiliationtype_id = 3?
From declarative_authorization documentation:
To reduce redundancy in has_permission_on blocks, a rule may depend on permissions on associated objects: