簡體   English   中英

將 cancancan 的 check_authorization 與帶有自定義控制器的設計一起使用?

[英]Using cancancan's check_authorization with devise with custom controllers?

TL; DR (下面的完整問題)

cancan 帶有check_authorization ,它可以讓您知道您是否忘記為應用程序的任何部分添加授權。 本質上,我只想知道是否有必要為應用程序的“設計”部分添加授權 - 或者設計是否開箱即用? (例如,如果一個用戶可以更改另一個用戶的密碼,那將是非常糟糕的! - 這是否需要通過 cancan 來阻止,或者是否設計確保已經開箱即用?)

完整問題

我有設計和康康設置,一切似乎都有效。

當我添加check_authorization ,一切都繼續工作,除了登錄和退出不再起作用

CanCan::AuthorizationNotPerformed in Devise::SessionsController#destroy
This action failed the check_authorization because it does not authorize_resource. Add skip_authorization_check to bypass this check.
Extracted source (around line #266):
264
265
266
267
268
269
              
          next if options[:unless] && controller.send(options[:unless])

          raise AuthorizationNotPerformed,
                'This action failed the check_authorization because it does not authorize_resource. '\
                'Add skip_authorization_check to bypass this check.'
        end

奇怪的是,當用戶更新他們的信息時,效果很好(沒有錯誤)

任何想法/指針非常感謝

另外,我應該在設備控制器上skip_authorization_check嗎? 盡管錯誤消息暗示了這一點,但聽起來很冒險

最后,我不完全知道如何訪問設計控制器以添加skip_authorization_check 這是我的目錄(使用用戶控制器進行設計)

在此處輸入圖片說明

答案是您不必擔心skip_authorization_check控制器上的skip_authorization_check

如果您收到任何其他控制器的此錯誤消息:

CanCan::AuthorizationNotPerformed (This action failed the check_authorization because it does not authorize_resource. Add skip_authorization_check to bypass this check.):

那么解決方案是要么

  1. 為需要它的資源(或其部分)添加授權,或
  2. 如果資源不需要授權,只需跳過授權檢查。

可以通過將其添加到資源來跳過授權檢查

skip_authorization_check

你可以使用onlyexcept像這樣

skip_authorization_check except: [:index]

skip_authorization_check only: [:show, :edit]

暫無
暫無

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

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