policies and auto review builds

This commit is contained in:
Mark Moser
2016-11-20 13:07:53 -06:00
parent e8e745f356
commit df997aa258
14 changed files with 124 additions and 61 deletions

View File

@ -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

View File

@ -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