2016-09-20 17:19:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
class QuizPolicy < ApplicationPolicy
|
|
|
|
# Quiz Access Policy
|
|
|
|
#
|
|
|
|
# Only Admins and Managers can create or update a quiz (and its questions)
|
|
|
|
# Reviewers can view any quiz they are linked to
|
|
|
|
# Recruiters can only list quiz names (for candidate assignments)
|
|
|
|
|
2016-09-21 17:04:08 -05:00
|
|
|
def index?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2016-09-20 17:19:11 -05:00
|
|
|
def view?
|
2016-09-22 13:30:30 -05:00
|
|
|
return true if user.acts_as_manager?
|
2016-09-20 17:19:11 -05:00
|
|
|
user.quizzes.include? record
|
|
|
|
end
|
|
|
|
|
|
|
|
def create?
|
2016-09-22 13:30:30 -05:00
|
|
|
user.acts_as_manager?
|
2016-09-20 17:19:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
2016-09-22 13:30:30 -05:00
|
|
|
user.acts_as_manager?
|
2016-09-20 17:19:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
2017-05-03 16:25:32 -05:00
|
|
|
if user.acts_as_recruiter?
|
2016-09-20 17:19:11 -05:00
|
|
|
scope
|
2017-05-03 16:25:32 -05:00
|
|
|
else
|
|
|
|
scope.joins(:reviewers).where('reviewer_to_quizzes.user_id = ?', user.id)
|
2016-09-20 17:19:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|