[英]Authorization on an association with CanCan,Devise and Rolify
我的應用程序中具有當前的數據庫結構:
Publisher has_many videos, has_many users
Video belongs_to publisher
User belongs_to publisher
我希望能夠根據發布者向用戶授予權限,但是實際上被編輯的對象是視頻對象。
這意味着用戶X可以編輯來自發布者1和2的視頻,而用戶Y只能編輯來自發布者2和3的視頻,依此類推。 我很確定可以使用CanCan,Devise,Rolify組合來完成此操作。
有人可以在這里指出正確的方向嗎?
回復較晚,抱歉。 希望您現在已經解決了您的問題,但是我會為您提供解決方案。
在您的CanCan能力中,您具有以下內容:
def initialize(current_user)
current_user ||= User.new
can :update, Video do |video|
current_user.publisher_list.contains? video.publisher
end
end
如果user.publisher_list返回用戶可以修改的發布者列表,則上面的代碼將起作用。 我相信您也可以:
def initialize(current_user)
current_user ||= User.new
can :update, Video, publisher: {id: current_user.publisher_list}
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.