我有一个 Rails 4 应用程序,我根据我在应用程序中的模型设置编写了一个 CanCan Ability 模型。在测试时它有时会起作用,然后又不起作用。我不确定问题是什么。日志中没有任何内容可以指出问题。我也不认为它是那么干净。有关如何改进此能力模型的任何建议?这似乎非常多余和令人困惑。
if user
##
can :manage, User do |u|
case u.account
## If user is a Developer allow it to only be managed by itself (user)
when Developer
u == user
## If user is a Organization allow it to only be managed by it's founders
when Organization
u.account.founders.exists?(user)
else
false
end
end
can :manage, App do |a|
case a.appable
## If app belongs to a Developer allow it to only be managed by it owner (developer)
when Developer
a.appable.id == user.id
## If app belongs to a Organization allow it to only be managed by its organizations' founders
when Organization
a.appable.founders.exists?(user)
else
false
end
end
##
end