vote/veto processing
This commit is contained in:
@ -16,6 +16,35 @@ class User < ApplicationRecord
|
||||
save
|
||||
end
|
||||
|
||||
# Voting
|
||||
def cast_yea_on candidate
|
||||
vote = votes.find_or_create_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.vote = :nay
|
||||
vote.save
|
||||
end
|
||||
|
||||
def approve_candidate candidate
|
||||
candidate = Candidate.find(candidate.to_i)
|
||||
|
||||
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
|
||||
vote.veto = :approved
|
||||
candidate.update_attribute(:review_status, :approved) if vote.save
|
||||
end
|
||||
|
||||
def decline_candidate candidate
|
||||
candidate = Candidate.find(candidate.to_i)
|
||||
|
||||
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
|
||||
vote.veto = :rejected
|
||||
candidate.update_attribute(:review_status, :declined) if vote.save
|
||||
end
|
||||
|
||||
# Roles
|
||||
def admin?
|
||||
'admin' == role
|
||||
|
Reference in New Issue
Block a user