0
我的用例是,如果用戶有角色:agency
,他可以看到客戶。但我必須使用客戶和機構之間的鏈接來驗證這一點。看看下面的代碼:如何配置專家顯示屬於父母債券
class Agency < ApplicationRecord
has_many :agency_clients
has_many :clients, through: :agency_clients
resourcify
end
class AgencyClient < ActiveRecord::Base
belongs_to :agency
belongs_to :client
end
class Client < ApplicationRecord
has_many :agency_clients
has_many :agencies, through: :agency_clients
resourcify
end
class ClientPolicy < ApplicationPolicy
def show?
user.has_role?(:admin) || user.has_role?(:client, record)
end
class Scope < Scope
def resolve
if user.has_role? :admin
scope.all
elsif user.has_role? :client, :any
scope.with_role(:client, user)
else
scope.none
end
end
end
end
謝謝!