MDL-61307 privacy: Rename deletion functions

This commit is contained in:
Andrew Nicols
2018-03-13 08:48:13 +08:00
parent 70f0923499
commit e98f0cf7ff
9 changed files with 43 additions and 43 deletions
+2 -2
View File
@@ -104,7 +104,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
*
* @param \context $context Details about which context to delete comments for.
*/
public static function delete_comments_for_context(\context $context) {
public static function delete_comments_for_all_users_in_context(\context $context) {
global $DB;
$DB->delete_records('comments', ['contextid' => $context->id]);
}
@@ -115,7 +115,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
* @param \core_privacy\local\request\approved_contextlist $contextlist Contains the user ID and a list of contexts to be
* deleted from.
*/
public static function delete_comments_for_user_in_context(\core_privacy\local\request\approved_contextlist $contextlist) {
public static function delete_comments_for_user(\core_privacy\local\request\approved_contextlist $contextlist) {
global $DB;
$userid = $contextlist->get_user()->id;
+4 -4
View File
@@ -92,7 +92,7 @@ class core_comment_privacy_testcase extends provider_testcase {
/**
* Tests the deletion of all comments in a context.
*/
public function test_delete_comments_for_context() {
public function test_delete_comments_for_all_users_in_context() {
$this->resetAfterTest();
$course1 = $this->getDataGenerator()->create_course();
@@ -115,7 +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.
\core_comment\privacy\provider::delete_comments_for_context($coursecontext1);
\core_comment\privacy\provider::delete_comments_for_all_users_in_context($coursecontext1);
// No records left here.
$this->assertCount(0, $comment1->get_comments());
// All of the records are left intact here.
@@ -126,7 +126,7 @@ class core_comment_privacy_testcase extends provider_testcase {
/**
* Tests deletion of comments for a specified user and contexts.
*/
public function test_delete_comments_for_user_in_context() {
public function test_delete_comments_for_user() {
$this->resetAfterTest();
$course1 = $this->getDataGenerator()->create_course();
@@ -155,7 +155,7 @@ class core_comment_privacy_testcase extends provider_testcase {
// Delete the comments for user 1.
$approvedcontextlist = new core_privacy\tests\request\approved_contextlist($user1, 'block_comments',
[$coursecontext1->id, $coursecontext2->id]);
\core_comment\privacy\provider::delete_comments_for_user_in_context($approvedcontextlist);
\core_comment\privacy\provider::delete_comments_for_user($approvedcontextlist);
// No comments left in comments 1 as only user 1 commented there.
$this->assertCount(0, $comment1->get_comments());
+5 -5
View File
@@ -86,12 +86,12 @@ trait legacy_polyfill {
}
/**
* Delete all use data which matches the specified deletion criteria.
* Delete all data for all users in the specified context.
*
* @param context $context The specific context to delete data for.
*/
public static function delete_for_context(\context $context) {
return static::_delete_for_context($context);
public static function delete_data_for_all_users_in_context(\context $context) {
return static::_delete_data_for_all_users_in_context($context);
}
/**
@@ -99,7 +99,7 @@ trait legacy_polyfill {
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_user_data(approved_contextlist $contextlist) {
return static::_delete_user_data($contextlist);
public static function delete_data_for_user(approved_contextlist $contextlist) {
return static::_delete_data_for_user($contextlist);
}
}
@@ -54,16 +54,16 @@ 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 data for all users in the specified context.
*
* @param context $context The specific context to delete data for.
* @param context $context The specific context to delete data for.
*/
public static function delete_for_context(\context $context);
public static function delete_data_for_all_users_in_context(\context $context);
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_user_data(approved_contextlist $contextlist);
public static function delete_data_for_user(approved_contextlist $contextlist);
}
+6 -6
View File
@@ -89,10 +89,10 @@ class helper {
* @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, \context $context) {
public static function delete_data_for_all_users_in_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, $context);
static::delete_data_for_all_users_in_context_course_module($component, $context);
}
}
@@ -103,12 +103,12 @@ class helper {
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_user_data(approved_contextlist $contextlist) {
public static function delete_data_for_user(approved_contextlist $contextlist) {
$component = $contextlist->get_component();
if (strpos($component, 'mod_') === 0) {
// Activity modules support data stored by core about them - for example, activity completion.
static::delete_user_data_for_course_module($contextlist);
static::delete_data_for_user_in_course_module($contextlist);
}
}
@@ -272,7 +272,7 @@ class helper {
* @param string $component The component being deleted for.
* @param \context_module $context The context to delete all data for.
*/
public static function delete_for_context_course_module(string $component, \context_module $context) {
public static function delete_data_for_all_users_in_context_course_module(string $component, \context_module $context) {
global $DB;
// Delete course completion data for this context.
@@ -286,7 +286,7 @@ class helper {
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
protected static function delete_user_data_for_course_module(approved_contextlist $contextlist) {
protected static function delete_data_for_user_in_course_module(approved_contextlist $contextlist) {
global $DB;
foreach ($contextlist as $context) {
+6 -6
View File
@@ -230,7 +230,7 @@ class manager {
* @throws \moodle_exception if the contextlist_collection doesn't contain all approved_contextlist items, or if the component
* for an approved_contextlist isn't a core provider.
*/
public function delete_user_data(contextlist_collection $contextlistcollection) {
public function delete_data_for_user(contextlist_collection $contextlistcollection) {
// Delete the data.
foreach ($contextlistcollection as $approvedcontextlist) {
if (!$approvedcontextlist instanceof \core_privacy\local\request\approved_contextlist) {
@@ -241,12 +241,12 @@ class manager {
if (count($approvedcontextlist)) {
// The component knows about data that it has.
// Have it delete its own data.
$this->get_provider_classname($approvedcontextlist->get_component())::delete_user_data($approvedcontextlist);
$this->get_provider_classname($approvedcontextlist->get_component())::delete_data_for_user($approvedcontextlist);
}
}
// Delete any shared user data it doesn't know about.
local\request\helper::delete_user_data($approvedcontextlist);
local\request\helper::delete_data_for_user($approvedcontextlist);
}
}
@@ -255,16 +255,16 @@ class manager {
*
* @param context $context The specific context to delete data for.
*/
public function delete_for_context(\context $context) {
public function delete_data_for_all_users_in_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($context);
$this->get_provider_classname($component)::delete_data_for_all_users_in_context($context);
}
// Delete any shared user data it doesn't know about.
local\request\helper::delete_for_context($component, $context);
local\request\helper::delete_data_for_all_users_in_context($component, $context);
}
}
+2 -2
View File
@@ -70,7 +70,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
*
* @param context $context The specific context to delete data for.
*/
public static function delete_for_context(\context $context) {
public static function delete_data_for_all_users_in_context(\context $context) {
// This does nothing. We only want to confirm this can be called via the \core_privacy\manager.
}
@@ -79,7 +79,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_user_data(approved_contextlist $contextlist) {
public static function delete_data_for_user(approved_contextlist $contextlist) {
// This does nothing. We only want to confirm this can be called via the \core_privacy\manager.
}
}
+10 -10
View File
@@ -110,32 +110,32 @@ class core_privacy_legacy_polyfill_test extends advanced_testcase {
/**
* Test that the local\request\core_user_preference_provider polyfill works and that the static
* _delete_for_context can be successfully called.
* _delete_data_for_all_users_in_context can be successfully called.
*/
public function test_delete_for_context() {
public function test_delete_data_for_all_users_in_context() {
$mock = $this->createMock(test_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
->method('get_return_value')
->with('_delete_for_context', [\context_system::instance()]);
->with('_delete_data_for_all_users_in_context', [\context_system::instance()]);
test_legacy_polyfill_request_provider::$mock = $mock;
test_legacy_polyfill_request_provider::delete_for_context(\context_system::instance());
test_legacy_polyfill_request_provider::delete_data_for_all_users_in_context(\context_system::instance());
}
/**
* Test that the local\request\core_user_preference_provider polyfill works and that the static
* _delete_user_data can be successfully called.
* _delete_data_for_user can be successfully called.
*/
public function test_delete_user_data() {
public function test_delete_data_for_user() {
$contextlist = new approved_contextlist(\core_user::get_user_by_username('admin'), 'core_privacy', [98]);
$mock = $this->createMock(test_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
->method('get_return_value')
->with('_delete_user_data', [$contextlist]);
->with('_delete_data_for_user', [$contextlist]);
test_legacy_polyfill_request_provider::$mock = $mock;
test_legacy_polyfill_request_provider::delete_user_data($contextlist);
test_legacy_polyfill_request_provider::delete_data_for_user($contextlist);
}
}
@@ -243,7 +243,7 @@ class test_legacy_polyfill_request_provider implements \core_privacy\local\reque
*
* @param context $context The specific context to delete data for.
*/
public static function _delete_for_context(\context $context) {
public static function _delete_data_for_all_users_in_context(\context $context) {
return static::$mock->get_return_value(__FUNCTION__, func_get_args());
}
@@ -252,7 +252,7 @@ class test_legacy_polyfill_request_provider implements \core_privacy\local\reque
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function _delete_user_data(approved_contextlist $contextlist) {
public static function _delete_data_for_user(approved_contextlist $contextlist) {
return static::$mock->get_return_value(__FUNCTION__, func_get_args());
}
}
+4 -4
View File
@@ -163,9 +163,9 @@ class privacy_manager_testcase extends advanced_testcase {
}
/**
* Test verifying only approved contextlists can be used with the delete_user_data method.
* Test verifying only approved contextlists can be used with the delete_data_for_user method.
*/
public function test_delete_user_data() {
public function test_delete_data_for_user() {
$this->resetAfterTest();
// Get a mock manager, in which the core components list is mocked to include all mock plugins.
// testcomponent is a core provider, testcomponent2 is a null provider, testcomponent3 is subplugin provider (non core).
@@ -184,10 +184,10 @@ class privacy_manager_testcase extends advanced_testcase {
}
// Verify null, as the method has no return type and exits normally. Mainly checking we don't see any exception.
$this->assertNull($mockman->delete_user_data($approvedcontextlistcollection));
$this->assertNull($mockman->delete_data_for_user($approvedcontextlistcollection));
// Verify an exception is thrown if trying to pass in a collection of non-approved_contextlist items.
$this->expectException(moodle_exception::class);
$mockman->delete_user_data($contextlistcollection);
$mockman->delete_data_for_user($contextlistcollection);
}
}