mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-61307 core: Remove deletion_criteria
This commit is contained in:
parent
a235a6e02d
commit
70f0923499
@ -102,11 +102,11 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
|
||||
/**
|
||||
* Deletes all comments for a specified context.
|
||||
*
|
||||
* @param \core_privacy\local\request\deletion_criteria $criteria Details about which context to delete comments for.
|
||||
* @param \context $context Details about which context to delete comments for.
|
||||
*/
|
||||
public static function delete_comments_for_context(\core_privacy\local\request\deletion_criteria $criteria) {
|
||||
public static function delete_comments_for_context(\context $context) {
|
||||
global $DB;
|
||||
$DB->delete_records('comments', ['contextid' => $criteria->get_context()->id]);
|
||||
$DB->delete_records('comments', ['contextid' => $context->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,8 +115,7 @@ class core_comment_privacy_testcase extends provider_testcase {
|
||||
$comment2->add('First comment for user 2 on comment 2');
|
||||
|
||||
// Delete only for the first context. All records in the comments table for this context should be removed.
|
||||
$deletioncriteria = new \core_privacy\local\request\deletion_criteria($coursecontext1);
|
||||
\core_comment\privacy\provider::delete_comments_for_context($deletioncriteria);
|
||||
\core_comment\privacy\provider::delete_comments_for_context($coursecontext1);
|
||||
// No records left here.
|
||||
$this->assertCount(0, $comment1->get_comments());
|
||||
// All of the records are left intact here.
|
||||
|
@ -26,7 +26,6 @@ namespace core_privacy\local;
|
||||
use \core_privacy\local\metadata\collection;
|
||||
use \core_privacy\local\request\contextlist;
|
||||
use \core_privacy\local\request\approved_contextlist;
|
||||
use \core_privacy\local\request\deletion_criteria;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -87,12 +86,12 @@ trait legacy_polyfill {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all use data which matches the specified deletion_criteria.
|
||||
* Delete all use data which matches the specified deletion criteria.
|
||||
*
|
||||
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
|
||||
* @param context $context The specific context to delete data for.
|
||||
*/
|
||||
public static function delete_for_context(deletion_criteria $criteria) {
|
||||
return static::_delete_for_context($criteria);
|
||||
public static function delete_for_context(\context $context) {
|
||||
return static::_delete_for_context($context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,11 +54,11 @@ interface core_user_data_provider extends core_data_provider {
|
||||
public static function export_user_data(approved_contextlist $contextlist);
|
||||
|
||||
/**
|
||||
* Delete all use data which matches the specified deletion_criteria.
|
||||
* Delete all use data which matches the specified deletion criteria.
|
||||
*
|
||||
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
|
||||
* @param context $context The specific context to delete data for.
|
||||
*/
|
||||
public static function delete_for_context(deletion_criteria $criteria);
|
||||
public static function delete_for_context(\context $context);
|
||||
|
||||
/**
|
||||
* Delete all user data for the specified user, in the specified contexts.
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The \core_privacy\local\request\deletion_criteria class.
|
||||
*
|
||||
* @package core_privacy
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_privacy\local\request;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The deletion_criteria class is used to describe conditions for a set of
|
||||
* data due to be deleted.
|
||||
*
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class deletion_criteria {
|
||||
/**
|
||||
* @var context The context being deleted.
|
||||
*/
|
||||
protected $context = null;
|
||||
|
||||
/**
|
||||
* Constructor for a new deletion_criteria.
|
||||
*
|
||||
* @param \context $context The context being deleted.
|
||||
*/
|
||||
public function __construct(\context $context) {
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context to be deleted.
|
||||
*
|
||||
* @return \context
|
||||
*/
|
||||
public function get_context() : \context {
|
||||
return $this->context;
|
||||
}
|
||||
}
|
@ -86,13 +86,13 @@ class helper {
|
||||
*
|
||||
* This will handle deletion for things such as activity completion.
|
||||
*
|
||||
* @param string $component The component being deleted for.
|
||||
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
|
||||
* @param string $component The component being deleted for.
|
||||
* @param context $context The specific context to delete data for.
|
||||
*/
|
||||
public static function delete_for_context(string $component, deletion_criteria $criteria) {
|
||||
public static function delete_for_context(string $component, \context $context) {
|
||||
if (strpos($component, 'mod_') === 0) {
|
||||
// Activity modules support data stored by core about them - for example, activity completion.
|
||||
static::delete_for_context_course_module($component, $criteria->get_context());
|
||||
static::delete_for_context_course_module($component, $context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
namespace core_privacy;
|
||||
use core_privacy\local\metadata\collection;
|
||||
use core_privacy\local\request\contextlist_collection;
|
||||
use core_privacy\local\request\deletion_criteria;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -252,20 +251,20 @@ class manager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user data for all users using the specified deletion_criteria.
|
||||
* Delete all use data which matches the specified deletion criteria.
|
||||
*
|
||||
* @param deletion_criteria $criteria the criteria object dictating what contexts will be deleted.
|
||||
* @param context $context The specific context to delete data for.
|
||||
*/
|
||||
public function delete_for_context(deletion_criteria $criteria) {
|
||||
public function delete_for_context(\context $context) {
|
||||
foreach ($this->get_component_list() as $component) {
|
||||
if ($this->component_implements($component, \core_privacy\local\request\core_user_data_provider::class)) {
|
||||
// This component knows about specific data that it owns.
|
||||
// Have it delete all of that user data for the context.
|
||||
$this->get_provider_classname($component)::delete_for_context($criteria);
|
||||
$this->get_provider_classname($component)::delete_for_context($context);
|
||||
}
|
||||
|
||||
// Delete any shared user data it doesn't know about.
|
||||
local\request\helper::delete_for_context($component, $criteria);
|
||||
local\request\helper::delete_for_context($component, $context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Unit Tests for the request deletion criteria.
|
||||
*
|
||||
* @package core_privacy
|
||||
* @category test
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
use \core_privacy\local\request\deletion_criteria;
|
||||
|
||||
/**
|
||||
* Tests for the \core_privacy API's request deletion criteria class.
|
||||
*
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class deletion_criteria_test extends advanced_testcase {
|
||||
/**
|
||||
* The get_context function should return the entered context.
|
||||
*/
|
||||
public function test_get_context() {
|
||||
$context = \context_system::instance();
|
||||
$uit = new deletion_criteria($context);
|
||||
$this->assertSame($context, $uit->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* The get_context function should return the entered context.
|
||||
*/
|
||||
public function test_get_context_user_context() {
|
||||
$context = \context_user::instance(\core_user::get_user_by_username('admin')->id);
|
||||
$uit = new deletion_criteria($context);
|
||||
$this->assertSame($context, $uit->get_context());
|
||||
}
|
||||
}
|
7
privacy/tests/fixtures/mock_provider.php
vendored
7
privacy/tests/fixtures/mock_provider.php
vendored
@ -27,7 +27,6 @@ namespace mod_testcomponent\privacy;
|
||||
use core_privacy\local\metadata\collection;
|
||||
use core_privacy\local\request\approved_contextlist;
|
||||
use core_privacy\local\request\contextlist;
|
||||
use core_privacy\local\request\deletion_criteria;
|
||||
|
||||
/**
|
||||
* Mock core_user_data_provider for unit tests.
|
||||
@ -67,11 +66,11 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all use data which matches the specified deletion_criteria.
|
||||
* Delete all use data which matches the specified deletion criteria.
|
||||
*
|
||||
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
|
||||
* @param context $context The specific context to delete data for.
|
||||
*/
|
||||
public static function delete_for_context(deletion_criteria $criteria) {
|
||||
public static function delete_for_context(\context $context) {
|
||||
// This does nothing. We only want to confirm this can be called via the \core_privacy\manager.
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ global $CFG;
|
||||
|
||||
use \core_privacy\local\metadata\collection;
|
||||
use \core_privacy\local\request\contextlist;
|
||||
use \core_privacy\local\request\deletion_criteria;
|
||||
use \core_privacy\local\request\approved_contextlist;
|
||||
|
||||
/**
|
||||
@ -114,15 +113,13 @@ class core_privacy_legacy_polyfill_test extends advanced_testcase {
|
||||
* _delete_for_context can be successfully called.
|
||||
*/
|
||||
public function test_delete_for_context() {
|
||||
$criteria = new deletion_criteria(\context_system::instance());
|
||||
|
||||
$mock = $this->createMock(test_legacy_polyfill_mock_wrapper::class);
|
||||
$mock->expects($this->once())
|
||||
->method('get_return_value')
|
||||
->with('_delete_for_context', [$criteria]);
|
||||
->with('_delete_for_context', [\context_system::instance()]);
|
||||
|
||||
test_legacy_polyfill_request_provider::$mock = $mock;
|
||||
test_legacy_polyfill_request_provider::delete_for_context($criteria);
|
||||
test_legacy_polyfill_request_provider::delete_for_context(\context_system::instance());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,11 +239,11 @@ class test_legacy_polyfill_request_provider implements \core_privacy\local\reque
|
||||
|
||||
|
||||
/**
|
||||
* Delete all use data which matches the specified deletion_criteria.
|
||||
* Delete all use data which matches the specified deletion criteria.
|
||||
*
|
||||
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
|
||||
* @param context $context The specific context to delete data for.
|
||||
*/
|
||||
public static function _delete_for_context(deletion_criteria $criteria) {
|
||||
public static function _delete_for_context(\context $context) {
|
||||
return static::$mock->get_return_value(__FUNCTION__, func_get_args());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user