Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'MDL-25122' of git://github.com/timhunt/moodle

  • Loading branch information...
commit 908053e21de88b7f594d7de33945c243794eac77 2 parents 915a20f + 79c6e3a
Eloy Lafuente (stronk7) stronk7 authored
23 mod/quiz/attemptlib.php
@@ -593,6 +593,29 @@ public function is_own_attempt() {
593 593 }
594 594
595 595 /**
  596 + * Is the current user allowed to review this attempt. This applies when
  597 + * {@link is_own_attempt()} returns false.
  598 + * @return bool whether the review should be allowed.
  599 + */
  600 + public function is_review_allowed() {
  601 + if (!$this->has_capability('mod/quiz:viewreports')) {
  602 + return false;
  603 + }
  604 +
  605 + $cm = $this->get_cm();
  606 + if ($this->has_capability('moodle/site:accessallgroups') ||
  607 + groups_get_activity_groupmode($cm) != SEPARATEGROUPS) {
  608 + return true;
  609 + }
  610 +
  611 + // Check the users have at least one group in common.
  612 + $teachersgroups = groups_get_activity_allowed_groups($cm);
  613 + $studentsgroups = groups_get_all_groups($cm->course, $this->attempt->userid, $cm->groupingid);
  614 + return $teachersgroups && $studentsgroups &&
  615 + array_intersect(array_keys($teachersgroups), array_keys($studentsgroups));
  616 + }
  617 +
  618 + /**
596 619 * Check the appropriate capability to see whether this user may review their own attempt.
597 620 * If not, prints an error.
598 621 */
1  mod/quiz/lang/en/quiz.php
@@ -531,6 +531,7 @@
531 531 $string['noquestionsonpage'] = 'Empty page';
532 532 $string['noresponse'] = 'No response';
533 533 $string['noreview'] = 'You are not allowed to review this quiz';
  534 +$string['noreviewattempt'] = 'You are not allowed to review this attempt.';
534 535 $string['noreviewshort'] = 'Not permitted';
535 536 $string['noreviewuntil'] = 'You are not allowed to review this quiz until {$a}';
536 537 $string['noreviewuntilshort'] = 'Available {$a}';
18 mod/quiz/review.php
@@ -34,21 +34,17 @@
34 34 $accessmanager = $attemptobj->get_access_manager(time());
35 35 $options = $attemptobj->get_review_options();
36 36
37   -/// Permissions checks for normal users who do not have quiz:viewreports capability.
38   - if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
39   - /// Can't review other users' attempts.
40   - if (!$attemptobj->is_own_attempt()) {
41   - quiz_error($attemptobj->get_quiz(), 'notyourattempt');
42   - }
43   - /// Can't review during the attempt - send them back to the attempt page.
  37 + // Check permissions.
  38 + if ($attemptobj->is_own_attempt()) {
44 39 if (!$attemptobj->is_finished()) {
45 40 redirect($attemptobj->attempt_url(0, $page));
46   - }
47   - /// Can't review unless Students may review -> Responses option is turned on.
48   - if (!$options->responses) {
  41 + } else if (!$options->responses) {
49 42 $accessmanager->back_to_view_page($attemptobj->is_preview_user(),
50   - $accessmanager->cannot_review_message($options));
  43 + $accessmanager->cannot_review_message($attemptobj->get_attempt_state()));
51 44 }
  45 +
  46 + } else if (!$attemptobj->is_review_allowed()) {
  47 + throw new moodle_quiz_exception($attemptobj, 'noreviewattempt');
52 48 }
53 49
54 50 /// Load the questions and states needed by this page.
21 mod/quiz/reviewquestion.php
@@ -32,27 +32,15 @@
32 32 $accessmanager = $attemptobj->get_access_manager(time());
33 33 $options = $attemptobj->get_review_options();
34 34
35   -/// Permissions checks for normal users who do not have quiz:viewreports capability.
36   - if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
37   - /// Can't review during the attempt - send them back to the attempt page.
  35 + // Check permissions.
  36 + if ($attemptobj->is_own_attempt()) {
38 37 if (!$attemptobj->is_finished()) {
39 38 echo $OUTPUT->header();
40 39 echo $OUTPUT->notification(get_string('cannotreviewopen', 'quiz'));
41 40 echo $OUTPUT->close_window_button();
42 41 echo $OUTPUT->footer();
43 42 die;
44   - }
45   - /// Can't review other users' attempts.
46   - if (!$attemptobj->is_own_attempt()) {
47   - echo $OUTPUT->header();
48   - echo $OUTPUT->notification(get_string('notyourattempt', 'quiz'));
49   - echo $OUTPUT->close_window_button();
50   - echo $OUTPUT->footer();
51   - die;
52   - }
53   -
54   - /// Can't review unless Students may review -> Responses option is turned on.
55   - if (!$options->responses) {
  43 + } else if (!$options->responses) {
56 44 $accessmanager = $attemptobj->get_access_manager(time());
57 45 echo $OUTPUT->header();
58 46 echo $OUTPUT->notification($accessmanager->cannot_review_message($attemptobj->get_review_options()));
@@ -60,6 +48,9 @@
60 48 echo $OUTPUT->footer();
61 49 die;
62 50 }
  51 +
  52 + } else if (!$attemptobj->is_review_allowed()) {
  53 + throw new moodle_quiz_exception($attemptobj, 'noreviewattempt');
63 54 }
64 55
65 56 /// Load the questions and states.

0 comments on commit 908053e

Please sign in to comment.
Something went wrong with that request. Please try again.