MDL-13179 - avoid calling get_admin() when unecessary.
It uses a relatively complex query and its not needed except for a minority of users so we may as well avoid it.. merged from MOODLE_19_STABLE
This commit is contained in:
+1
-2
@@ -63,8 +63,7 @@
|
||||
error("No such user!", '', true);
|
||||
}
|
||||
|
||||
$primaryadmin = get_admin();
|
||||
if ($user->id == $primaryadmin->id) {
|
||||
if (is_primary_admin($user->id)) {
|
||||
error("You are not allowed to delete the primary admin user!", '', true);
|
||||
}
|
||||
|
||||
|
||||
@@ -7865,5 +7865,21 @@ function get_plugin_name($plugin, $type='mod') {
|
||||
return $plugin_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a userid the primary administrator?
|
||||
*
|
||||
* @param $userid int id of user to check
|
||||
* @return boolean
|
||||
*/
|
||||
function is_primary_admin($userid){
|
||||
$primaryadmin = get_admin();
|
||||
|
||||
if($userid == $primaryadmin->id){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
|
||||
?>
|
||||
|
||||
+1
-2
@@ -73,8 +73,7 @@
|
||||
print_error('guestnoeditprofileother');
|
||||
}
|
||||
// no editing of primary admin!
|
||||
$mainadmin = get_admin();
|
||||
if ($user->id == $mainadmin->id) {
|
||||
if (is_primary_admin($user->id)) {
|
||||
print_error('adminprimarynoedit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@
|
||||
redirect($CFG->wwwroot . "/user/view.php?id=$id&course={$course->id}");
|
||||
}
|
||||
|
||||
$mainadmin = get_admin();
|
||||
if ($user->id != $USER->id and $user->id == $mainadmin->id) { // Can't edit primary admin
|
||||
if ($user->id != $USER->id and is_primary_admin($user->id)) { // Can't edit primary admin
|
||||
print_error('adminprimarynoedit');
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -95,9 +95,8 @@
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
|
||||
|
||||
/// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
|
||||
|
||||
$mainadmin = get_admin();
|
||||
/// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
|
||||
|
||||
if(empty($CFG->loginhttps)) {
|
||||
$wwwroot = $CFG->wwwroot;
|
||||
@@ -122,11 +121,10 @@
|
||||
$edittype = 'normal';
|
||||
}
|
||||
|
||||
} else if ($user->id != $mainadmin->id) {
|
||||
//no editing of primary admin!
|
||||
if (has_capability('moodle/user:update', $systemcontext)) {
|
||||
} else {
|
||||
if (has_capability('moodle/user:update', $systemcontext) and !is_primary_admin($user->id)){
|
||||
$edittype = 'advanced';
|
||||
} else if (has_capability('moodle/user:editprofile', $personalcontext)) {
|
||||
} else if (has_capability('moodle/user:editprofile', $personalcontext) and !is_primary_admin($user->id)){
|
||||
//teachers, parents, etc.
|
||||
$edittype = 'normal';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user