Skip to content

Commit

Permalink
MDL-17458 $CFG->rolesactive cleanup + other cleanup in upgrade code
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jan 15, 2009
1 parent 0361508 commit 18818ab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 65 deletions.
7 changes: 1 addition & 6 deletions admin/settings/top.php
Expand Up @@ -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"));

Expand Down
30 changes: 7 additions & 23 deletions index.php
Expand Up @@ -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;
Expand All @@ -51,37 +47,25 @@
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();
} else {
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');
}
}


Expand Down
18 changes: 11 additions & 7 deletions lib/accesslib.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/adminlib.php
Expand Up @@ -1594,9 +1594,6 @@ public function search($query) {
*/
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)) {
Expand Down Expand Up @@ -1745,9 +1742,6 @@ public function add($setting) {
// 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)) {
Expand Down
12 changes: 0 additions & 12 deletions lib/deprecatedlib.php
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions login/index.php
Expand Up @@ -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/");
}
Expand All @@ -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;
Expand Down

0 comments on commit 18818ab

Please sign in to comment.