Skip to content

Commit

Permalink
MDL-23774 deleting of admins is a restricted operation, also external…
Browse files Browse the repository at this point in the history
… lib should not delete the account that is calling it; user pictures are not a problem any more
  • Loading branch information
skodak committed Aug 12, 2010
1 parent 6f4b954 commit b73a28b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions user/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static function delete_users_parameters() {
}

public static function delete_users($userids) {
global $CFG, $DB;
global $CFG, $DB, $USER;
require_once($CFG->dirroot."/user/lib.php");

// Ensure the current user is allowed to run this function
Expand All @@ -209,10 +209,13 @@ public static function delete_users($userids) {
$params = self::validate_parameters(self::delete_users_parameters(), array('userids'=>$userids));

$transaction = $DB->start_delegated_transaction();
// TODO: this is problematic because the DB rollback does not handle rollbacking of deleted user images!

foreach ($params['userids'] as $userid) {
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST);
// must not allow deleting of admins or self!!!
if (is_siteadmin($user) or $USER->id == $user->id) {
throw new moodle_exception('nopermissions', 'error');
}
user_delete_user($user);
}

Expand Down

0 comments on commit b73a28b

Please sign in to comment.