簡體   English   中英

if_attribute在declarative_authorization上不適用於多個哈希

[英]if_attribute doesn't work with multiple hash on declarative_authorization

我在Rails 3.1的Ruby上使用了clarativeative_authorization。

一個群組有很多相冊(groupalbum),一個群組是由一個用戶創建的(群組表外鍵中的user_id)。 只有論壇的所有者才能創建相冊。

這是我的authorization_rules.rb:

has_permission_on [:group_albums], :to => [:create] do
    if_attribute :group =>  { :user => is_in { user.groups } }
end

這是我的GroupAlbumsControler:

class GroupAlbumsController < ApplicationController
    before_filter :set_group_album_from_params, :only => :show
    before_filter :set_group_album_new, :only => [:index, :new]
    filter_access_to :all, :attribute_check => true
    (...)
end

但這不起作用:

You are not allowed to access this action.

即使我以論壇的所有者身份登錄。

我的錯誤在哪里?

這可能不起作用的原因可能有很多。

您是否已將:index和:new添加到您的特權中?

privileges do
  privilege :manage, :includes => [:create, :read, :update, :delete]
  privilege :read, :includes => [:index, :show]
  privilege :create, :includes => :new
  privilege :update, :includes => :edit
  privilege :delete, :includes => :destroy
end

您是否對當前用戶:group_albums具有讀取權限?

has_permission_on [:group_albums], :to => [:create, :read] do
    if_attribute :group =>  { :user => is_in { user.groups } }
end

你叫哪個動作?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM