2017-10-02 19 views
0

역할 전문가가있는 사용자가 patient 컨트롤러의 색인 작업에 액세스 할 수 없도록이 전문 정책을 사용하려고합니다. 스코프 섹션은 현재 내가 원하는대로 작동하지만 현재 작성된 정책으로 임상가 사용자로서/환자에게 액세스 할 수 있습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 어떤 도움을 주셔서 감사합니다! 여기명성 정책 색인 작업 제한 및 특정 역할보기

내 역할 정의입니다 :

enum role: { staff: 0, clinician: 1, admin: 2 } 

환자의 정책

class PatientPolicy < ApplicationPolicy 
    class Scope 
    attr_reader :user, :scope 

    def initialize(user, scope) 
     @user = user 
     @scope = scope 
    end 

    def resolve 
     if user.admin? 
     scope.all 
     else 
     scope.joins(:user).merge(User.where(university: user.university)) 
     end 
    end 
    end 

def index? 
    user.staff? or user.admin? 
end 

end 

환자 컨트롤러 :

def index 
    @patients = policy_scope(Patient) 
end 
[rest of controller] 

답변

1

자체 목표 : 환자 컨트롤러의 색인 작업에 권한 부여 행을 추가해야했습니다.

def index 
    authorize Patient 
    @patients = policy_scope(Patient) 
end