mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-61308 assign_feedback: Privacy code for user rights.
- Loading branch information
Showing
14 changed files
with
1,542 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file contains the assignfeedback_provider interface. | ||
* | ||
* Assignment Sub plugins should implement this if they store personal information. | ||
* | ||
* @package mod_assign | ||
* @copyright 2018 Adrian Greeve <adrian@moodle.com> | ||
* | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace mod_assign\privacy; | ||
|
||
use core_privacy\local\request\contextlist; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
interface assignfeedback_provider extends \core_privacy\local\request\plugin\subplugin_provider { | ||
|
||
/** | ||
* Retrieves the contextids associated with the provided userid for this subplugin. | ||
* NOTE if your subplugin must have an entry in the assign_grade table to work, then this | ||
* method can be empty. | ||
* | ||
* @param int $userid The user ID to get context IDs for. | ||
* @param \core_privacy\local\request\contextlist $contextlist Use add_from_sql with this object to add your context IDs. | ||
*/ | ||
public static function get_context_for_userid_within_feedback(int $userid, contextlist $contextlist); | ||
|
||
/** | ||
* Returns student user ids related to the provided teacher ID. If an entry must be present in the assign_grade table for | ||
* your plugin to work then there is no need to fill in this method. If you filled in get_context_for_userid_within_feedback() | ||
* then you probably have to fill this in as well. | ||
* | ||
* @param useridlist $useridlist A list of user IDs of students graded by this user. | ||
*/ | ||
public static function get_student_user_ids(useridlist $useridlist); | ||
|
||
/** | ||
* Export feedback data with the available grade and userid information provided. | ||
* assign_plugin_request_data contains: | ||
* - context | ||
* - grade object | ||
* - current path (subcontext) | ||
* - user object | ||
* | ||
* @param assign_plugin_request_data $exportdata Contains data to help export the user information. | ||
*/ | ||
public static function export_feedback_user_data(assign_plugin_request_data $exportdata); | ||
|
||
/** | ||
* Any call to this method should delete all user data for the context defined in the deletion_criteria. | ||
* assign_plugin_request_data contains: | ||
* - context | ||
* - assign object | ||
* | ||
* @param assign_plugin_request_data $requestdata Data useful for deleting user data from this sub-plugin. | ||
*/ | ||
public static function delete_feedback_for_context(assign_plugin_request_data $requestdata); | ||
|
||
/** | ||
* Calling this function should delete all user data associated with this grade. | ||
* assign_plugin_request_data contains: | ||
* - context | ||
* - grade object | ||
* - user object | ||
* - assign object | ||
* | ||
* @param assign_plugin_request_data $requestdata Data useful for deleting user data. | ||
*/ | ||
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata); | ||
} |
100 changes: 100 additions & 0 deletions
100
mod/assign/classes/privacy/feedback_legacy_polyfill.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file contains the polyfill to allow a plugin to operate with Moodle 3.3 up. | ||
* | ||
* @package mod_assign | ||
* @copyright 2018 Adrian Greeve <adrian@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace mod_assign\privacy; | ||
|
||
use core_privacy\local\request\contextlist; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* The trait used to provide backwards compatability for third-party plugins. | ||
* | ||
* @copyright 2018 Adrian Greeve <adrian@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
trait feedback_legacy_polyfill { | ||
|
||
/** | ||
* Retrieves the contextids associated with the provided userid for this subplugin. | ||
* NOTE if your subplugin must have an entry in the assign_grade table to work, then this | ||
* method can be empty. | ||
* | ||
* @param int $userid The user ID to get context IDs for. | ||
* @param \core_privacy\local\request\contextlist $contextlist Use add_from_sql with this object to add your context IDs. | ||
*/ | ||
public static function get_context_for_userid_within_feedback(int $userid, contextlist $contextlist) { | ||
return static::_get_context_for_userid_within_feedback($userid, $contextlist); | ||
} | ||
|
||
/** | ||
* Returns student user ids related to the provided teacher ID. If an entry must be present in the assign_grade table for | ||
* your plugin to work then there is no need to fill in this method. If you filled in get_context_for_userid_within_feedback() | ||
* then you probably have to fill this in as well. | ||
* | ||
* @param useridlist $useridlist A list of user IDs of students graded by this user. | ||
*/ | ||
public static function get_student_user_ids(useridlist $useridlist) { | ||
return static::_get_student_user_ids($useridlist); | ||
} | ||
|
||
/** | ||
* Export feedback data with the available grade and userid information provided. | ||
* assign_plugin_request_data contains: | ||
* - context | ||
* - grade object | ||
* - current path (subcontext) | ||
* - user object | ||
* | ||
* @param assign_plugin_request_data $exportdata Contains data to help export the user information. | ||
*/ | ||
public static function export_feedback_user_data(assign_plugin_request_data $exportdata) { | ||
return static::_export_feedback_user_data($exportdata); | ||
} | ||
|
||
/** | ||
* Any call to this method should delete all user data for the context defined in the deletion_criteria. | ||
* assign_plugin_request_data contains: | ||
* - context | ||
* - assign object | ||
* | ||
* @param assign_plugin_request_data $requestdata Data useful for deleting user data from this sub-plugin. | ||
*/ | ||
public static function delete_feedback_for_context(assign_plugin_request_data $requestdata) { | ||
return static::_delete_feedback_for_context($requestdata); | ||
} | ||
|
||
/** | ||
* Calling this function should delete all user data associated with this grade. | ||
* assign_plugin_request_data contains: | ||
* - context | ||
* - grade object | ||
* - user object | ||
* - assign object | ||
* | ||
* @param assign_plugin_request_data $requestdata Data useful for deleting user data. | ||
*/ | ||
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) { | ||
return static::_delete_feedback_for_grade($requestdata); | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
mod/assign/feedback/comments/classes/privacy/provider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Privacy class for requesting user data. | ||
* | ||
* @package assignfeedback_comments | ||
* @copyright 2018 Adrian Greeve <adrian@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace assignfeedback_comments\privacy; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot . '/mod/assign/locallib.php'); | ||
|
||
use \core_privacy\local\metadata\collection; | ||
use \core_privacy\local\metadata\provider as metadataprovider; | ||
use \mod_assign\privacy\assignfeedback_provider; | ||
use \core_privacy\local\request\writer; | ||
use \core_privacy\local\request\contextlist; | ||
use \mod_assign\privacy\assign_plugin_request_data; | ||
use \mod_assign\privacy\useridlist; | ||
|
||
/** | ||
* Privacy class for requesting user data. | ||
* | ||
* @package assignfeedback_comments | ||
* @copyright 2018 Adrian Greeve <adrian@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class provider implements metadataprovider, assignfeedback_provider { | ||
|
||
/** | ||
* Return meta data about this plugin. | ||
* | ||
* @param collection $collection A list of information to add to. | ||
* @return collection Return the collection after adding to it. | ||
*/ | ||
public static function get_metadata(collection $collection) : collection { | ||
$data = [ | ||
'assignment' => 'privacy:metadata:assignmentid', | ||
'grade' => 'privacy:metadata:gradepurpose', | ||
'commenttext' => 'privacy:metadata:commentpurpose' | ||
]; | ||
$collection->add_database_table('assignfeedback_comments', $data, 'privacy:metadata:tablesummary'); | ||
return $collection; | ||
} | ||
|
||
/** | ||
* No need to fill in this method as all information can be acquired from the assign_grades table in the mod assign | ||
* provider. | ||
* | ||
* @param int $userid The user ID. | ||
* @param contextlist $contextlist The context list. | ||
*/ | ||
public static function get_context_for_userid_within_feedback(int $userid, contextlist $contextlist) { | ||
// This uses the assign_grades table. | ||
} | ||
|
||
/** | ||
* This also does not need to be filled in as this is already collected in the mod assign provider. | ||
* | ||
* @param useridlist $useridlist A list of user IDs | ||
*/ | ||
public static function get_student_user_ids(useridlist $useridlist) { | ||
// Not required. | ||
} | ||
|
||
/** | ||
* Export all user data for this plugin. | ||
* | ||
* @param assign_plugin_request_data $exportdata Data used to determine which context and user to export and other useful | ||
* information to help with exporting. | ||
*/ | ||
public static function export_feedback_user_data(assign_plugin_request_data $exportdata) { | ||
// 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); | ||
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); | ||
} | ||
} | ||
|
||
/** | ||
* Any call to this method should delete all user data for the context defined in the deletion_criteria. | ||
* | ||
* @param assign_plugin_request_data $requestdata Data useful for deleting user data from this sub-plugin. | ||
*/ | ||
public static function delete_feedback_for_context(assign_plugin_request_data $requestdata) { | ||
$assign = $requestdata->get_assign(); | ||
$plugin = $assign->get_plugin_by_type('assignfeedback', 'comments'); | ||
$plugin->delete_instance(); | ||
} | ||
|
||
/** | ||
* Calling this function should delete all user data associated with this grade entry. | ||
* | ||
* @param assign_plugin_request_data $requestdata Data useful for deleting user data. | ||
*/ | ||
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) { | ||
global $DB; | ||
$DB->delete_records('assignfeedback_comments', ['assignment' => $requestdata->get_assign()->get_instance()->id, | ||
'grade' => $requestdata->get_pluginobject()->id]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.