Merge branch 'MDL-58453-master' of git://github.com/jleyva/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2017-04-11 16:47:29 +02:00
commit ad02561c15
2 changed files with 19 additions and 0 deletions

View file

@ -1002,6 +1002,10 @@ class mod_feedback_external extends external_api {
list($feedback, $course, $cm, $context) = self::validate_feedback($params['feedbackid']); 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. // Check permissions.
require_capability('mod/feedback:viewreports', $context); require_capability('mod/feedback:viewreports', $context);

View file

@ -674,10 +674,25 @@ class mod_feedback_external_testcase extends externallib_advanced_testcase {
mod_feedback_external::get_non_respondents($this->feedback->id); 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. * Test get_non_respondents.
*/ */
public function 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. // Create another student.
$anotherstudent = self::getDataGenerator()->create_user(); $anotherstudent = self::getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($anotherstudent->id, $this->course->id, $this->studentrole->id, 'manual'); $this->getDataGenerator()->enrol_user($anotherstudent->id, $this->course->id, $this->studentrole->id, 'manual');