Skip to content

Commit

Permalink
MDL-62428 core: fix incorrect early return in privacy providers
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed May 14, 2018
1 parent 6df0fa9 commit e1baf5e
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backup/tests/privacy_provider_test.php
Expand Up @@ -169,7 +169,7 @@ public function test_delete_data_for_user() {

$coursecontext = context_course::instance($this->course->id);
$contextlist = new \core_privacy\local\request\approved_contextlist($this->user, 'core_backup',
[$coursecontext->id]);
[context_system::instance()->id, $coursecontext->id]);
provider::delete_data_for_user($contextlist);

// After deletion, the backup operation for the user should have been deleted.
Expand Down
2 changes: 1 addition & 1 deletion backup/util/ui/classes/privacy/provider.php
Expand Up @@ -163,7 +163,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
$userid = $contextlist->get_user()->id;
foreach ($contextlist->get_contexts() as $context) {
if (!$context instanceof \context_course) {
return;
continue;
}

$DB->delete_records('backup_controllers', ['itemid' => $context->instanceid, 'userid' => $userid]);
Expand Down
2 changes: 1 addition & 1 deletion cohort/classes/privacy/provider.php
Expand Up @@ -167,7 +167,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
$userid = $contextlist->get_user()->id;
foreach ($contextlist->get_contexts() as $context) {
if (!$context instanceof \context_system && !$context instanceof \context_coursecat) {
return;
continue;
}
static::delete_data($context, $userid);
}
Expand Down
5 changes: 4 additions & 1 deletion cohort/tests/privacy_test.php
Expand Up @@ -202,7 +202,10 @@ public function test_delete_data_for_user() {
$this->assertEquals(5, $count);

$contextlist = provider::get_contexts_for_userid($user1->id);
$approvedcontextlist = new approved_contextlist($user1, 'cohort', $contextlist->get_contextids());
$contexts = [];
$contexts[] = \context_user::instance($user1->id)->id;
$contexts = array_merge($contexts, $contextlist->get_contextids());
$approvedcontextlist = new approved_contextlist($user1, 'cohort', $contexts);
provider::delete_data_for_user($approvedcontextlist);

// After deletion, the cohort_members entries for the first student should have been deleted.
Expand Down
2 changes: 1 addition & 1 deletion enrol/lti/classes/privacy/provider.php
Expand Up @@ -156,7 +156,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {

foreach ($contextlist->get_contexts() as $context) {
if (!($context instanceof \context_course || $context instanceof \context_module)) {
return;
continue;
}

$enrolltitools = $DB->get_fieldset_select('enrol_lti_tools', 'id', 'contextid = :contextid',
Expand Down
4 changes: 2 additions & 2 deletions enrol/lti/tests/privacy_provider_test.php
Expand Up @@ -158,8 +158,8 @@ public function test_delete_data_for_user() {
$count = $DB->count_records('enrol_lti_users');
$this->assertEquals(4, $count);

$contextlist = new \core_privacy\local\request\approved_contextlist($this->user, 'core_backup',
[$coursecontext->id, $cmcontext->id]);
$contextlist = new \core_privacy\local\request\approved_contextlist($this->user, 'enrol_lti',
[context_system::instance()->id, $coursecontext->id, $cmcontext->id]);
provider::delete_data_for_user($contextlist);

$ltiusers = $DB->get_records('enrol_lti_users');
Expand Down
2 changes: 1 addition & 1 deletion mod/choice/classes/privacy/provider.php
Expand Up @@ -210,7 +210,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
foreach ($contextlist->get_contexts() as $context) {

if (!$context instanceof \context_module) {
return;
continue;
}
$instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
$DB->delete_records('choice_answers', ['choiceid' => $instanceid, 'userid' => $userid]);
Expand Down
2 changes: 1 addition & 1 deletion mod/choice/tests/privacy_provider_test.php
Expand Up @@ -208,7 +208,7 @@ public function test_delete_data_for_user_() {
$context1 = context_module::instance($cm1->id);
$context2 = context_module::instance($cm2->id);
$contextlist = new \core_privacy\local\request\approved_contextlist($this->student, 'choice',
[$context1->id, $context2->id]);
[context_system::instance()->id, $context1->id, $context2->id]);
provider::delete_data_for_user($contextlist);

// After deletion, the choice answers for the first student should have been deleted.
Expand Down
2 changes: 1 addition & 1 deletion mod/lti/classes/privacy/provider.php
Expand Up @@ -182,7 +182,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
$userid = $contextlist->get_user()->id;
foreach ($contextlist->get_contexts() as $context) {
if (!$context instanceof \context_module) {
return;
continue;
}
$instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
$DB->delete_records('lti_submission', ['ltiid' => $instanceid, 'userid' => $userid]);
Expand Down
2 changes: 1 addition & 1 deletion mod/lti/tests/privacy_provider_test.php
Expand Up @@ -271,7 +271,7 @@ public function test_delete_data_for_user() {

$context = \context_module::instance($lti->cmid);
$contextlist = new \core_privacy\local\request\approved_contextlist($user1, 'lti',
[$context->id]);
[context_system::instance()->id, $context->id]);
provider::delete_data_for_user($contextlist);

// After deletion the lti submission for the first user should have been deleted.
Expand Down

0 comments on commit e1baf5e

Please sign in to comment.