From 18818abf4c65996019bf0193bd7ddfae2219892b Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 15 Jan 2009 22:09:57 +0000 Subject: [PATCH] MDL-17458 $CFG->rolesactive cleanup + other cleanup in upgrade code --- admin/settings/top.php | 7 +------ index.php | 30 +++++++----------------------- lib/accesslib.php | 18 +++++++++++------- lib/adminlib.php | 6 ------ lib/deprecatedlib.php | 12 ------------ login/index.php | 12 +----------- 6 files changed, 20 insertions(+), 65 deletions(-) diff --git a/admin/settings/top.php b/admin/settings/top.php index b44a58e2a5..f1069217ad 100644 --- a/admin/settings/top.php +++ b/admin/settings/top.php @@ -6,12 +6,7 @@ // are added to them. $systemcontext = get_context_instance(CONTEXT_SYSTEM); -if (empty($CFG->rolesactive)) { - // installation starts - no permission checks - $hassiteconfig = true; -} else { - $hassiteconfig = has_capability('moodle/site:config', $systemcontext); -} +$hassiteconfig = has_capability('moodle/site:config', $systemcontext); $ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php")); diff --git a/index.php b/index.php index f6449e0643..4f39b5b8b1 100644 --- a/index.php +++ b/index.php @@ -34,10 +34,6 @@ require_once($CFG->dirroot .'/course/lib.php'); require_once($CFG->dirroot .'/lib/blocklib.php'); - if (empty($SITE)) { - redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); - } - // Bounds for block widths // more flexible for theme designers taken from theme config.php $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width; @@ -51,16 +47,10 @@ define('BLOCK_R_MAX_WIDTH', $rmax); // check if major upgrade needed - also present in login/index.php - if ((int)$CFG->version < 2006101100) { //1.7 or older + if (empty($CFG->version) or (int)$CFG->version < 2009011400) { //1.9 or older @require_logout(); redirect("$CFG->wwwroot/$CFG->admin/"); } - // Trigger 1.9 accesslib upgrade? - if ((int)$CFG->version < 2007092000 - && isset($USER->id) - && is_siteadmin($USER->id)) { // this test is expensive, but is only triggered during the upgrade - redirect("$CFG->wwwroot/$CFG->admin/"); - } if ($CFG->forcelogin) { require_login(); @@ -68,20 +58,14 @@ user_accesstime_log(); } - if (!empty($CFG->rolesactive)) { // if already using roles system - if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { - if (moodle_needs_upgrading()) { - redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); - } - } else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required - if (isloggedin() && $USER->username != 'guest') { - redirect($CFG->wwwroot .'/my/index.php'); - } - } - } else { // if upgrading from 1.6 or below - if (is_siteadmin($USER->id) && moodle_needs_upgrading()) { + if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + if (moodle_needs_upgrading()) { redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); } + } else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required + if (isloggedin() && $USER->username != 'guest') { + redirect($CFG->wwwroot .'/my/index.php'); + } } diff --git a/lib/accesslib.php b/lib/accesslib.php index 593b457554..8b1bfe348a 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -351,7 +351,16 @@ function get_guest_role() { * @return bool */ function has_capability($capability, $context, $userid=NULL, $doanything=true) { - global $USER, $ACCESS, $CFG, $DIRTYCONTEXTS, $DB; + global $USER, $ACCESS, $CFG, $DIRTYCONTEXTS, $DB, $SCRIPT; + + if (empty($CFG->rolesactive)) { + if ($SCRIPT === "/$CFG->admin/index.php" or $SCRIPT === "/$CFG->admin/cliupgrade.php") { + // we are in an installer - roles can not work yet + return true; + } else { + return false; + } + } // the original $CONTEXT here was hiding serious errors // for security reasons do not reuse previous context @@ -1177,12 +1186,6 @@ function get_user_access_sitewide($userid) { global $CFG, $DB; - // this flag has not been set! - // (not clean install, or upgraded successfully to 1.7 and up) - if (empty($CFG->rolesactive)) { - return false; - } - /* Get in 3 cheap DB queries... * - role assignments - with role_caps * - relevant role caps @@ -1614,6 +1617,7 @@ function compact_rdefs(&$rdefs) { function load_all_capabilities() { global $USER, $CFG, $DIRTYCONTEXTS; + // roles not installed yet - we are in the middle of installation if (empty($CFG->rolesactive)) { return; } diff --git a/lib/adminlib.php b/lib/adminlib.php index 65fff3e0a4..3b8768293a 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1594,9 +1594,6 @@ class admin_externalpage implements part_of_admin_tree { */ public function check_access() { global $CFG; - if (empty($CFG->rolesactive)) { - return true; // no access check before site is fully set up - } $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context; foreach($this->req_capability as $cap) { if (is_valid_capability($cap) and has_capability($cap, $context)) { @@ -1745,9 +1742,6 @@ class admin_settingpage implements part_of_admin_tree { // see admin_externalpage public function check_access() { global $CFG; - if (empty($CFG->rolesactive)) { - return true; // no access check before site is fully set up - } $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context; foreach($this->req_capability as $cap) { if (is_valid_capability($cap) and has_capability($cap, $context)) { diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 9a8cfdc358..cb5ea14368 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -49,10 +49,6 @@ function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) { /// Is the user able to access this course as a teacher? global $CFG; - if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7 - return false; - } - if ($courseid) { $context = get_context_instance(CONTEXT_COURSE, $courseid); } else { @@ -75,10 +71,6 @@ function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) { function isteacherinanycourse($userid=0, $includeadmin=true) { global $USER, $CFG, $DB; - if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7 - return false; - } - if (!$userid) { if (empty($USER->id)) { return false; @@ -129,10 +121,6 @@ function isteacherinanycourse($userid=0, $includeadmin=true) { function isguest($userid=0) { global $CFG; - if (empty($CFG->rolesactive)) { - return false; - } - $context = get_context_instance(CONTEXT_SYSTEM); return has_capability('moodle/legacy:guest', $context, $userid, false); diff --git a/login/index.php b/login/index.php index 2ddacda86f..0a67aa8938 100644 --- a/login/index.php +++ b/login/index.php @@ -4,7 +4,7 @@ require_once("../config.php"); // check if major upgrade needed - also present in /index.php - if ((int)$CFG->version < 2006101100) { //1.7 or older + if ((int)$CFG->version < 2009011400) { //1.9 or older @require_logout(); redirect("$CFG->wwwroot/$CFG->admin/"); } @@ -24,16 +24,6 @@ $session_has_timed_out = false; } -// setup and verify auth settings - -if (!isset($CFG->registerauth)) { - set_config('registerauth', ''); -} - -if (!isset($CFG->auth_instructions)) { - set_config('auth_instructions', ''); -} - // auth plugins may override these - SSO anyone? $frm = false; $user = false; -- 2.39.5