mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Modified to support fresh installation of new Roles System.
This commit is contained in:
parent
1afecc03f4
commit
0c30fdc924
2 changed files with 61 additions and 15 deletions
|
@ -127,6 +127,12 @@
|
||||||
$db->debug = true;
|
$db->debug = true;
|
||||||
if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
|
if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
|
||||||
$db->debug = false;
|
$db->debug = false;
|
||||||
|
|
||||||
|
// Install the roles system.
|
||||||
|
moodle_install_roles();
|
||||||
|
if (!update_capabilities()) {
|
||||||
|
error('Had trouble installing the core capabilities for the Roles System');
|
||||||
|
}
|
||||||
notify($strdatabasesuccess, "green");
|
notify($strdatabasesuccess, "green");
|
||||||
} else {
|
} else {
|
||||||
$db->debug = false;
|
$db->debug = false;
|
||||||
|
@ -171,10 +177,13 @@
|
||||||
$db->debug=true;
|
$db->debug=true;
|
||||||
if (main_upgrade($CFG->version)) {
|
if (main_upgrade($CFG->version)) {
|
||||||
if (empty($CFG->rolesactive)) {
|
if (empty($CFG->rolesactive)) {
|
||||||
moodle_upgrade_roles_system_17();
|
// Upgrade to the roles system.
|
||||||
|
moodle_install_roles();
|
||||||
}
|
}
|
||||||
if (!update_capabilities()) {
|
if (!update_capabilities()) {
|
||||||
error('Had trouble upgrading the core capabilities for Roles');
|
error('Had trouble upgrading the core capabilities for the Roles System');
|
||||||
|
} else {
|
||||||
|
set_config('rolesactive', 1);
|
||||||
}
|
}
|
||||||
$db->debug=false;
|
$db->debug=false;
|
||||||
if (set_config("version", $version)) {
|
if (set_config("version", $version)) {
|
||||||
|
@ -308,8 +317,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// NOTE: We aren't going to have a user_admin table anymore. FIX below!
|
||||||
|
// We need to assign the "admin" user to the default admin role at some point!
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
/// Set up the admin user
|
/// Set up the admin user
|
||||||
if (! record_exists("user_admins")) { // No admin user yet
|
//if (!record_exists("user_admins")) { // No admin user yet
|
||||||
|
if (!$CFG->rolesactive) {
|
||||||
redirect("user.php");
|
redirect("user.php");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
|
|
||||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||||
|
|
||||||
if (! record_exists("user_admins")) { // No admin user yet
|
|
||||||
|
//if (! record_exists("user_admins")) { // No admin user yet
|
||||||
|
if (!$CFG->rolesactive) { // No admin user yet.
|
||||||
|
|
||||||
$user->firstname = get_string("admin");
|
$user->firstname = get_string("admin");
|
||||||
$user->lastname = get_string("user");
|
$user->lastname = get_string("user");
|
||||||
|
@ -38,20 +40,28 @@
|
||||||
error("SERIOUS ERROR: Could not create admin user record !!!");
|
error("SERIOUS ERROR: Could not create admin user record !!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$admin->userid = $user->id;
|
$admin->userid = $user->id;
|
||||||
|
|
||||||
if (! insert_record("user_admins", $admin)) {
|
if (! insert_record("user_admins", $admin)) {
|
||||||
error("Could not make user $user->id an admin !!!");
|
error("Could not make user $user->id an admin !!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $user = get_record("user", "id", $user->id)) { // Double check
|
if (! $user = get_record("user", "id", $user->id)) { // Double check.
|
||||||
error("User ID was incorrect (can't find it)");
|
error("User ID was incorrect (can't find it)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Assign the default admin role to the new user.
|
||||||
|
$adminrole = get_record('role', 'name', get_string('administrator'));
|
||||||
|
role_assign($adminrole->id, $user->id, 0, $context->id);
|
||||||
|
set_config('rolesactive', 1);
|
||||||
|
|
||||||
|
|
||||||
|
// Assign as a teacher in the site-level course.
|
||||||
if (! $site = get_site()) {
|
if (! $site = get_site()) {
|
||||||
error("Could not find site-level course");
|
error("Could not find site-level course");
|
||||||
}
|
}
|
||||||
|
|
||||||
$teacher->userid = $user->id;
|
$teacher->userid = $user->id;
|
||||||
$teacher->course = $site->id;
|
$teacher->course = $site->id;
|
||||||
$teacher->authority = 1;
|
$teacher->authority = 1;
|
||||||
|
@ -59,6 +69,8 @@
|
||||||
error("Could not make user $id a teacher of site-level course !!!");
|
error("Could not make user $id a teacher of site-level course !!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Log the user in.
|
||||||
$USER = $user;
|
$USER = $user;
|
||||||
$USER->loggedin = true;
|
$USER->loggedin = true;
|
||||||
$USER->sessionIP = md5(getremoteaddr()); // Store the current IP in the session
|
$USER->sessionIP = md5(getremoteaddr()); // Store the current IP in the session
|
||||||
|
@ -66,7 +78,9 @@
|
||||||
$USER->admin = true;
|
$USER->admin = true;
|
||||||
$USER->teacher["$site->id"] = true;
|
$USER->teacher["$site->id"] = true;
|
||||||
$USER->newadminuser = true;
|
$USER->newadminuser = true;
|
||||||
sesskey(); // for added security, used to check script parameters
|
sesskey(); // For added security, used to check script parameters
|
||||||
|
load_user_capability();
|
||||||
|
|
||||||
|
|
||||||
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
||||||
exit;
|
exit;
|
||||||
|
@ -79,11 +93,13 @@
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
|
|
||||||
if (!isadmin()) {
|
|
||||||
error("You must be an administrator to edit users this way.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($newuser and confirm_sesskey()) { // Create a new user
|
if ($newuser && confirm_sesskey()) { // Create a new user
|
||||||
|
|
||||||
|
if (!has_capability('moodle/user:create', $context->id)) {
|
||||||
|
error('You do not have the required permission to create new users.');
|
||||||
|
}
|
||||||
|
|
||||||
$user->auth = "manual";
|
$user->auth = "manual";
|
||||||
$user->firstname = "";
|
$user->firstname = "";
|
||||||
$user->lastname = "";
|
$user->lastname = "";
|
||||||
|
@ -104,6 +120,10 @@
|
||||||
|
|
||||||
} else { // List all users for editing
|
} else { // List all users for editing
|
||||||
|
|
||||||
|
if (!has_capability('moodle/user:update', $context->id)) {
|
||||||
|
error('You do not have the required permission to edit users.');
|
||||||
|
}
|
||||||
|
|
||||||
$stredituser = get_string("edituser");
|
$stredituser = get_string("edituser");
|
||||||
$stradministration = get_string("administration");
|
$stradministration = get_string("administration");
|
||||||
$strusers = get_string("users");
|
$strusers = get_string("users");
|
||||||
|
@ -140,7 +160,12 @@
|
||||||
notify(get_string("usernotconfirmed", "", fullname($user, true)));
|
notify(get_string("usernotconfirmed", "", fullname($user, true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ($delete and confirm_sesskey() and has_capability('moodle/user:delete', $context->id)) { // Delete a selected user, after confirmation
|
} else if ($delete and confirm_sesskey()) { // Delete a selected user, after confirmation
|
||||||
|
|
||||||
|
if (!has_capability('moodle/user:delete', $context->id)) {
|
||||||
|
error('You do not have the required permission to delete a user.');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$user = get_record("user", "id", "$delete")) {
|
if (!$user = get_record("user", "id", "$delete")) {
|
||||||
error("No such user!");
|
error("No such user!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue