2016-11-19 16:34:48 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
class ReviewerVotePolicy < ApplicationPolicy
|
|
|
|
# Voting Policy
|
|
|
|
#
|
2017-02-27 13:41:46 -06:00
|
|
|
# Only Reviewers and Managers can cast a vote on a quiz result
|
2016-11-19 16:34:48 -06:00
|
|
|
#
|
|
|
|
# Reviewers can vote any quiz they are linked to
|
|
|
|
# Only Managers, and Admins, can veto a quiz result
|
|
|
|
|
|
|
|
def up?
|
2017-02-27 13:41:46 -06:00
|
|
|
return false unless user.commented_on?(record.candidate.test_hash)
|
2016-11-20 13:07:53 -06:00
|
|
|
return false unless record.candidate.reviewers.include? user
|
2017-02-27 13:41:46 -06:00
|
|
|
return false if user.admin?
|
2016-11-20 13:07:53 -06:00
|
|
|
user.acts_as_reviewer?
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def down?
|
2017-02-27 13:41:46 -06:00
|
|
|
return false unless user.commented_on?(record.candidate.test_hash)
|
2016-11-20 13:07:53 -06:00
|
|
|
return false unless record.candidate.reviewers.include? user
|
2017-02-27 13:41:46 -06:00
|
|
|
return false if user.admin?
|
2016-11-20 13:07:53 -06:00
|
|
|
user.acts_as_reviewer?
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def approve?
|
2016-11-20 13:07:53 -06:00
|
|
|
return true if user.acts_as_admin?
|
|
|
|
return false unless record.candidate.reviewers.include? user
|
2016-11-19 16:34:48 -06:00
|
|
|
user.acts_as_manager?
|
|
|
|
end
|
|
|
|
|
|
|
|
def decline?
|
2016-11-20 13:07:53 -06:00
|
|
|
return true if user.acts_as_admin?
|
|
|
|
return false unless record.candidate.reviewers.include? user
|
2016-11-19 16:34:48 -06:00
|
|
|
user.acts_as_manager?
|
|
|
|
end
|
|
|
|
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
|
|
|
return ReviewerVote.none if user.recruiter?
|
|
|
|
|
|
|
|
if user.reviewer?
|
|
|
|
scope.where(user_id: user.id)
|
|
|
|
else
|
|
|
|
scope
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|