【发布时间】:2017-10-02 19:08:17
【问题描述】:
我正在尝试使用此权威政策来禁止具有临床医生角色的用户访问患者控制器上的索引操作。范围部分目前正在按我希望的方式工作,但是根据当前编写的政策,我仍然可以以临床医生用户的身份访问 /patients。我究竟做错了什么?谢谢你的帮助!
这是我的角色定义:
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]
【问题讨论】:
标签: ruby-on-rails pundit