简体   繁体   English

CanCan复杂的能力定义

[英]CanCan complex ability definition

I have a Task object. 我有一个Task对象。

Tasks belong to a user OR a company. 任务属于用户或公司。

A user can belong to many companies through employmentships (like a regional manager). 用户可以通过雇佣关系(如区域经理)属于许多公司。

Is there a way that I can do a check with cancan to see if a task either belongs to the user or one of the companies they belong to? 有没有办法我可以用cancan检查任务是属于用户还是属于他们所属的公司之一?

ie

can :manage, Task, do |task|
   task.user_id == user.id || user.companies.each do |company|
     task.company_id == company.id
   end
end

Yes you can, If I understood this well, something like this should work: 是的你可以,如果我理解这一点,这样的事情应该有效:

can :manage, Task, do |task|
   task.user_id == user.id || user.company_ids.include?(task.company_id)
end

Best! 最好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM