diff --git a/lib/db/services.php b/lib/db/services.php index ddf6a4f35a5..bc291e75c3e 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -673,6 +673,33 @@ $functions = array( 'capabilities'=> 'moodle/notes:manage', ), + 'core_notes_delete_notes' => array( + 'classname' => 'core_notes_external', + 'methodname' => 'delete_notes', + 'classpath' => 'notes/externallib.php', + 'description' => 'Delete notes', + 'type' => 'write', + 'capabilities'=> 'moodle/notes:manage', + ), + + 'core_notes_get_notes' => array( + 'classname' => 'core_notes_external', + 'methodname' => 'get_notes', + 'classpath' => 'notes/externallib.php', + 'description' => 'Get notes', + 'type' => 'read', + 'capabilities'=> 'moodle/notes:view', + ), + + 'core_notes_update_notes' => array( + 'classname' => 'core_notes_external', + 'methodname' => 'update_notes', + 'classpath' => 'notes/externallib.php', + 'description' => 'Update notes', + 'type' => 'write', + 'capabilities'=> 'moodle/notes:manage', + ), + // === webservice related functions === 'moodle_webservice_get_siteinfo' => array( diff --git a/notes/delete.php b/notes/delete.php index 687daf47af2..11138dff86e 100644 --- a/notes/delete.php +++ b/notes/delete.php @@ -41,9 +41,7 @@ if (empty($CFG->enablenotes)) { if (data_submitted() && confirm_sesskey()) { //if data was submitted and is valid, then delete note $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid; - if (note_delete($noteid)) { - add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'delete note'); - } else { + if (!note_delete($noteid)) { print_error('cannotdeletepost', 'notes', $returnurl); } redirect($returnurl); diff --git a/notes/edit.php b/notes/edit.php index 05fe4f516bc..ddccbc3dea5 100644 --- a/notes/edit.php +++ b/notes/edit.php @@ -70,9 +70,7 @@ if ($noteform->is_cancelled()) { /// if data was submitted and validated, then save it to database if ($note = $noteform->get_data()){ - if (note_save($note)) { - add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id, 'update note'); - } + note_save($note); // redirect to notes list that contains this note redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); } diff --git a/notes/externallib.php b/notes/externallib.php index 44b378f2979..e7cd3f86ab2 100644 --- a/notes/externallib.php +++ b/notes/externallib.php @@ -53,11 +53,7 @@ class core_notes_external extends external_api { 'publishstate' => new external_value(PARAM_ALPHA, '\'personal\', \'course\' or \'site\''), 'courseid' => new external_value(PARAM_INT, 'course id of the note (in Moodle a note can only be created into a course, even for site and personal notes)'), 'text' => new external_value(PARAM_RAW, 'the text of the message - text or HTML'), - 'format' => new external_value(PARAM_ALPHANUMEXT, // For backward compatibility it can not be PARAM_INT, so we don't use external_format_value. - 'text format (' . FORMAT_HTML . ' = HTML, ' - . FORMAT_MOODLE . ' = MOODLE, ' - . FORMAT_PLAIN . ' = PLAIN or ' - . FORMAT_MARKDOWN . ' = MARKDOWN)', VALUE_DEFAULT, FORMAT_HTML), + 'format' => new external_format_value('text', VALUE_DEFAULT), 'clientnoteid' => new external_value(PARAM_ALPHANUMEXT, 'your own client id for the note. If this id is provided, the fail message id will be returned to you', VALUE_OPTIONAL), ) ) @@ -81,19 +77,19 @@ class core_notes_external extends external_api { $params = self::validate_parameters(self::create_notes_parameters(), array('notes' => $notes)); - //check if note system is enabled + // Check if note system is enabled. if (!$CFG->enablenotes) { throw new moodle_exception('notesdisabled', 'notes'); } - //retrieve all courses + // Retrieve all courses. $courseids = array(); foreach($params['notes'] as $note) { $courseids[] = $note['courseid']; } $courses = $DB->get_records_list("course", "id", $courseids); - //retrieve all users of the notes + // Retrieve all users of the notes. $userids = array(); foreach($params['notes'] as $note) { $userids[] = $note['userid']; @@ -105,32 +101,32 @@ class core_notes_external extends external_api { foreach ($params['notes'] as $note) { $success = true; - $resultnote = array(); //the infos about the success of the operation + $resultnote = array(); // The infos about the success of the operation. - //check the course exists + // Check the course exists. if (empty($courses[$note['courseid']])) { $success = false; $errormessage = get_string('invalidcourseid', 'error'); } else { - // Ensure the current user is allowed to run this function + // Ensure the current user is allowed to run this function. $context = context_course::instance($note['courseid']); self::validate_context($context); require_capability('moodle/notes:manage', $context); } - //check the user exists + // Check the user exists. if (empty($users[$note['userid']])) { $success = false; $errormessage = get_string('invaliduserid', 'notes', $note['userid']); } - //build the resultnote + // Build the resultnote. if (isset($note['clientnoteid'])) { $resultnote['clientnoteid'] = $note['clientnoteid']; } if ($success) { - //now we can create the note + // Now we can create the note. $dbnote = new stdClass; $dbnote->courseid = $note['courseid']; $dbnote->userid = $note['userid']; @@ -148,7 +144,7 @@ class core_notes_external extends external_api { $dbnote->content = $note['text']; $dbnote->format = $textformat; - //get the state ('personal', 'course', 'site') + // Get the state ('personal', 'course', 'site'). switch ($note['publishstate']) { case 'personal': $dbnote->publishstate = NOTES_STATE_DRAFT; @@ -164,11 +160,8 @@ class core_notes_external extends external_api { break; } - //TODO MDL-31119 performance improvement - if possible create a bulk functions for saving multiple notes at once - if (note_save($dbnote)) { //note_save attribut an id in case of success - add_to_log($dbnote->courseid, 'notes', 'add', - 'index.php?course='.$dbnote->courseid.'&user='.$dbnote->userid - . '#note-' . $dbnote->id , 'add note'); + // TODO MDL-31119 performance improvement - if possible create a bulk functions for saving multiple notes at once + if (note_save($dbnote)) { // Note_save attribut an id in case of success. $success = $dbnote->id; } @@ -198,13 +191,258 @@ class core_notes_external extends external_api { new external_single_structure( array( 'clientnoteid' => new external_value(PARAM_ALPHANUMEXT, 'your own id for the note', VALUE_OPTIONAL), - 'noteid' => new external_value(PARAM_INT, 'test this to know if it success: id of the created note when successed, -1 when failed'), + 'noteid' => new external_value(PARAM_INT, 'test this to know if it success: id of the created note when successed, -1 when failed'), 'errormessage' => new external_value(PARAM_TEXT, 'error message - if failed', VALUE_OPTIONAL) ) ) ); } + /** + * Returns description of delete_notes parameters + * + * @return external_function_parameters + * @since Moodle 2.5 + */ + public static function delete_notes_parameters() { + return new external_function_parameters( + array( + "notes"=> new external_multiple_structure( + new external_value(PARAM_INT, 'ID of the note to be retrieved'), 'Array of Note Ids to be deleted.' + ) + ) + ); + } + + /** + * Delete notes about users. + * Note: code should be matching the /notes/delete.php checks. + * + * @param array $notes An array of ids for the notes to delete. + * @return null + * @since Moodle 2.5 + */ + public static function delete_notes($notes = array()) { + global $CFG; + require_once($CFG->dirroot . "/notes/lib.php"); + + $params = self::validate_parameters(self::delete_notes_parameters(), $notes); + + // Check if note system is enabled. + if (!$CFG->enablenotes) { + throw new moodle_exception('notesdisabled', 'notes'); + } + $warnings = array(); + foreach ($params['notes'] as $noteid) { + $note = note_load($noteid); + if (isset($note->id)) { + // Ensure the current user is allowed to run this function. + $context = context_course::instance($note->courseid); + self::validate_context($context); + require_capability('moodle/notes:manage', $context); + if (!note_delete($note)) { + $warnings[] = array(array('item'=>'note', 'itemid'=>$noteid, 'warningcode'=>'savedfailed', 'message'=>'Note could not be modified')); + } + } else { + $warnings[] = array('item'=>'note', 'itemid'=>$noteid, 'warningcode'=>'badid', 'message'=>'Note does not exist'); + } + } + return $warnings; + } + + /** + * Returns description of delete_notes result value. + * + * @return external_description + * @since Moodle 2.5 + */ + public static function delete_notes_returns() { + return new external_warnings('item is always \'note\'', + 'When errorcode is savedfailed the note could not be modified.' . + 'When errorcode is badparam, an incorrect parameter was provided.' . + 'When errorcode is badid, the note does not exist', + 'errorcode can be badparam (incorrect parameter), savedfailed (could not be modified), or badid (note does not exist)'); + + } + + /** + * Returns description of get_notes parameters. + * + * @return external_function_parameters + * @since Moodle 2.5 + */ + public static function get_notes_parameters() { + return new external_function_parameters( + array( + "notes"=> new external_multiple_structure( + new external_value(PARAM_INT, 'ID of the note to be retrieved'), 'Array of Note Ids to be retrieved.' + ) + ) + ); + } + + /** + * Get notes about users. + * + * @param array $notes An array of ids for the notes to retrieve. + * @return null + * @since Moodle 2.5 + */ + public static function get_notes($notes) { + global $CFG; + require_once($CFG->dirroot . "/notes/lib.php"); + + $params = self::validate_parameters(self::get_notes_parameters(), $notes); + // Check if note system is enabled. + if (!$CFG->enablenotes) { + throw new moodle_exception('notesdisabled', 'notes'); + } + $resultnotes = array(); + foreach ($params['notes'] as $noteid) { + $resultnote = array(); + + $note = note_load($noteid); + if (isset($note->id)) { + // Ensure the current user is allowed to run this function. + $context = context_course::instance($note->courseid); + self::validate_context($context); + require_capability('moodle/notes:view', $context); + list($gotnote['text'], $gotnote['format']) = external_format_text($note->content, $note->format, $context->id, 'notes', '', ''); + $gotnote['noteid'] = $note->id; + $gotnote['userid'] = $note->userid; + $gotnote['publishstate'] = $note->publishstate; + $gotnote['courseid'] = $note->courseid; + $resultnotes["notes"][] = $gotnote; + } else { + $resultnotes["warnings"][] = array('item'=>'note', 'itemid'=>$noteid, 'warningcode'=>'badid', 'message'=>'Note does not exist'); + } + } + return $resultnotes; + } + + /** + * Returns description of get_notes result value. + * + * @return external_description + * @since Moodle 2.5 + */ + public static function get_notes_returns() { + return new external_single_structure( + array( + 'notes' => new external_multiple_structure( + new external_single_structure( + array( + 'noteid' => new external_value(PARAM_INT, 'id of the note', VALUE_OPTIONAL), + 'userid' => new external_value(PARAM_INT, 'id of the user the note is about', VALUE_OPTIONAL), + 'publishstate' => new external_value(PARAM_ALPHA, '\'personal\', \'course\' or \'site\'', VALUE_OPTIONAL), + 'courseid' => new external_value(PARAM_INT, 'course id of the note', VALUE_OPTIONAL), + 'text' => new external_value(PARAM_RAW, 'the text of the message - text or HTML', VALUE_OPTIONAL), + 'format' => new external_format_value('text', VALUE_OPTIONAL), + ), 'note' + ) + ), + 'warnings' => new external_warnings('item is always \'note\'', + 'When errorcode is savedfailed the note could not be modified.' . + 'When errorcode is badparam, an incorrect parameter was provided.' . + 'When errorcode is badid, the note does not exist', + 'errorcode can be badparam (incorrect parameter), savedfailed (could not be modified), or badid (note does not exist)') + ) + ); + } + + /** + * Returns description of update_notes parameters. + * + * @return external_function_parameters + * @since Moodle 2.5 + */ + public static function update_notes_parameters() { + return new external_function_parameters( + array( + 'notes' => new external_multiple_structure( + new external_single_structure( + array( + 'id' => new external_value(PARAM_INT, 'id of the note'), + 'publishstate' => new external_value(PARAM_ALPHA, '\'personal\', \'course\' or \'site\''), + 'text' => new external_value(PARAM_RAW, 'the text of the message - text or HTML'), + 'format' => new external_format_value('text', VALUE_DEFAULT), + ) + ), "Array of Notes", VALUE_DEFAULT, array() + ) + ) + ); + } + + /** + * Update notes about users. + * + * @param array $notes An array of ids for the notes to update. + * @return array fail infos. + * @since Moodle 2.2 + */ + public static function update_notes($notes = array()) { + global $CFG, $DB; + require_once($CFG->dirroot . "/notes/lib.php"); + + $params = self::validate_parameters(self::update_notes_parameters(), array('notes' => $notes)); + + // Check if note system is enabled. + if (!$CFG->enablenotes) { + throw new moodle_exception('notesdisabled', 'notes'); + } + + $warnings = array(); + foreach ($params['notes'] as $note) { + $notedetails = note_load($note['id']); + if (isset($notedetails->id)) { + // Ensure the current user is allowed to run this function. + $context = context_course::instance($notedetails->courseid); + self::validate_context($context); + require_capability('moodle/notes:manage', $context); + + $dbnote = new stdClass; + $dbnote->id = $note['id']; + $dbnote->content = $note['text']; + $dbnote->format = external_validate_format($note['format']); + // Get the state ('personal', 'course', 'site'). + switch ($note['publishstate']) { + case 'personal': + $dbnote->publishstate = NOTES_STATE_DRAFT; + break; + case 'course': + $dbnote->publishstate = NOTES_STATE_PUBLIC; + break; + case 'site': + $dbnote->publishstate = NOTES_STATE_SITE; + $dbnote->courseid = SITEID; + break; + default: + $warnings[] = array('item'=>'note', 'itemid'=>$note["id"], 'warningcode'=>'badparam', 'message'=>'Provided publishstate incorrect'); + break; + } + if (!note_save($dbnote)) { + $warnings[] = array('item'=>'note', 'itemid'=>$note["id"], 'warningcode'=>'savedfailed', 'message'=>'Note could not be modified'); + } + } else { + $warnings[] = array('item'=>'note', 'itemid'=>$note["id"], 'warningcode'=>'badid', 'message'=>'Note does not exist'); + } + } + return $warnings; + } + + /** + * Returns description of update_notes result value. + * + * @return external_description + * @since Moodle 2.5 + */ + public static function update_notes_returns() { + return new external_warnings('item is always \'note\'', + 'When errorcode is savedfailed the note could not be modified.' . + 'When errorcode is badparam, an incorrect parameter was provided.' . + 'When errorcode is badid, the note does not exist', + 'errorcode can be badparam (incorrect parameter), savedfailed (could not be modified), or badid (note does not exist)'); + } } /** @@ -262,4 +500,4 @@ class moodle_notes_external extends external_api { return core_notes_external::create_notes_returns(); } -} +} \ No newline at end of file diff --git a/notes/lib.php b/notes/lib.php index b20421979cb..ce720e37c45 100644 --- a/notes/lib.php +++ b/notes/lib.php @@ -100,10 +100,18 @@ function note_save(&$note) { // insert new note $note->created = $note->lastmodified; $id = $DB->insert_record('post', $note); - $note = $DB->get_record('post', array('id'=>$id)); + $note = note_load($id); + $logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid)); + $logurl->set_anchor('note-' . $id); + + add_to_log($note->courseid, 'notes', 'add', $logurl, 'add note'); } else { // update old note $DB->update_record('post', $note); + $note = note_load($note->id); + $logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid)); + $logurl->set_anchor('note-' . $note->id); + add_to_log($note->courseid, 'notes', 'update', $logurl , 'update note'); } unset($note->module); return true; @@ -112,13 +120,19 @@ function note_save(&$note) { /** * Deletes a note object based on its id. * - * @param int $note_id id of the note to delete + * @param int|object $note id of the note to delete, or a note object which is to be deleted. * @return boolean true if the object was deleted; false otherwise */ -function note_delete($noteid) { +function note_delete($note) { global $DB; - - return $DB->delete_records('post', array('id'=>$noteid, 'module'=>'notes')); + if (is_int($note)) { + $note = note_load($note); + debugging('Warning: providing note_delete with a note object would improve performance.',DEBUG_DEVELOPER); + } + $logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid)); + $logurl->set_anchor('note-' . $note->id); + add_to_log($note->courseid, 'notes', 'delete', $logurl, 'delete note'); + return $DB->delete_records('post', array('id'=>$note->id, 'module'=>'notes')); } /** diff --git a/notes/tests/externallib_test.php b/notes/tests/externallib_test.php index d36724f9849..7e85630ebe4 100644 --- a/notes/tests/externallib_test.php +++ b/notes/tests/externallib_test.php @@ -37,13 +37,13 @@ class core_notes_external_testcase extends externallib_advanced_testcase { */ public function test_create_notes() { - global $DB, $USER, $DB; + global $DB, $USER; $this->resetAfterTest(true); - $course = self::getDataGenerator()->create_course(); + $course = self::getDataGenerator()->create_course(); - // Set the required capabilities by the external function + // Set the required capabilities by the external function. $contextid = context_course::instance($course->id)->id; $roleid = $this->assignUserCapability('moodle/notes:manage', $contextid); $this->assignUserCapability('moodle/course:view', $contextid, $roleid); @@ -58,7 +58,6 @@ class core_notes_external_testcase extends externallib_advanced_testcase { $notes = array($note1); $creatednotes = core_notes_external::create_notes($notes); - // We need to execute the return values cleaning process to simulate the web service server. $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes); @@ -71,10 +70,174 @@ class core_notes_external_testcase extends externallib_advanced_testcase { $this->assertEquals($thenote->content, $note1['text']); $this->assertEquals($creatednotes[0]['clientnoteid'], $note1['clientnoteid']); - // Call without required capability + // Call without required capability. $this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid); $this->setExpectedException('required_capability_exception'); $creatednotes = core_notes_external::create_notes($notes); + } + public function test_delete_notes() { + + global $DB, $USER; + + $this->resetAfterTest(true); + + $course = self::getDataGenerator()->create_course(); + + // Set the required capabilities by the external function. + $contextid = context_course::instance($course->id)->id; + $roleid = $this->assignUserCapability('moodle/notes:manage', $contextid); + $this->assignUserCapability('moodle/course:view', $contextid, $roleid); + + // Create test note data. + $cnote = array(); + $cnote['userid'] = $USER->id; + $cnote['publishstate'] = 'personal'; + $cnote['courseid'] = $course->id; + $cnote['text'] = 'the text'; + $cnote['clientnoteid'] = 4; + $cnotes = array($cnote); + $creatednotes = core_notes_external::create_notes($cnotes); + $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes); + + $dnotes1 = array("notes"=>array($creatednotes[0]['noteid'])); + $deletednotes1 = core_notes_external::delete_notes($dnotes1); + $deletednotes1 = external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes1); + + // Confirm that base note data was deleted correctly. + $notdeletedcount = $DB->count_records_select('post', 'id = ' . $creatednotes[0]['noteid']); + $this->assertEquals(0, $notdeletedcount); + + $dnotes2 = array("notes"=>array(33)); // This note does not exist. + $deletednotes2 = core_notes_external::delete_notes($dnotes2); + $deletednotes2 = external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes2); + + $this->assertEquals("note", $deletednotes2[0]["item"]); + $this->assertEquals(33, $deletednotes2[0]["itemid"]); + $this->assertEquals("badid", $deletednotes2[0]["warningcode"]); + $this->assertEquals("Note does not exist", $deletednotes2[0]["message"]); + + // Call without required capability. + $creatednotes = core_notes_external::create_notes($cnotes); + $dnotes3 = array("notes"=>array($creatednotes[0]['noteid'])); + + $this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid); + $this->setExpectedException('required_capability_exception'); + $deletednotes = core_notes_external::delete_notes($dnotes3); + } + + public function test_get_notes() { + + global $DB, $USER; + + $this->resetAfterTest(true); + + $course = self::getDataGenerator()->create_course(); + + // Set the required capabilities by the external function. + $contextid = context_course::instance($course->id)->id; + $roleid = $this->assignUserCapability('moodle/notes:manage', $contextid); + $this->assignUserCapability('moodle/notes:view', $contextid, $roleid); + $this->assignUserCapability('moodle/course:view', $contextid, $roleid); + + // Create test note data. + $cnote = array(); + $cnote['userid'] = $USER->id; + $cnote['publishstate'] = 'personal'; + $cnote['courseid'] = $course->id; + $cnote['text'] = 'the text'; + $cnotes = array($cnote); + + $creatednotes1 = core_notes_external::create_notes($cnotes); + $creatednotes2 = core_notes_external::create_notes($cnotes); + $creatednotes3 = core_notes_external::create_notes($cnotes); + + $creatednotes1 = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes1); + $creatednotes2 = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes2); + $creatednotes3 = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes3); + + // Note 33 does not exist. + $gnotes = array("notes"=>array($creatednotes1[0]['noteid'], $creatednotes2[0]['noteid'], $creatednotes3[0]['noteid'], 33)); + $getnotes = core_notes_external::get_notes($gnotes); + $getnotes = external_api::clean_returnvalue(core_notes_external::get_notes_returns(), $getnotes); + + $this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid); + // Confirm that base note data was retrieved correctly. + $this->assertEquals($cnote['userid'], $getnotes["notes"][0]["userid"]); + $this->assertEquals($cnote['text'], $getnotes["notes"][0]["text"]); + $this->assertEquals($cnote['userid'], $getnotes["notes"][1]["userid"]); + $this->assertEquals($cnote['text'], $getnotes["notes"][1]["text"]); + $this->assertEquals($cnote['userid'], $getnotes["notes"][2]["userid"]); + $this->assertEquals($cnote['text'], $getnotes["notes"][2]["text"]); + $this->assertEquals("note", $getnotes["warnings"][0]["item"]); + $this->assertEquals(33, $getnotes["warnings"][0]["itemid"]); + $this->assertEquals("badid", $getnotes["warnings"][0]["warningcode"]); + $this->assertEquals("Note does not exist", $getnotes["warnings"][0]["message"]); + + // Call without required capability. + $this->unassignUserCapability('moodle/notes:view', $contextid, $roleid); + $this->setExpectedException('required_capability_exception'); + $creatednotes = core_notes_external::get_notes($gnotes); + } + + public function test_update_notes() { + + global $DB, $USER; + + $this->resetAfterTest(true); + + $course = self::getDataGenerator()->create_course(); + + // Set the required capabilities by the external function. + $contextid = context_course::instance($course->id)->id; + $roleid = $this->assignUserCapability('moodle/notes:manage', $contextid); + $this->assignUserCapability('moodle/course:view', $contextid, $roleid); + + // Create test note data. + $note1 = array(); + $note1['userid'] = $USER->id; + $note1['publishstate'] = 'personal'; + $note1['courseid'] = $course->id; + $note1['text'] = 'the text'; + $note2['userid'] = $USER->id; + $note2['publishstate'] = 'course'; + $note2['courseid'] = $course->id; + $note2['text'] = 'the text'; + $note3['userid'] = $USER->id; + $note3['publishstate'] = 'site'; + $note3['courseid'] = $course->id; + $note3['text'] = 'the text'; + $notes1 = array($note1, $note2, $note3); + + $creatednotes = core_notes_external::create_notes($notes1); + $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes); + + $note2 = array(); + $note2["id"] = $creatednotes[0]['noteid']; + $note2['publishstate'] = 'personal'; + $note2['text'] = 'the new text'; + $note2['format'] = FORMAT_HTML; + $notes2 = array($note2); + + $updatednotes = core_notes_external::update_notes($notes2); + + $updatednotes = external_api::clean_returnvalue(core_notes_external::update_notes_returns(), $updatednotes); + $thenote = $DB->get_record('post', array('id' => $creatednotes[0]['noteid'])); + + // Confirm that base note data was updated correctly. + $this->assertEquals($thenote->publishstate, NOTES_STATE_DRAFT); + $this->assertEquals($note2['text'], $thenote->content); + + // Call without required capability. + $creatednotes = core_notes_external::create_notes($notes1); + $this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid); + $this->setExpectedException('required_capability_exception'); + $note2 = array(); + $note2["id"] = $creatednotes[0]['noteid']; + $note2['publishstate'] = 'personal'; + $note2['text'] = 'the new text'; + $note2['format'] = FORMAT_HTML; + $notes2 = array($note2); + $updatednotes = core_notes_external::update_notes($notes2); } } diff --git a/user/addnote.php b/user/addnote.php index 3636615023f..a39a17d4958 100644 --- a/user/addnote.php +++ b/user/addnote.php @@ -63,9 +63,7 @@ if (!empty($users) && confirm_sesskey()) { $note->content = $contents[$k]; $note->publishstate = $states[$k]; $note->userid = $v; - if (note_save($note)) { - add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'add note'); - } + note_save($note); } redirect("$CFG->wwwroot/user/index.php?id=$id"); } diff --git a/user/groupaddnote.php b/user/groupaddnote.php index ae2404b2f97..69fdfb11348 100644 --- a/user/groupaddnote.php +++ b/user/groupaddnote.php @@ -66,9 +66,7 @@ if (!empty($users) && !empty($content) && confirm_sesskey()) { } $note->id = 0; $note->userid = $v; - if (note_save($note)) { - add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'add note'); - } + note_save($note); } redirect("$CFG->wwwroot/user/index.php?id=$id"); diff --git a/version.php b/version.php index 2900718c6f7..9dd758c9550 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,8 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2013022200.00; // YYYYMMDD = weekly release date of this DEV branch + +$version = 2013022300.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes