mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 10:26:17 +02:00
Merge branch 'MDL-59595-master-2' of git://github.com/snake/moodle
This commit is contained in:
commit
c965349aad
@ -7968,9 +7968,7 @@ function admin_externalpage_setup($section, $extrabutton = '', array $extraurlpa
|
||||
* @return object admin_root object
|
||||
*/
|
||||
function admin_get_root($reload=false, $requirefulltree=true) {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
|
||||
static $ADMIN = NULL;
|
||||
global $CFG, $DB, $OUTPUT, $ADMIN;
|
||||
|
||||
if (is_null($ADMIN)) {
|
||||
// create the admin tree!
|
||||
|
@ -712,6 +712,7 @@ class manager {
|
||||
* @param \stdClass $user record
|
||||
*/
|
||||
public static function set_user(\stdClass $user) {
|
||||
global $ADMIN;
|
||||
$GLOBALS['USER'] = $user;
|
||||
unset($GLOBALS['USER']->description); // Conserve memory.
|
||||
unset($GLOBALS['USER']->password); // Improve security.
|
||||
@ -723,6 +724,9 @@ class manager {
|
||||
// Relink session with global $USER just in case it got unlinked somehow.
|
||||
$_SESSION['USER'] =& $GLOBALS['USER'];
|
||||
|
||||
// Nullify the $ADMIN tree global. If we're changing users, then this is now stale and must be generated again if needed.
|
||||
$ADMIN = null;
|
||||
|
||||
// Init session key.
|
||||
sesskey();
|
||||
}
|
||||
|
@ -414,4 +414,28 @@ class core_admintree_testcase extends advanced_testcase {
|
||||
$this->assertEquals('These entries are invalid: nonvalid site name', $adminsetting->write_setting('nonvalid site name'));
|
||||
$this->assertEquals('Empty lines are not valid', $adminsetting->write_setting("localhost\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the $ADMIN global (adminroot cache) is properly reset when changing users, which might occur naturally during cron.
|
||||
*/
|
||||
public function test_adminroot_cache_reset() {
|
||||
$this->resetAfterTest();
|
||||
global $DB;
|
||||
// Current user is a manager at site context, which won't have access to the 'debugging' section of the admin tree.
|
||||
$manageruser = $this->getDataGenerator()->create_user();
|
||||
$context = context_system::instance();
|
||||
$managerrole = $DB->get_record('role', array('shortname' => 'manager'));
|
||||
role_assign($managerrole->id, $manageruser->id, $context->id);
|
||||
$this->setUser($manageruser);
|
||||
$adminroot = admin_get_root();
|
||||
$section = $adminroot->locate('debugging');
|
||||
$this->assertEmpty($section);
|
||||
|
||||
// Now, change the user to an admin user and confirm we get a new copy of the admin tree when next we ask for it.
|
||||
$adminuser = get_admin();
|
||||
$this->setUser($adminuser);
|
||||
$adminroot = admin_get_root();
|
||||
$section = $adminroot->locate('debugging');
|
||||
$this->assertInstanceOf('\admin_settingpage', $section);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user