2016-01-23 75 views
0

我已安装了cancan和devise。现在它只是限制用户登录和某些控制器。我想扩大用户只能访问他们工作公司的记录的权限:
*邮寄者邮寄我们对潜在客户的邮件。
* Customer_order当然是客户订单。所有用户只能在某些记录上工作

user.company_id == mailers.company_id 
OR user.company.id == customer_order.company_id 

如果这些匹配,那么用户可以对这些记录执行CRUD。

回答

0

只需检查before_filter中的权限即可。 如果你有一个companies_controller你可以这样做:

before_filter :check_permission, only: [:show, :new, :create] # and all the actions you want to protect 

# Your actions 

private 

def check_permission 
    # current_user is available if you're using Devise 
    # you have to set mailers somehow, maybe with another filter 
    unless current_user.company_id == @mailers.company_id 
    redirect_to root_path 
    end 
end 
相关问题