mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-27520 assignfeedback_comments: updated privacy provider
This commit is contained in:
parent
c98e9fbae1
commit
b7a9b6f872
@ -58,6 +58,8 @@ class provider implements metadataprovider, assignfeedback_provider {
|
||||
'commenttext' => 'privacy:metadata:commentpurpose'
|
||||
];
|
||||
$collection->add_database_table('assignfeedback_comments', $data, 'privacy:metadata:tablesummary');
|
||||
$collection->link_subsystem('core_files', 'privacy:metadata:filepurpose');
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
@ -91,13 +93,29 @@ class provider implements metadataprovider, assignfeedback_provider {
|
||||
// Get that comment information and jam it into that exporter.
|
||||
$assign = $exportdata->get_assign();
|
||||
$plugin = $assign->get_plugin_by_type('assignfeedback', 'comments');
|
||||
$comments = $plugin->get_feedback_comments($exportdata->get_pluginobject()->id);
|
||||
$gradeid = $exportdata->get_pluginobject()->id;
|
||||
$comments = $plugin->get_feedback_comments($gradeid);
|
||||
if ($comments && !empty($comments->commenttext)) {
|
||||
$data = (object)['commenttext' => format_text($comments->commenttext, $comments->commentformat,
|
||||
['context' => $exportdata->get_context()])];
|
||||
writer::with_context($exportdata->get_context())
|
||||
->export_data(array_merge($exportdata->get_subcontext(),
|
||||
[get_string('privacy:commentpath', 'assignfeedback_comments')]), $data);
|
||||
$comments->commenttext = writer::with_context($assign->get_context())->rewrite_pluginfile_urls(
|
||||
[],
|
||||
ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA,
|
||||
$gradeid,
|
||||
$comments->commenttext
|
||||
);
|
||||
|
||||
$currentpath = array_merge(
|
||||
$exportdata->get_subcontext(),
|
||||
[get_string('privacy:commentpath', 'assignfeedback_comments')]
|
||||
);
|
||||
$data = (object)
|
||||
[
|
||||
'commenttext' => format_text($comments->commenttext, $comments->commentformat,
|
||||
['context' => $exportdata->get_context()])
|
||||
];
|
||||
writer::with_context($exportdata->get_context())->export_data($currentpath, $data);
|
||||
writer::with_context($exportdata->get_context())->export_area_files($currentpath,
|
||||
ASSIGNFEEDBACK_COMMENTS_COMPONENT, ASSIGNFEEDBACK_COMMENTS_FILEAREA, $gradeid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,6 +126,10 @@ class provider implements metadataprovider, assignfeedback_provider {
|
||||
*/
|
||||
public static function delete_feedback_for_context(assign_plugin_request_data $requestdata) {
|
||||
$assign = $requestdata->get_assign();
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($requestdata->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA);
|
||||
|
||||
$plugin = $assign->get_plugin_by_type('assignfeedback', 'comments');
|
||||
$plugin->delete_instance();
|
||||
}
|
||||
@ -119,6 +141,11 @@ class provider implements metadataprovider, assignfeedback_provider {
|
||||
*/
|
||||
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) {
|
||||
global $DB;
|
||||
|
||||
$fs = new \file_storage();
|
||||
$fs->delete_area_files($requestdata->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA, $requestdata->get_pluginobject()->id);
|
||||
|
||||
$DB->delete_records('assignfeedback_comments', ['assignment' => $requestdata->get_assign()->get_instance()->id,
|
||||
'grade' => $requestdata->get_pluginobject()->id]);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ $string['pluginname'] = 'Feedback comments';
|
||||
$string['privacy:commentpath'] = 'Feedback comments';
|
||||
$string['privacy:metadata:assignmentid'] = 'Assignment ID';
|
||||
$string['privacy:metadata:commentpurpose'] = 'The comment text.';
|
||||
$string['privacy:metadata:filepurpose'] = 'Feedback files from the teacher for the student.';
|
||||
$string['privacy:metadata:gradepurpose'] = 'The grade ID associated with the comment.';
|
||||
$string['privacy:metadata:tablesummary'] = 'This stores comments made by the graders as feedback for the student on their submission.';
|
||||
$string['commentinline'] = 'Comment inline';
|
||||
|
@ -47,6 +47,8 @@ class assignfeedback_comments_privacy_testcase extends \mod_assign\tests\mod_ass
|
||||
* @return array Feedback plugin object and the grade object.
|
||||
*/
|
||||
protected function create_feedback($assign, $student, $teacher, $submissiontext, $feedbacktext) {
|
||||
global $CFG;
|
||||
|
||||
$submission = new \stdClass();
|
||||
$submission->assignment = $assign->get_instance()->id;
|
||||
$submission->userid = $student->id;
|
||||
@ -62,11 +64,33 @@ class assignfeedback_comments_privacy_testcase extends \mod_assign\tests\mod_ass
|
||||
|
||||
$this->setUser($teacher);
|
||||
|
||||
$context = context_user::instance($teacher->id);
|
||||
|
||||
$draftitemid = file_get_unused_draft_itemid();
|
||||
file_prepare_draft_area($draftitemid, $context->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA, $grade->id);
|
||||
|
||||
$dummy = array(
|
||||
'contextid' => $context->id,
|
||||
'component' => 'user',
|
||||
'filearea' => 'draft',
|
||||
'itemid' => $draftitemid,
|
||||
'filepath' => '/',
|
||||
'filename' => 'feedback1.txt'
|
||||
);
|
||||
|
||||
$fs = get_file_storage();
|
||||
$fs->create_file_from_string($dummy, $feedbacktext);
|
||||
|
||||
$feedbacktext = $feedbacktext .
|
||||
" <img src='{$CFG->wwwroot}/draftfile.php/{$context->id}/user/draft/{$draftitemid}/feedback1.txt.png>";
|
||||
|
||||
$plugin = $assign->get_feedback_plugin_by_type('comments');
|
||||
$feedbackdata = new \stdClass();
|
||||
$feedbackdata->assignfeedbackcomments_editor = [
|
||||
'text' => $feedbacktext,
|
||||
'format' => 1
|
||||
'format' => FORMAT_HTML,
|
||||
'itemid' => $draftitemid
|
||||
];
|
||||
|
||||
$plugin->save($grade, $feedbackdata);
|
||||
@ -109,12 +133,24 @@ class assignfeedback_comments_privacy_testcase extends \mod_assign\tests\mod_ass
|
||||
// The student should be able to see the teachers feedback.
|
||||
$exportdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign, $grade, [], $user1);
|
||||
\assignfeedback_comments\privacy\provider::export_feedback_user_data($exportdata);
|
||||
$this->assertEquals($feedbacktext, $writer->get_data(['Feedback comments'])->commenttext);
|
||||
$this->assertContains($feedbacktext, $writer->get_data(['Feedback comments'])->commenttext);
|
||||
|
||||
$filespath = [];
|
||||
$filespath[] = 'Feedback comments';
|
||||
$feedbackfile = $writer->get_files($filespath)['feedback1.txt'];
|
||||
|
||||
$this->assertInstanceOf('stored_file', $feedbackfile);
|
||||
$this->assertEquals('feedback1.txt', $feedbackfile->get_filename());
|
||||
|
||||
// The teacher should also be able to see the feedback that they provided.
|
||||
$exportdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign, $grade, [], $user2);
|
||||
\assignfeedback_comments\privacy\provider::export_feedback_user_data($exportdata);
|
||||
$this->assertEquals($feedbacktext, $writer->get_data(['Feedback comments'])->commenttext);
|
||||
$this->assertContains($feedbacktext, $writer->get_data(['Feedback comments'])->commenttext);
|
||||
|
||||
$feedbackfile = $writer->get_files($filespath)['feedback1.txt'];
|
||||
|
||||
$this->assertInstanceOf('stored_file', $feedbackfile);
|
||||
$this->assertEquals('feedback1.txt', $feedbackfile->get_filename());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,6 +183,12 @@ class assignfeedback_comments_privacy_testcase extends \mod_assign\tests\mod_ass
|
||||
$feedbackcomments = $plugin1->get_feedback_comments($grade2->id);
|
||||
$this->assertNotEmpty($feedbackcomments);
|
||||
|
||||
$fs = new file_storage();
|
||||
$files = $fs->get_area_files($assign->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA);
|
||||
// 4 including directories.
|
||||
$this->assertEquals(4, count($files));
|
||||
|
||||
// Delete all comments for this context.
|
||||
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign);
|
||||
assignfeedback_comments\privacy\provider::delete_feedback_for_context($requestdata);
|
||||
@ -156,6 +198,12 @@ class assignfeedback_comments_privacy_testcase extends \mod_assign\tests\mod_ass
|
||||
$this->assertEmpty($feedbackcomments);
|
||||
$feedbackcomments = $plugin1->get_feedback_comments($grade2->id);
|
||||
$this->assertEmpty($feedbackcomments);
|
||||
|
||||
$fs = new file_storage();
|
||||
$files = $fs->get_area_files($assign->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA);
|
||||
$this->assertEquals(0, count($files));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,6 +236,12 @@ class assignfeedback_comments_privacy_testcase extends \mod_assign\tests\mod_ass
|
||||
$feedbackcomments = $plugin1->get_feedback_comments($grade2->id);
|
||||
$this->assertNotEmpty($feedbackcomments);
|
||||
|
||||
$fs = new file_storage();
|
||||
$files = $fs->get_area_files($assign->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA);
|
||||
// 4 including directories.
|
||||
$this->assertEquals(4, count($files));
|
||||
|
||||
// Delete all comments for this grade object.
|
||||
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign, $grade1, [], $user1);
|
||||
assignfeedback_comments\privacy\provider::delete_feedback_for_grade($requestdata);
|
||||
@ -199,5 +253,18 @@ class assignfeedback_comments_privacy_testcase extends \mod_assign\tests\mod_ass
|
||||
// These comments should not.
|
||||
$feedbackcomments = $plugin1->get_feedback_comments($grade2->id);
|
||||
$this->assertNotEmpty($feedbackcomments);
|
||||
|
||||
$fs = new file_storage();
|
||||
$files = $fs->get_area_files($assign->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
|
||||
ASSIGNFEEDBACK_COMMENTS_FILEAREA);
|
||||
// 2 files that were not deleted.
|
||||
$this->assertEquals(2, count($files));
|
||||
|
||||
array_shift($files);
|
||||
$file = array_shift($files);
|
||||
|
||||
$this->assertInstanceOf('stored_file', $file);
|
||||
$this->assertEquals('feedback1.txt', $file->get_filename());
|
||||
$this->assertEquals($grade2->id, $file->get_itemid());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user