Skip to content

Commit

Permalink
Merge branch 'MDL-62535-master' of git://github.com/abgreeve/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Aug 29, 2018
2 parents 12ef47c + 4905daf commit cf76059
Show file tree
Hide file tree
Showing 20 changed files with 1,165 additions and 43 deletions.
10 changes: 10 additions & 0 deletions admin/tool/dataprivacy/classes/metadata_registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public function get_registry_metadata() {
if (isset($contributedplugins[$plugintype][$shortname])) {
$internaldata['external'] = true;
}

// Check if the interface is deprecated.
if (!$manager->is_empty_subsystem($component)) {
$classname = $manager->get_provider_classname_for_component($component);
$componentclass = new $classname();
if ($componentclass instanceof \core_privacy\local\deprecated) {
$internaldata['deprecated'] = true;
}
}

return $internaldata;
}, $leaves['plugins']);
$fullyrichtree[$branch]['plugin_type_raw'] = $plugintype;
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/dataprivacy/lang/en/tool_dataprivacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
$string['defaultssaved'] = 'Defaults saved';
$string['deny'] = 'Deny';
$string['denyrequest'] = 'Deny request';
$string['deprecated'] = 'Deprecated';
$string['deprecatedexplanation'] = 'This plugin is using an old version of one of the privacy interfaces and should be updated.';
$string['download'] = 'Download';
$string['downloadexpireduser'] = 'Download has expired. Submit a new request if you wish to export your personal data.';
$string['dporolemapping'] = 'Privacy officer role mapping';
Expand Down
3 changes: 3 additions & 0 deletions admin/tool/dataprivacy/templates/component_status.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
{{#external}}
<span class="badge badge-pill badge-notice">{{#str}}external, tool_dataprivacy{{/str}}</span>
{{/external}}
{{#deprecated}}
<span class="badge badge-pill badge-warning">{{#str}}deprecated, tool_dataprivacy{{/str}}</span>
{{/deprecated}}
</div>

{{#compliant}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<dd>{{#str}}requiresattentionexplanation, tool_dataprivacy{{/str}}</dd>
<dt><span class="badge badge-pill badge-notice">{{#str}}external, tool_dataprivacy{{/str}}</span></dt>
<dd>{{#str}}externalexplanation, tool_dataprivacy{{/str}}</dd>
<dt><span class="badge badge-pill badge-warning">{{#str}}deprecated, tool_dataprivacy{{/str}}</span></dt>
<dd>{{#str}}deprecatedexplanation, tool_dataprivacy{{/str}}</dd>
</dl>
<hr />
<div class="clearfix"><a class="tool_dataprivacy-expand-all pull-right" href="#" data-visibility-state='visible'>{{#str}}visible, tool_dataprivacy{{/str}}</a></div>
Expand Down
34 changes: 32 additions & 2 deletions grade/grading/classes/privacy/gradingform_legacy_polyfill.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

defined('MOODLE_INTERNAL') || die();

use core_privacy\local\request\approved_contextlist;

/**
* The trait used to provide backwards compatability for third-party plugins.
*
Expand All @@ -36,35 +34,67 @@
*/
trait gradingform_legacy_polyfill {

/**
* Export user data relating to an instance ID.
*
* @param \context $context Context to use with the export writer.
* @param int $instanceid The instance ID to export data for.
* @param array $subcontext The directory to export this data to.
*/
public static function export_gradingform_instance_data(\context $context, int $instanceid, array $subcontext) {
static::_export_gradingform_instance_data($context, $instanceid, $subcontext);
}

/**
* Deletes all user data related to the provided instance IDs.
*
* @param array $instanceids The instance IDs to delete information from.
*/
public static function delete_gradingform_for_instances(array $instanceids) {
static::_delete_gradingform_for_instances($instanceids);
}

/**
* This method is used to export any user data this sub-plugin has using the object to get the context and userid.
*
* @deprecated Since Moodle 3.6 MDL-62535 Please use the methods in the gradingform_provider_v2 interface.
* @todo MDL-63137 remove this method.
*
* @param context $context Context owner of the data.
* @param stdClass $definition Grading definition entry to export.
* @param int $userid The user whose information is to be exported.
*
* @return stdClass The data to export.
*/
public static function get_gradingform_export_data(\context $context, $definition, int $userid) {
debugging('This method is deprecated. Please use the gradingform_provider_v2 interface', DEBUG_DEVELOPER);
return static::_get_gradingform_export_data($context, $definition, $userid);
}

/**
* Any call to this method should delete all user data for the context defined.
*
* @deprecated Since Moodle 3.6 MDL-62535 Please use the methods in the gradingform_provider_v2 interface.
* @todo MDL-63137 remove this method.
*
* @param context $context Context owner of the data.
*/
public static function delete_gradingform_for_context(\context $context) {
debugging('This method is deprecated. Please use the gradingform_provider_v2 interface', DEBUG_DEVELOPER);
static::_delete_gradingform_for_context($context);
}

/**
* A call to this method should delete user data (where practicle) from the userid and context.
*
* @deprecated Since Moodle 3.6 MDL-62535 Please use the methods in the gradingform_provider_v2 interface.
* @todo MDL-63137 remove this method.
*
* @param int $userid The user whose information is to be deleted.
* @param context $context Context owner of the data.
*/
public static function delete_gradingform_for_userid(int $userid, \context $context) {
debugging('This method is deprecated. Please use the gradingform_provider_v2 interface', DEBUG_DEVELOPER);
static::_delete_gradingform_for_userid($userid, $context);
}
}
15 changes: 14 additions & 1 deletion grade/grading/classes/privacy/gradingform_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*
* Grading method plugins should implement this if they store personal information.
*
* @deprecated since Moodle 3.6 MDL-62535 Please use the gradingform_provider_v2 interface
* @todo MDL-63167 Remove this file.
*
* @package core_grading
* @copyright 2018 Sara Arjona <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -31,11 +34,15 @@
use core_privacy\local\request\approved_contextlist;

interface gradingform_provider extends
\core_privacy\local\request\plugin\subsystem_provider {
\core_privacy\local\request\plugin\subsystem_provider,
\core_privacy\local\deprecated {

/**
* This method is used to export any user data this sub-plugin has using the object to get the context and userid.
*
* @deprecated since Moodle 3.6 MDL-62535 Please use the methods in the gradingform_provider_v2 interface
* @todo MDL-63167 Remove this file.
*
* @param \context $context Context owner of the data.
* @param \stdClass $definition Grading definition entry to export.
* @param int $userid The user whose information is to be exported.
Expand All @@ -47,13 +54,19 @@ public static function get_gradingform_export_data(\context $context, $definitio
/**
* Any call to this method should delete all user data for the context defined.
*
* @deprecated since Moodle 3.6 MDL-62535 Please use the methods in the gradingform_provider_v2 interface
* @todo MDL-63167 Remove this file.
*
* @param \context $context Context owner of the data.
*/
public static function delete_gradingform_for_context(\context $context);

/**
* A call to this method should delete user data (where practicle) from the userid and context.
*
* @deprecated since Moodle 3.6 MDL-62535 Please use the methods in the gradingform_provider_v2 interface
* @todo MDL-63167 Remove this file.
*
* @param int $userid The user to delete.
* @param \context $context the context to refine the deletion.
*/
Expand Down
46 changes: 46 additions & 0 deletions grade/grading/classes/privacy/gradingform_provider_v2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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 core_grading
* @copyright 2018 Adrian Greeve <adriangreeve.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_grading\privacy;

defined('MOODLE_INTERNAL') || die();

interface gradingform_provider_v2 extends
\core_privacy\local\request\plugin\subsystem_provider {

/**
* Export user data relating to an instance ID.
*
* @param \context $context Context to use with the export writer.
* @param int $instanceid The instance ID to export data for.
* @param array $subcontext The directory to export this data to.
*/
public static function export_gradingform_instance_data(\context $context, int $instanceid, array $subcontext);

/**
* Deletes all user data related to the provided instance IDs.
*
* @param array $instanceids The instance IDs to delete information from.
*/
public static function delete_gradingform_for_instances(array $instanceids);
}
87 changes: 79 additions & 8 deletions grade/grading/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,73 @@ public static function export_user_data(approved_contextlist $contextlist) {
}
}

/**
* Export all user data related to a context and itemid.
*
* @param \context $context Context to export on.
* @param int $itemid Item ID to export on.
* @param array $subcontext Directory location to export to.
*/
public static function export_item_data(\context $context, int $itemid, array $subcontext) {
global $DB;

$sql = "SELECT gi.id AS instanceid, gd.id AS definitionid, gd.method
FROM {grading_areas} ga
JOIN {grading_definitions} gd ON gd.areaid = ga.id
JOIN {grading_instances} gi ON gi.definitionid = gd.id AND gi.itemid = :itemid
WHERE ga.contextid = :contextid";
$params = [
'itemid' => $itemid,
'contextid' => $context->id,
];
$records = $DB->get_recordset_sql($sql, $params);
foreach ($records as $record) {
$instancedata = manager::component_class_callback(
"gradingform_{$record->method}",
gradingform_provider_v2::class,
'export_gradingform_instance_data',
[$context, $record->instanceid, $subcontext]
);
}
$records->close();
}

/**
* Deletes all user data related to a context and possibly an itemid.
*
* @param \context $context The context to delete on.
* @param int|null $itemid An optional item ID to refine the deletion.
*/
public static function delete_instance_data(\context $context, int $itemid = null) {
global $DB;
$itemsql = '';
$params = ['contextid' => $context->id];
if (isset($itemid)) {
$params['itemid'] = $itemid;
$itemsql = 'AND gi.itemid = :itemid';
}
$sql = "SELECT gi.id AS instanceid, gd.id, gd.method
FROM {grading_definitions} gd
JOIN {grading_instances} gi ON gi.definitionid = gd.id
JOIN {grading_areas} ga ON ga.id = gd.areaid
WHERE ga.contextid = :contextid $itemsql";
$records = $DB->get_records_sql($sql, $params);
if ($records) {
$firstrecord = current($records);
$method = $firstrecord->method;
$instanceids = array_map(function($record) {
return $record->instanceid;
}, $records);
manager::component_class_callback(
"gradingform_{$method}",
gradingform_provider_v2::class,
'delete_gradingform_for_instances',
[$instanceids]);
// Delete grading_instances rows.
$DB->delete_records_list('grading_instances', 'id', $instanceids);
}
}

/**
* Exports the data related to grading definitions within the specified context/subcontext.
*
Expand Down Expand Up @@ -191,6 +258,8 @@ protected static function export_definitions(\context $context, array $subcontex
if (!empty($definition->timecopied)) {
$tmpdata['timecopied'] = transform::datetime($definition->timecopied);
}

// MDL-63167 - This section is to be removed with the final deprecation of the gradingform_provider interface.
// Export gradingform information (if needed).
$instancedata = manager::component_class_callback(
"gradingform_{$definition->method}",
Expand All @@ -201,6 +270,7 @@ protected static function export_definitions(\context $context, array $subcontex
if (null !== $instancedata) {
$tmpdata = array_merge($tmpdata, $instancedata);
}
// End of section to be removed with deprecation.

$defdata[] = (object) $tmpdata;

Expand Down Expand Up @@ -258,34 +328,35 @@ protected static function export_grading_instances(\context $context, array $sub
}

/**
* Delete all use data which matches the specified $context.
* No deletion of the advanced grading is done.
*
* We never delete grading content.
*
* @param context $context A user context.
* @param \context $context the context to delete in.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
// MDL-63167 - This section is to be removed with the final deprecation of the gradingform_provider interface.
manager::plugintype_class_callback(
'gradingform',
gradingform_provider::class,
'delete_gradingform_for_context',
[$context]
);
// End of section to be removed for final deprecation.
}

/**
* Delete all user data for the specified user, in the specified contexts.
*
* We never delete grading content.
* Deletion of data in this provider is only related to grades and so can not be
* deleted for the creator of the advanced grade criteria.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
* @param approved_contextlist $contextlist a list of contexts approved for deletion.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
// MDL-63167 - This section is to be removed with the final deprecation of the gradingform_provider interface.
manager::plugintype_class_callback(
'gradingform',
gradingform_provider::class,
'delete_gradingform_for_userid',
[$contextlist]
);
// End of section to be removed for final deprecation.
}
}
Loading

0 comments on commit cf76059

Please sign in to comment.