CanCan 2.0: 관리자 이름 공간의 "스푸트"가 승인되지 않았습니다.

10100 단어 cancan

묘사

여보세요,
나는 트위터와detailed the issue in this Gist를 통해 라이언과 짧은 토론을 진행했다.
이 설정은 모든 관리 컨트롤러가 계승하는 관리 명칭 공간을 포함한다AdminController.내 root_urldashboard#index를 가리키는데 enable_authorization 모든 컨트롤러 작업이 잠겨 있기 때문에 DB에서 지원하는 자원이든 아니든 간에 AdminAbility를 설정했는데 Admin 네임스페이스에만 생성됩니다.
물론 계기판 컨트롤러의 명칭 공간은Admin::DashboardController이기 때문에 나의 규칙은can :access, :dashboards이다.이 점도 참패했다
CanCan::Unauthorized in Admin::DashboardController#index
You are not authorized to access this page.
이것은 CanCan 2.0이기 때문에 통과할 수 없습니다. :class => false 이것은 load_and_authorize_resource 무효이며, 이것은 현재 지원하는 모든 내용입니다.
지금까지can :access, :all만 출근할 수 있었지만 큰 도움이 되지 않았다.무슨 생각 있어요?
See this spec 비록 이러한 규범 중 대다수가 폼 제출과 파라미터 산열을 통해 추정하는 것에 더 관심을 갖는 것 같지만...-나는 창설/편집을 가정합니까?해봤어요?CanCan 2는 기본적으로 디렉터 이름을 리소스로 사용하기 때문에 작동할 수 있어야 합니다.See in the code here . 자원이 없기 때문에 load 와 authorize resource를 사용할 필요가 없습니다.

토론 #1

헤이, 라이언. - 네, 해봤어요. can :access, :dashboard- 같은 오류예요.
지적하신 바와 같이 저는 사용하지 않았습니다

토론 #2

. 단지 제가 사용할 수 없음can :access, :dashboard을 설명하려고 했습니다. 왜냐하면 CanCan 2에서 더 이상 지원하지 않기 때문입니다.load_and_authorize_resource CanCan 2가 같은 이름의 공간 컨트롤러가 아닌 Dashboard라는 최고급 컨트롤러를 보고 있는지 알고 싶습니다.직감적으로, 나는 상황이 이러면 안 된다고 생각한다. 나는 여기서 가정한다. 관리성이 Admin 명칭 공간에 있기 때문에 authorize_resource :class => false 이 명칭 공간에서 '범위' 이다.
관리 편의성can :access, :dashboard 규칙이 네임스페이스로 제한됩니까?can :access, :dashboardcan/cannot를 바탕으로 한다. 이것은 권한을 부여받은 내용이기 때문이다.나는 이것이 내 머릿속의 명칭 공간을 포함하는지 기억하지 못한다.컨트롤러에서 실행해 보십시오

토론 #셋

. 출력이 무엇인지 보십시오.그리고 params[:controller] 통화에 추가하려고 시도합니다.이 가능하다, ~할 수 있다,...raise params[:controller] 이상을 구할 때 이 질문을 하려고 했습니다. 요청이 CanCan에 걸린 것 같아서 컨트롤러에 도착할 수 없었습니다.
class ApplicationController < ActionController::Base
  protect_from_forgery
  rescue_from CanCan::Unauthorized do |exception|
    raise params[:controller]
    # redirect_to root_path, :alert => exception.message
  end  
end
이것은 상술한 관점을 증명하였다
RuntimeError in Admin::DashboardController#index
admin/dashboard
그래도
class AdminAbility
  include CanCan::Ability

  def initialize(user)
    can :access, "admin/dashboard"
  end
end
...아직도 트리거cancan :access, "admin/dashboard"에 더 많은 정보가 있습니다.

