MDL-45445 events: added missing 'relateduserid' validation

This commit is contained in:
Mark Nelson 2014-05-06 22:47:21 -07:00
parent b448a5ac67
commit 943c61051f
30 changed files with 313 additions and 5 deletions

View File

@ -326,6 +326,7 @@ class core_bloglib_testcase extends advanced_testcase {
\core\event\blog_association_created::create(array(
'contextid' => 1,
'objectid' => 3,
'relateduserid' => 2,
'other' => array('associateid' => 2 , 'blogid' => 3, 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('The \'associatetype\' value must be set in other and be a valid type.', $e->getMessage());
@ -334,6 +335,7 @@ class core_bloglib_testcase extends advanced_testcase {
\core\event\blog_association_created::create(array(
'contextid' => 1,
'objectid' => 3,
'relateduserid' => 2,
'other' => array('associateid' => 2 , 'blogid' => 3, 'associatetype' => 'random', 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('The \'associatetype\' value must be set in other and be a valid type.', $e->getMessage());
@ -343,6 +345,7 @@ class core_bloglib_testcase extends advanced_testcase {
\core\event\blog_association_created::create(array(
'contextid' => 1,
'objectid' => 3,
'relateduserid' => 2,
'other' => array('blogid' => 3, 'associatetype' => 'course', 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('The \'associateid\' value must be set in other.', $e->getMessage());
@ -352,6 +355,7 @@ class core_bloglib_testcase extends advanced_testcase {
\core\event\blog_association_created::create(array(
'contextid' => 1,
'objectid' => 3,
'relateduserid' => 2,
'other' => array('associateid' => 3, 'associatetype' => 'course', 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('The \'blogid\' value must be set in other.', $e->getMessage());
@ -361,6 +365,7 @@ class core_bloglib_testcase extends advanced_testcase {
\core\event\blog_association_created::create(array(
'contextid' => 1,
'objectid' => 3,
'relateduserid' => 2,
'other' => array('blogid' => 3, 'associateid' => 3, 'associatetype' => 'course')));
} catch (coding_exception $e) {
$this->assertContains('The \'subject\' value must be set in other.', $e->getMessage());

View File

@ -104,14 +104,24 @@ class blog_association_created extends base {
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (empty($this->other['associatetype']) || ($this->other['associatetype'] !== 'course'
&& $this->other['associatetype'] !== 'coursemodule')) {
throw new \coding_exception('The \'associatetype\' value must be set in other and be a valid type.');
} else if (!isset($this->other['blogid'])) {
}
if (!isset($this->other['blogid'])) {
throw new \coding_exception('The \'blogid\' value must be set in other.');
} else if (!isset($this->other['associateid'])) {
}
if (!isset($this->other['associateid'])) {
throw new \coding_exception('The \'associateid\' value must be set in other.');
} else if (!isset($this->other['subject'])) {
}
if (!isset($this->other['subject'])) {
throw new \coding_exception('The \'subject\' value must be set in other.');
}
}

View File

@ -126,4 +126,18 @@ class blog_entry_created extends base {
return array (SITEID, 'blog', 'add', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
$this->blogentry->subject);
}
/**
* Custom validations.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -117,4 +117,18 @@ class blog_entry_deleted extends base {
return array (SITEID, 'blog', 'delete', 'index.php?userid=' . $this->relateduserid, 'deleted blog entry with entry id# '.
$this->objectid);
}
/**
* Custom validations.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -124,5 +124,19 @@ class blog_entry_updated extends base {
return array(SITEID, 'blog', 'update', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
$this->blogentry->subject);
}
/**
* Custom validations.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -94,4 +94,18 @@ class cohort_member_added extends base {
$data->userid = $this->relateduserid;
return $data;
}
/**
* Custom validations.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -95,4 +95,18 @@ class cohort_member_removed extends base {
$data->userid = $this->relateduserid;
return $data;
}
/**
* Custom validations.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -124,6 +124,14 @@ class course_completed extends base {
protected function validate_data() {
parent::validate_data();
// TODO: MDL-45445 add validation of relateduserid and other['relateduserid'].
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
// Check that the 'relateduserid' value is set in other as well. This is because we introduced this in 2.6
// and some observers may be relying on this value to be present.
if (!isset($this->other['relateduserid'])) {
throw new \coding_exception('The \'relateduserid\' value must be set in other.');
}
}
}

View File

@ -80,6 +80,10 @@ class email_failed extends base {
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['subject'])) {
throw new \coding_exception('The \'subject\' value must be set in other.');
}

View File

@ -113,6 +113,10 @@ class group_member_added extends base {
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['component'])) {
throw new \coding_exception('The \'component\' value must be set in other, even if empty.');
}

View File

@ -94,4 +94,18 @@ class group_member_removed extends base {
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groups';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -92,4 +92,18 @@ class note_created extends base {
$logurl->set_anchor('note-' . $this->objectid);
return array($this->courseid, 'notes', 'add', $logurl, 'add note');
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -82,4 +82,18 @@ class note_deleted extends base {
$logurl->set_anchor('note-' . $this->objectid);
return array($this->courseid, 'notes', 'delete', $logurl, 'delete note');
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -92,4 +92,18 @@ class note_updated extends base {
$logurl->set_anchor('note-' . $this->objectid);
return array($this->courseid, 'notes', 'update', $logurl, 'update note');
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -109,4 +109,18 @@ class role_assigned extends base {
return array($this->courseid, 'role', 'assign', 'admin/roles/assign.php?contextid='.$this->contextid.'&roleid='.$this->objectid,
$rolenames[$this->objectid], '', $this->userid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -106,4 +106,18 @@ class role_unassigned extends base {
return array($this->courseid, 'role', 'unassign', 'admin/roles/assign.php?contextid='.$this->contextid.'&roleid='.$this->objectid,
$rolenames[$this->objectid], '', $this->userid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -138,4 +138,18 @@ class user_graded extends base {
return array($this->courseid, 'grade', 'update', $url, $info);
}
/**
* Custom validation.
*
* @throws \coding_exception when validation does not pass.
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -90,4 +90,18 @@ class user_loggedinas extends base {
public function get_url() {
return new \moodle_url('/user/view.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception when validation does not pass.
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -97,4 +97,18 @@ class user_profile_viewed extends base {
}
return null;
}
/**
* Custom validation.
*
* @throws \coding_exception when validation does not pass.
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -113,6 +113,9 @@ class response_deleted extends \core\event\base {
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['anonymous'])) {
throw new \coding_exception('The \'anonymous\' value must be set in other.');
}

View File

@ -135,6 +135,9 @@ class response_submitted extends \core\event\base {
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['anonymous'])) {
throw new \coding_exception('The \'anonymous\' value must be set in other.');
}

View File

@ -184,7 +184,8 @@ class mod_feedback_events_testcase extends advanced_testcase {
try {
\mod_feedback\event\response_submitted::create(array(
'context' => $context,
'objectid' => $this->eventfeedbackcompleted->id
'objectid' => $this->eventfeedbackcompleted->id,
'relateduserid' => 2,
));
$this->fail("Event validation should not allow \\mod_feedback\\event\\response_deleted to be triggered without
other['anonymous']");
@ -289,6 +290,7 @@ class mod_feedback_events_testcase extends advanced_testcase {
\mod_feedback\event\response_submitted::create(array(
'context' => $context,
'objectid' => $this->eventfeedbackcompleted->id,
'relateduserid' => 2,
'anonymous' => 0,
'other' => array('cmid' => $this->eventcm->id, 'anonymous' => 2)
));
@ -303,6 +305,7 @@ class mod_feedback_events_testcase extends advanced_testcase {
\mod_feedback\event\response_submitted::create(array(
'context' => $context,
'objectid' => $this->eventfeedbackcompleted->id,
'relateduserid' => 2,
'anonymous' => 0,
'other' => array('instanceid' => $this->eventfeedback->id, 'anonymous' => 2)
));
@ -317,6 +320,7 @@ class mod_feedback_events_testcase extends advanced_testcase {
\mod_feedback\event\response_submitted::create(array(
'context' => $context,
'objectid' => $this->eventfeedbackcompleted->id,
'relateduserid' => 2,
'other' => array('cmid' => $this->eventcm->id, 'instanceid' => $this->eventfeedback->id)
));
$this->fail("Event validation should not allow \\mod_feedback\\event\\response_deleted to be triggered without

View File

@ -83,4 +83,18 @@ class essay_attempt_viewed extends \core\event\base {
return array($this->courseid, 'lesson', 'view grade', 'essay.php?id=' . $this->contextinstanceid . '&mode=grade&attemptid='
. $this->objectid, get_string('manualgrading', 'lesson'), $this->contextinstanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -103,6 +103,10 @@ class interactions_viewed extends \core\event\base {
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (empty($this->other['attemptid'])) {
throw new \coding_exception('The \'attemptid\' must be set in other.');
}

View File

@ -105,6 +105,9 @@ class tracks_viewed extends \core\event\base {
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (empty($this->other['attemptid'])) {
throw new \coding_exception('The \'attemptid\' value must be set in other.');
}

View File

@ -101,6 +101,10 @@ class user_report_viewed extends \core\event\base {
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (empty($this->other['attemptid'])) {
throw new \coding_exception('The \'attemptid\' value must be set in other.');
}

View File

@ -90,4 +90,18 @@ class submission_assessed extends \core\event\base {
public function get_url() {
return new \moodle_url('/mod/workshop/assessment.php', array('asid' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -91,4 +91,18 @@ class submission_reassessed extends \core\event\base {
public function get_url() {
return new \moodle_url('/mod/workshop/assessment.php?', array('asid' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -88,4 +88,18 @@ class submission_viewed extends \core\event\base {
'submission.php?cmid=' . $this->contextinstanceid . '&id=' . $this->objectid,
$this->objectid, $this->contextinstanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}

View File

@ -94,5 +94,9 @@ class user_report_viewed extends \core\event\base {
if ($this->contextlevel != CONTEXT_COURSE) {
throw new \coding_exception('Context level must be CONTEXT_COURSE.');
}
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
}