0
我有一個Rails 4應用程序,我基於我的模型設置在我的應用程序中編寫了一個CanCan能力模型。雖然有時測試它有效,然後它不會。我不知道是什麼問題。日誌中沒有任何內容會指出問題。無論如何,我也不認爲它是乾淨的。有關如何改進此能力模型的任何建議?這看起來非常冗雜和令人困惑。CanCan能力模型
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