Skip to content

Commit

Permalink
Merge pull request #659 from ubc/#658-prevent-over-comparing
Browse files Browse the repository at this point in the history
Prevent students from performing extra comparisons
  • Loading branch information
andrew-gardener authored Jan 4, 2018
2 parents ddbed34 + fc7abb2 commit 2195a80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 5 additions & 2 deletions compair/api/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ def get(self, course_uuid, assignment_uuid):
message="Comparisons can only be seen here by those enrolled in the course. Please double-check your enrollment in this course.")
restrict_user = not allow(MANAGE, assignment)

comparison_count = assignment.completed_comparison_count_for_user(current_user.id)

if not assignment.compare_grace:
abort(403, title="Comparisons Unavailable",
message="Sorry, the comparison deadline has passed. No comparisons can be done after the deadline.")
elif not restrict_user and not assignment.educators_can_compare:
abort(403, title="Comparisons Unavailable",
message="Only students can currently compare answers for this assignment. To change these settings to include instructors and teaching assistants, edit the assignment.")
elif restrict_user and comparison_count >= assignment.total_comparisons_required:
abort(400, title="Comparisons Completed",
message="More comparisons aren't available, since you've finished your comparisons for this assignment. Good job!")

# check if user has a comparison they have not completed yet
new_pair = False
Expand Down Expand Up @@ -98,8 +103,6 @@ def get(self, course_uuid, assignment_uuid):
except UnknownPairGeneratorException:
abort(500, title="Comparisons Unavailable", message="Generating scored pairs failed, this really shouldn't happen.")

comparison_count = assignment.completed_comparison_count_for_user(current_user.id)

return {
'comparison': marshal(comparison, dataformat.get_comparison(restrict_user)),
'new_pair': new_pair,
Expand Down
15 changes: 12 additions & 3 deletions compair/tests/api/test_comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_submit_comparison_access_control(self):
# expected_comparisons = rv.json
comparison_submit = self._build_comparison_submit(WinningAnswer.answer1.value)

# test deny access to unenroled users
# test deny access to unenrolled users
with self.login(self.data.get_unauthorized_student().username):
rv = self.client.post(
self.base_url,
Expand Down Expand Up @@ -229,14 +229,17 @@ def test_get_and_submit_comparison(self, mocked_update_assignment_grades_run, mo

users = [self.data.get_authorized_student(), self.data.get_authorized_instructor(), self.data.get_authorized_ta()]
for user in users:
max_comparisons = 0
max_comparisons = self.assignment.number_of_comparisons
other_student_answers = 0
valid_answer_uuids = set()
for answer in self.data.get_student_answers():
if answer.assignment.id == self.assignment.id and answer.user_id != user.id:
other_student_answers += 1
valid_answer_uuids.add(answer.uuid)
max_comparisons = int(other_student_answers * (other_student_answers - 1) / 2)

# instructors and tas can compare every possible pair
if user.id in [self.data.get_authorized_instructor().id, self.data.get_authorized_ta().id]:
max_comparisons = int(other_student_answers * (other_student_answers - 1) / 2)

if user.id == self.data.get_authorized_student().id:
for comparison_example in self.data.comparisons_examples:
Expand Down Expand Up @@ -350,6 +353,12 @@ def test_get_and_submit_comparison(self, mocked_update_assignment_grades_run, mo
# all answers has been compared by the user, errors out when trying to get another pair
rv = self.client.get(self.base_url)
self.assert400(rv)
if user.id == self.data.get_authorized_student().id:
self.assertEqual("Comparisons Completed", rv.json['title'])
self.assertEqual("More comparisons aren't available, since you've finished your comparisons for this assignment. Good job!", rv.json['message'])
else:
self.assertEqual("Comparisons Unavailable", rv.json['title'])
self.assertEqual("You have compared all the currently available answer pairs. Please check back later for more answers.", rv.json['message'])

def _validate_comparison_submit(self, comparison_submit, actual_comparison, expected_comparison):
self.assertEqual(
Expand Down

0 comments on commit 2195a80

Please sign in to comment.