MDL-54035 accesslib: Check if the user can switch role before switching
authorDavid Monllao <davidm@moodle.com>
Wed, 26 Sep 2018 11:03:08 +0000 (13:03 +0200)
committerDavid Monllao <davidm@moodle.com>
Wed, 26 Sep 2018 11:03:08 +0000 (13:03 +0200)
lib/accesslib.php

index 2ca9f4d..27ec530 100644 (file)
@@ -1019,7 +1019,9 @@ function reload_all_capabilities() {
     foreach ($sw as $path => $roleid) {
         if ($record = $DB->get_record('context', array('path'=>$path))) {
             $context = context::instance_by_id($record->id);
-            role_switch($roleid, $context);
+            if (has_capability('moodle/role:switchroles', $context)) {
+                role_switch($roleid, $context);
+            }
         }
     }
 }