# frozen_string_literal: true class ResultPolicy < Struct.new(:user, :result) # Result Access Policy # # Only Admins and Recruiters can view all results # Managers and Reviewers can view any completed quiz they are linked to attr_reader :user, :record def initialize(user, record) raise Pundit::NotAuthorizedError, "Must be logged in." unless user @user = user @record = record end def index? true end # def view? # return true if user.acts_as_recruiter? # user.reviewees.include? record # end class Scope attr_reader :user, :scope def initialize(user, scope) @user = user @scope = scope end def resolve if user.acts_as_recruiter? Candidate.where(completed: true) else user.reviewees.where(completed: true) end end end end