policies and auto review builds
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
module Admin
|
||||
class VoteController < AdminController
|
||||
def up
|
||||
authorize ReviewerVote
|
||||
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
||||
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
||||
current_user.cast_yea_on(@candidate)
|
||||
|
||||
results = {
|
||||
@ -16,8 +16,8 @@ module Admin
|
||||
end
|
||||
|
||||
def down
|
||||
authorize ReviewerVote
|
||||
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
||||
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
||||
current_user.cast_nay_on(@candidate)
|
||||
|
||||
results = {
|
||||
@ -30,8 +30,8 @@ module Admin
|
||||
end
|
||||
|
||||
def approve
|
||||
authorize ReviewerVote
|
||||
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
||||
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
||||
current_user.approve_candidate(@candidate)
|
||||
|
||||
results = {
|
||||
@ -43,8 +43,8 @@ module Admin
|
||||
end
|
||||
|
||||
def decline
|
||||
authorize ReviewerVote
|
||||
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
||||
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
||||
current_user.decline_candidate(@candidate)
|
||||
|
||||
results = {
|
||||
|
@ -36,6 +36,7 @@ class QuizController < ApplicationController
|
||||
|
||||
def complete_and_email
|
||||
if current_candidate.update_attributes(completed: true)
|
||||
current_candidate.build_reviews
|
||||
CandidateMailer.submitted(current_candidate).deliver_later
|
||||
RecruiterMailer.candidate_submitted(current_candidate).deliver_later
|
||||
ReviewerMailer.candidate_submission(current_candidate).deliver_later
|
||||
|
@ -5,6 +5,7 @@ class Candidate < ApplicationRecord
|
||||
has_many :answers
|
||||
belongs_to :recruiter, class_name: "User"
|
||||
has_many :votes, class_name: "ReviewerVote"
|
||||
has_many :reviewers, through: :quiz
|
||||
|
||||
serialize :email, CryptSerializer
|
||||
|
||||
@ -22,6 +23,12 @@ class Candidate < ApplicationRecord
|
||||
declined: 2
|
||||
}
|
||||
|
||||
def build_reviews
|
||||
reviewers.each do |reviewer|
|
||||
votes.find_or_create_by(user_id: reviewer.id)
|
||||
end
|
||||
end
|
||||
|
||||
def submitted_answers
|
||||
answers.where(submitted: true)
|
||||
end
|
||||
|
@ -20,13 +20,13 @@ class User < ApplicationRecord
|
||||
|
||||
# Voting
|
||||
def cast_yea_on candidate
|
||||
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
|
||||
vote = votes.find_by(candidate_id: candidate.to_i)
|
||||
vote.vote = :yea
|
||||
vote.save
|
||||
end
|
||||
|
||||
def cast_nay_on candidate
|
||||
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
|
||||
vote = votes.find_by(candidate_id: candidate.to_i)
|
||||
vote.vote = :nay
|
||||
vote.save
|
||||
end
|
||||
@ -34,7 +34,7 @@ class User < ApplicationRecord
|
||||
def approve_candidate candidate
|
||||
candidate = Candidate.find(candidate.to_i)
|
||||
|
||||
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
|
||||
vote = votes.find_by(candidate_id: candidate.to_i)
|
||||
vote.veto = :approved
|
||||
candidate.update_attribute(:review_status, :approved) if vote.save
|
||||
end
|
||||
@ -42,7 +42,7 @@ class User < ApplicationRecord
|
||||
def decline_candidate candidate
|
||||
candidate = Candidate.find(candidate.to_i)
|
||||
|
||||
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
|
||||
vote = votes.find_by(candidate_id: candidate.to_i)
|
||||
vote.veto = :rejected
|
||||
candidate.update_attribute(:review_status, :declined) if vote.save
|
||||
end
|
||||
@ -50,7 +50,8 @@ class User < ApplicationRecord
|
||||
def my_vote candidate
|
||||
candidate = Candidate.find(candidate.to_i)
|
||||
|
||||
votes.find_by(candidate_id: candidate.id).vote
|
||||
my_vote = votes.find_by(candidate_id: candidate.id)
|
||||
my_vote.vote unless my_vote.nil?
|
||||
end
|
||||
|
||||
# Roles
|
||||
@ -83,7 +84,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def acts_as_reviewer?
|
||||
%w(admin reviewer).include? role
|
||||
%w(admin manager reviewer).include? role
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -8,21 +8,26 @@ class ReviewerVotePolicy < ApplicationPolicy
|
||||
# Only Managers, and Admins, can veto a quiz result
|
||||
|
||||
def up?
|
||||
# return true if user.reviewees.include? record.candidate
|
||||
true
|
||||
return true if user.acts_as_admin?
|
||||
return false unless record.candidate.reviewers.include? user
|
||||
user.acts_as_reviewer?
|
||||
end
|
||||
|
||||
def down?
|
||||
# return true if user.acts_as_manager?
|
||||
# user.quizzes.include? record
|
||||
true
|
||||
return true if user.acts_as_admin?
|
||||
return false unless record.candidate.reviewers.include? user
|
||||
user.acts_as_reviewer?
|
||||
end
|
||||
|
||||
def approve?
|
||||
return true if user.acts_as_admin?
|
||||
return false unless record.candidate.reviewers.include? user
|
||||
user.acts_as_manager?
|
||||
end
|
||||
|
||||
def decline?
|
||||
return true if user.acts_as_admin?
|
||||
return false unless record.candidate.reviewers.include? user
|
||||
user.acts_as_manager?
|
||||
end
|
||||
|
||||
|
34
app/views/admin/result/_voting.html.erb
Normal file
34
app/views/admin/result/_voting.html.erb
Normal file
@ -0,0 +1,34 @@
|
||||
<% # TODO: This needs to be extracted into a decorator, or something. It is only a quick hack solution. %>
|
||||
|
||||
<% if current_user.acts_as_reviewer? %>
|
||||
<div class="review_meta__votes" data-id="vote-count">
|
||||
<strong>Votes: </strong>
|
||||
<%= link_to admin_up_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
Yea (<span data-id="up-votes"><%= @candidate.votes.yea.count %></span>)
|
||||
<% end %>
|
||||
<%= link_to admin_down_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
Nay (<span data-id="down-votes"><%= @candidate.votes.nay.count %></span>)
|
||||
<% end %>
|
||||
<small>(Your vote: <span data-id="my-vote"><%= current_user.my_vote(@candidate) %></span>)</small>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if current_user.acts_as_manager? %>
|
||||
<div class="review_meta__vetos" data-id="veto-status">
|
||||
<strong>Manager Vetos: </strong>
|
||||
<%= link_to admin_approve_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
<span data-id="interview-request">
|
||||
<%= @candidate.approved? ? "Requested" : "Request Interview" %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= link_to admin_decline_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
<span data-id="interview-decline">
|
||||
<%= @candidate.declined? ? "Declined" : "Decline Interview" %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% else %>
|
||||
|
||||
<strong>Candidate Interview Status: </strong><%= @candidate.review_status %>
|
||||
<% end %>
|
@ -7,36 +7,9 @@
|
||||
<strong>Years of Experience:</strong> <%= @candidate.experience %><br />
|
||||
<strong>Recruiter Email:</strong> <%= mail_to @candidate.recruiter.name, @candidate.recruiter.email %><br />
|
||||
</div>
|
||||
<div>
|
||||
<div class="review_meta__votes" data-id="vote-count">
|
||||
<strong>Votes: </strong>
|
||||
<%= link_to admin_up_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
Yea (<span data-id="up-votes"><%= @candidate.votes.yea.count %></span>)
|
||||
<% end %>
|
||||
<%= link_to admin_down_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
Nay (<span data-id="down-votes"><%= @candidate.votes.nay.count %></span>)
|
||||
<% end %>
|
||||
<small>(Your vote: <span data-id="my-vote"><%= current_user.my_vote(@candidate) %></span>)</small>
|
||||
</div>
|
||||
<% if current_user.acts_as_manager? %>
|
||||
<div class="review_meta__vetos" data-id="veto-status">
|
||||
<strong>Manager Vetos: </strong>
|
||||
<%= link_to admin_approve_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
<span data-id="interview-request">
|
||||
<%= @candidate.approved? ? "Requested" : "Request Interview" %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= link_to admin_decline_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||
<span data-id="interview-decline">
|
||||
<%= @candidate.declined? ? "Declined" : "Decline Interview" %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<strong>Candidate Interview Status: </strong><%= @candidate.review_status %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div><%= render partial: 'voting' %></div>
|
||||
</div>
|
||||
|
||||
<% @quiz.each do |question| %>
|
||||
<%= form_for(:answer, url: '#never-post', html:{id: 'summary-form'}) do |form| %>
|
||||
|
Reference in New Issue
Block a user