[2] pry(#<Admin::DashboardController>)> a = AdminAbility.new(current_user)
=> #<AdminAbility:0x007ffdb4502d78
 @rules=
  [#<CanCan::Rule:0x007ffdb4500a50
    @actions=[:read],
    @base_behavior=true,
    @block=nil,
    @conditions={},
    @match_all=false,
    @subjects=["admin/dashboard"]>,
   #<CanCan::Rule:0x007ffdb44fa128
    @actions=[:manage],
    @base_behavior=true,
    @block=nil,
    @conditions={},
    @match_all=false,
    @subjects=["admin/dashboard"]>]>
[3] pry(#<Admin::DashboardController>)> a.can?(:index, "admin/dashboard")
=> false
[4] pry(#<Admin::DashboardController>)> a.can? :read, "admin/dashboard"
=> false
[5] pry(#<Admin::DashboardController>)> a.can? :manage, "admin/dashboard"
=> false
[13] pry(#<Admin::DashboardController>)> new_r = CanCan::Rule.new(true, :index, "admin/dashboard")
=> #<CanCan::Rule:0x007ffdb177e258
 @actions=[:index],
 @base_behavior=true,
 @block=nil,
 @conditions={},
 @match_all=false,
 @subjects=["admin/dashboard"]>
[14] pry(#<Admin::DashboardController>)> new_r.matches_conditions?(:index,"admin/dashboard",nil)
=> true

토론 #4

가 돌아오고 있는 것 같아CanCan::Unauthorized

토론 #5

토론 #6

에 이상이 생겼다.
    def authorize!(action, subject, *args)
      #...
      if cannot?(action, subject, *args)
        message ||= unauthorized_message(action, subject)
        raise Unauthorized.new(message, action, subject)
relevant_rules_for_match(action, subject, attribute)네, 바꿔서 일하게 할게요.
    def matches_subject?(subject)
      subject = subject_name(subject) if subject_object? subject
      @expanded_subjects.include?(:all) || @expanded_subjects.include?(subject.to_sym) # || matches_subject_class?(subject)
    end
대상
    def matches_subject?(subject)
      subject = subject_name(subject) if subject_object? subject
      @expanded_subjects.include?(:all) || @expanded_subjects.include?(subject.to_sym) || @expanded_subjects.include?(subject) # || matches_subject_class?(subject)
    end
# 라이언의 생각?이게 지금 제 차이예요.
diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb
index 915a0ca..425e4d6 100644
--- a/lib/cancan/ability.rb
+++ b/lib/cancan/ability.rb
@@ -303,6 +303,7 @@ module CanCan
       rules.reverse.each_with_object([]) do |rule, relevant_rules|
         rule.expanded_actions = expand_aliases(:actions, rule.actions)
         rule.expanded_subjects = expand_aliases(:subjects, rule.subjects)
+        binding.pry
         if rule.relevant?(action, subject, attribute) && rule.specificity >= specificity
           specificity = rule.specificity if rule.base_behavior
           relevant_rules << rule
diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb
index eff4cbf..097ce02 100644
--- a/lib/cancan/rule.rb
+++ b/lib/cancan/rule.rb
@@ -100,7 +100,7 @@ module CanCan

     def matches_subject?(subject)
       subject = subject_name(subject) if subject_object? subject
-      @expanded_subjects.include?(:all) || @expanded_subjects.include?(subject.to_sym) # || matches_subject_class?(subject)
+      @expanded_subjects.include?(:all) || @expanded_subjects.include?(subject.to_sym) || @expanded_subjects.include?(subject) # || matches_subject_class?(subject)
     end

     def matches_attribute?(attribute)
이게 증거예요.
From: /Users/mdesilva/code/linode.mwdesilva.com/rails/cancan_fork/lib/cancan/ability.rb @ line 306 in CanCan::Ability#relevant_rules:

    301:     def relevant_rules(action, subject, attribute = nil)
    302:       specificity = 0
    303:       rules.reverse.each_with_object([]) do |rule, relevant_rules|
    304:         rule.expanded_actions = expand_aliases(:actions, rule.actions)
    305:         rule.expanded_subjects = expand_aliases(:subjects, rule.subjects)
 => 306:         binding.pry
    307:         if rule.relevant?(action, subject, attribute) && rule.specificity >= specificity
    308:           specificity = rule.specificity if rule.base_behavior
    309:           relevant_rules << rule
    310:         end
    311:       end

[4] pry(#<AdminAbility>)> rule
=> #<CanCan::Rule:0x007fc712cedcf0
 @actions=[:index],
 @base_behavior=true,
 @block=nil,
 @conditions={},
 @expanded_actions=[:index],
 @expanded_subjects=["admin/dashboard"],
 @match_all=false,
 @subjects=["admin/dashboard"]>
[5] pry(#<AdminAbility>)> rule.relevant?(action, subject, attribute) && rule.specificity >= specificity
=> true
나는 어쩔 수 없이 []를 바꿨다
class AdminAbility
  include CanCan::Ability
  def initialize(user)
    can :index, "admin/dashboard"
  end
end
모든 시험이 통과된 것 같아요.
mdesilva@mbpi7 [12:30:18] rails/cancan_fork {ruby-1.8.7@cancan} [bsodmike-2.0*] 
-> % rake spec
No examples matched {:focus=>true}. Running all.
...................................................................................................*.......................................................................

Pending:
  CanCan::ControllerResource should authorize nested resource through parent association on index action
    # No reason given
    # ./spec/cancan/controller_resource_spec.rb:221

Finished in 0.79568 seconds
171 examples, 0 failures, 1 pending
if cannot?현재 172건의 테스트가 있습니다.
mdesilva@mbpi7 [01:48:38] rails/cancan_fork {ruby-1.8.7@cancan} [bsodmike-2.0*] 
-> % rake spec                                                            141 ↵
No examples matched {:focus=>true}. Running all.
...................................................................................................*........................................................................

Pending:
  CanCan::ControllerResource should authorize nested resource through parent association on index action
    # No reason given
    # ./spec/cancan/controller_resource_spec.rb:221

Finished in 0.78287 seconds
172 examples, 0 failures, 1 pending

토론 #7

마무리, 라이언이 당신의 복구에 녹아든 것 같아서요.고맙습니다.
2012년 5월 15일 오전 5:32, "데릭 푸리오" [email protected]
쓰기:

Closing this out as it seem Ryan has merged in your fixes.


Reply to this email directly or view it on GitHub: https://github.com/ryanb/cancan/issues/565#issuecomment-5707161

좋은 웹페이지 즐겨찾기