forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-63530 core_notes: Add support for removal of context users
This issue is part of the MDL-62560 Epic.
- Loading branch information
Mihail Geshoski
committed
Oct 30, 2018
1 parent
448bd57
commit fd45ae4
Showing
2 changed files
with
278 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
use core_privacy\local\request\contextlist; | ||
use core_privacy\local\request\transform; | ||
use core_privacy\local\request\writer; | ||
use core_privacy\local\request\userlist; | ||
use \core_privacy\local\request\approved_userlist; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
|
@@ -41,7 +43,10 @@ | |
* @copyright 2018 Zig Tan <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\plugin\provider { | ||
class provider implements | ||
\core_privacy\local\metadata\provider, | ||
\core_privacy\local\request\core_userlist_provider, | ||
\core_privacy\local\request\plugin\provider { | ||
|
||
/** | ||
* Return the fields which contain personal data. | ||
|
@@ -112,6 +117,48 @@ public static function get_contexts_for_userid(int $userid) : contextlist { | |
return $contextlist; | ||
} | ||
|
||
/** | ||
* Get the list of users who have data within a context. | ||
* | ||
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. | ||
*/ | ||
public static function get_users_in_context(userlist $userlist) { | ||
global $DB; | ||
|
||
$context = $userlist->get_context(); | ||
|
||
if (!$context instanceof \context_course) { | ||
return; | ||
} | ||
|
||
$params = [ | ||
'instanceid' => $context->instanceid | ||
]; | ||
|
||
$sql = "SELECT usermodified as userid | ||
FROM {post} | ||
WHERE module = 'notes' | ||
AND courseid = :instanceid"; | ||
|
||
$userlist->add_from_sql('userid', $sql, $params); | ||
|
||
$publishstates = [ | ||
NOTES_STATE_PUBLIC, | ||
NOTES_STATE_SITE | ||
]; | ||
|
||
list($publishstatesql, $publishstateparams) = $DB->get_in_or_equal($publishstates, SQL_PARAMS_NAMED); | ||
$params += $publishstateparams; | ||
|
||
$sql = "SELECT userid | ||
FROM {post} | ||
WHERE module = 'notes' | ||
AND courseid = :instanceid | ||
AND publishstate {$publishstatesql}"; | ||
|
||
$userlist->add_from_sql('userid', $sql, $params); | ||
} | ||
|
||
/** | ||
* Export personal data for the given approved_contextlist. | ||
* User and context information is contained within the contextlist. | ||
|
@@ -191,6 +238,31 @@ public static function delete_data_for_all_users_in_context(\context $context) { | |
$DB->delete_records('post', ['module' => 'notes', 'courseid' => $context->instanceid]); | ||
} | ||
|
||
/** | ||
* Delete multiple users within a single context. | ||
* | ||
* @param approved_userlist $userlist The approved context and user information to delete information for. | ||
*/ | ||
public static function delete_data_for_users(approved_userlist $userlist) { | ||
global $DB; | ||
|
||
$context = $userlist->get_context(); | ||
if ($context->contextlevel != CONTEXT_COURSE) { | ||
return; | ||
} | ||
|
||
$userids = $userlist->get_userids(); | ||
if (empty($userids)) { | ||
return; | ||
} | ||
|
||
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); | ||
$select = "module = :module AND courseid = :courseid AND usermodified {$usersql}"; | ||
$params = ['module' => 'notes', 'courseid' => $context->instanceid] + $userparams; | ||
|
||
$DB->delete_records_select('post', $select, $params); | ||
} | ||
|
||
/** | ||
* Delete all user data for the specified user, in the specified contexts. | ||
* | ||
|
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