voting requires a comment - completes #102

This commit is contained in:
Mark Moser
2017-02-27 13:41:46 -06:00
parent 538190b6bf
commit 3f41773c76
11 changed files with 84 additions and 18 deletions

View File

@ -24,6 +24,10 @@
padding-left: 30px;
width: 33%;
> div {
margin-bottom: 30px;
}
.comment-message {
margin-right: 5px;
}

View File

@ -19,6 +19,10 @@ class User < ApplicationRecord
save
end
def commented_on? test_hash
quiz_comments.where(test_hash: test_hash).count.positive?
end
# Voting
# TODO: Refactor this out of User, belongs on ReviewerVote
# ie: cast_yea(candidate, user)

View File

@ -10,7 +10,10 @@ class QuizCommentPolicy < ApplicationPolicy
end
def create?
user.acts_as_reviewer? && record.candidate.reviewers.where(id: user.id).count.positive?
return true if user.acts_as_admin?
user.acts_as_reviewer? &&
record.candidate.reviewers.where(id: user.id).count.positive?
end
def update?

View File

@ -2,20 +2,22 @@
class ReviewerVotePolicy < ApplicationPolicy
# Voting Policy
#
# Only Reviewers, Managers, and Admins, can cast a vote on a quiz result
# Only Reviewers and Managers can cast a vote on a quiz result
#
# Reviewers can vote any quiz they are linked to
# Only Managers, and Admins, can veto a quiz result
def up?
return true if user.acts_as_admin?
return false unless user.commented_on?(record.candidate.test_hash)
return false unless record.candidate.reviewers.include? user
return false if user.admin?
user.acts_as_reviewer?
end
def down?
return true if user.acts_as_admin?
return false unless user.commented_on?(record.candidate.test_hash)
return false unless record.candidate.reviewers.include? user
return false if user.admin?
user.acts_as_reviewer?
end

View File

@ -13,8 +13,6 @@
<strong>Client/Project:</strong> <%= @candidate.project %><br />
<strong>Recruiter Email:</strong> <%= mail_to @candidate.recruiter.name, @candidate.recruiter.email %><br />
</div>
<div><%= render partial: 'voting' %></div>
</div>
<% @quiz.each do |question| %>
@ -44,10 +42,19 @@
</div>
<div class="review-comments">
<h2 class="prft-heading">Comments</h2>
<%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %>
<% if policy(QuizComment).new? %>
<%= render partial: 'comment_form', locals: {comment: @comment, test_hash: @candidate.test_hash } %>
<% end %>
<div>
<h2 class="prft-heading">Voting</h2>
<div class="review_meta">
<div><%= render partial: 'voting' %></div>
</div>
</div>
<div>
<h2 class="prft-heading">Comments</h2>
<%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %>
<% if policy(QuizComment).new? %>
<%= render partial: 'comment_form', locals: {comment: @comment, test_hash: @candidate.test_hash } %>
<% end %>
</div>
</div>
</div>