Skip to content

Commit

Permalink
MDL-13179 - avoid calling get_admin() when unecessary.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
poltawski committed Jan 26, 2008
1 parent 29ee928 commit fc4b2de
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
3 changes: 1 addition & 2 deletions admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 16 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
?>
3 changes: 1 addition & 2 deletions user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
3 changes: 1 addition & 2 deletions user/editadvanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
10 changes: 4 additions & 6 deletions user/tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
}
Expand Down

0 comments on commit fc4b2de

Please sign in to comment.