skill-assessment-app/app/policies/result_policy.rb

42 lines
846 B
Ruby
Raw Normal View History

2017-05-04 14:02:11 -05:00
# 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