Merge branch 'MDL-58453-master' of git://github.com/jleyva/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 11 Apr 2017 14:47:29 +0000 (16:47 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 11 Apr 2017 14:47:29 +0000 (16:47 +0200)
mod/feedback/classes/external.php
mod/feedback/tests/external_test.php

index f380f39..83c842b 100644 (file)
@@ -1002,6 +1002,10 @@ class mod_feedback_external extends external_api {
 
         list($feedback, $course, $cm, $context) = self::validate_feedback($params['feedbackid']);
 
+        if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO || $feedback->course == SITEID) {
+            throw new moodle_exception('anonymous', 'feedback');
+        }
+
         // Check permissions.
         require_capability('mod/feedback:viewreports', $context);
 
index 3763d59..0d91edb 100644 (file)
@@ -674,10 +674,25 @@ class mod_feedback_external_testcase extends externallib_advanced_testcase {
         mod_feedback_external::get_non_respondents($this->feedback->id);
     }
 
+    /**
+     * Test get_non_respondents from an anonymous feedback.
+     */
+    public function test_get_non_respondents_from_anonymous_feedback() {
+        $this->setUser($this->student);
+        $this->expectException('moodle_exception');
+        $this->expectExceptionMessage(get_string('anonymous', 'feedback'));
+        mod_feedback_external::get_non_respondents($this->feedback->id);
+    }
+
     /**
      * Test get_non_respondents.
      */
     public function test_get_non_respondents() {
+        global $DB;
+
+        // Force non anonymous.
+        $DB->set_field('feedback', 'anonymous', FEEDBACK_ANONYMOUS_NO, array('id' => $this->feedback->id));
+
         // Create another student.
         $anotherstudent = self::getDataGenerator()->create_user();
         $this->getDataGenerator()->enrol_user($anotherstudent->id, $this->course->id, $this->studentrole->id, 'manual');