MDL-61743 core_privacy: Add context level checks for all users deletion
authorDavid Monllao <davidm@moodle.com>
Tue, 27 Mar 2018 07:08:50 +0000 (09:08 +0200)
committerDavid Monllao <davidm@moodle.com>
Fri, 6 Apr 2018 06:57:24 +0000 (08:57 +0200)
blocks/html/classes/privacy/provider.php
mod/choice/classes/privacy/provider.php

index 003562b..f3659f7 100644 (file)
@@ -153,6 +153,11 @@ class provider implements
      * @param   context                 $context   The specific context to delete data for.
      */
     public static function delete_data_for_all_users_in_context(\context $context) {
+
+        if (!$context instanceof \context_block) {
+            return;
+        }
+
         // The only way to delete data for the html block is to delete the block instance itself.
         blocks_delete_instance(static::get_instance_from_context($context));
     }
@@ -165,6 +170,10 @@ class provider implements
     public static function delete_data_for_user(approved_contextlist $contextlist) {
         // The only way to delete data for the html block is to delete the block instance itself.
         foreach ($contextlist as $context) {
+
+            if (!$context instanceof \context_block) {
+                continue;
+            }
             blocks_delete_instance(static::get_instance_from_context($context));
         }
     }
index 229efc9..a640bd7 100644 (file)
@@ -184,6 +184,11 @@ class provider implements
         if (empty($context)) {
             return;
         }
+
+        if (!$context instanceof \context_module) {
+            return;
+        }
+
         $instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
         $DB->delete_records('choice_answers', ['choiceid' => $instanceid]);
     }
@@ -202,6 +207,10 @@ class provider implements
 
         $userid = $contextlist->get_user()->id;
         foreach ($contextlist->get_contexts() as $context) {
+
+            if (!$context instanceof \context_module) {
+                return;
+            }
             $instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
             $DB->delete_records('choice_answers', ['choiceid' => $instanceid, 'userid' => $userid]);
         }