User admin must never be deleted.
323485
private static void truncateUsers(String tableName, Statement ddlStatement, Connection connection) throws SQLException {
    try (PreparedStatement preparedStatement = connection.prepareStatement("delete from users where login <> ?")) {
      preparedStatement.setString(1, "admin");
      preparedStatement.execute();
      // commit is useless on some databases
      connection.commit();
    }
    // "admin" is not flagged as root by default
    try (PreparedStatement preparedStatement = connection.prepareStatement("update users set is_root=?")) {
      preparedStatement.setBoolean(1, false);
      preparedStatement.execute();
      // commit is useless on some databases
      connection.commit();
    }
  }
697838
def delete_user(self, uid=0, user_id=''):
        
        if not uid:
            users = self.get_users()
            users = list(filter(lambda x: x.user_id==str(user_id), users))
            if not users:
                return False
            uid = users[0].uid
        command = const.CMD_DELETE_USER
        command_string = pack('h', uid)
        cmd_response = self.__send_command(command, command_string)
        if not cmd_response.get('status'):
            raise ZKErrorResponse("Can't delete user")
        self.refresh_data()
        if uid == (self.next_uid - 1):
            self.next_uid = uid
232418
def delete_user(username,
                uid=None,
                host=None,
                admin_username=None,
                admin_password=None):
    '''
    
    '''
    if uid is None:
        user = list_users()
        uid = user[username]['index']

    if uid:
        return __execute_cmd('config -g cfgUserAdmin -o '
                             'cfgUserAdminUserName -i {0} ""'.format(uid),
                             host=host, admin_username=admin_username,
                             admin_password=admin_password)

    else:
        log.warning('User \'%s\' does not exist', username)
        return False
149185
def ensure_compatible_admin(view):
    

    def wrapper(request, *args, **kwargs):
        user_roles = request.user.user_data.get('roles', [])
        if len(user_roles) != 1:
            context = {
                'message': 'I need to be able to manage user accounts. '
                           'My username is %s' % request.user.username
            }
            return render(request, 'mtp_common/user_admin/incompatible-admin.html', context=context)
        return view(request, *args, **kwargs)

    return wrapper
27143
def check_role_before_destroy
      if has_role?('Administrator')
        if User.administrators.count == 1
          raise "#{username}: This is the last administrator in this system." if User.administrators.first.username == username
        end
      end
    end
63082
protected function doesCurrentUserHaveAccess()
    {
        // Admins have access by default
        if (Craft::$app->user->getIsAdmin())
        {
            return true;
        }

        // User has the right permission
        if (Craft::$app->user->checkPermission(Patrol::MAINTENANCE_MODE_BYPASS_PERMISSION))
        {
            return true;
        }

        return false;
    }
342673
public boolean deleteUser(String name)
	{
		if (ADMIN_USER_ID.equals(name))
		{
			throw new SystemException(String.format("Cannot delete '%s' user.", ADMIN_USER_ID));
		}

		if (!isUserExist(name))
		{
			throw new SystemException(String.format("User '%s' does not exist.", name));
		}

		allAssociations.remove(name);

		return allUsers.remove(name);
	}
774915
def delete_cluster_admin(self, username):
        """"""
        url = "cluster_admins/{0}".format(username)

        self.request(
            url=url,
            method='DELETE',
            expected_response_code=200
        )

        return True
1172223
public function safeUp()
    {
        $auth = Yii::$app->authManager;

        // rules
        $ruleIsNewsModerator = new IsNewsModeratorRule;
        $auth->add($ruleIsNewsModerator);

        $ruleIsNewsAuthor = new IsNewsAuthorRule;
        $auth->add($ruleIsNewsAuthor);

        $ruleIsNewsOwner = new IsNewsOwnerRule;
        $auth->add($ruleIsNewsOwner);
        
        // roles
        $roleNewsModerator = $auth->createRole($this->roleNewsModerator);
        $roleNewsModerator->ruleName = $ruleIsNewsModerator->name;
        $auth->add($roleNewsModerator);

        $roleNewsAuthor = $auth->createRole($this->roleNewsAuthor);
        $roleNewsAuthor->ruleName = $ruleIsNewsAuthor->name;
        $auth->add($roleNewsAuthor);

      //$auth->addChild($roleNewsModerator, $roleNewsAuthor); //!! no: moderator is not author

        $roleAdmin = $auth->getRole($this->roleAdmin);
        $auth->addChild($roleAdmin, $roleNewsModerator); // system admin is moderator too

        $roleRoot = $auth->getRole($this->roleRoot); // system developer - need all roles by default
        $auth->addChild($roleRoot, $roleNewsAuthor); // root inherit roleNewsModerator from admin

        // permissions
        $createNews = $auth->createPermission('createNews');
        $createNews->description = 'Create news';
        $auth->add($createNews);

        $deleteNews = $auth->createPermission('deleteNews');
        $deleteNews->description = 'Delete news';
        $auth->add($deleteNews);

        $updateNews = $auth->createPermission('updateNews');
        $updateNews->description = 'Update news';
        $auth->add($updateNews);

        $updateOwnNews = $auth->createPermission('updateOwnNews');
        $updateOwnNews->description = 'Update own news';
        $updateOwnNews->ruleName = $ruleIsNewsOwner->name;
        $auth->add($updateOwnNews);

        $auth->addChild($updateOwnNews, $updateNews); //??

        // permissions in roles
        $auth->addChild($roleNewsAuthor, $createNews);
        $auth->addChild($roleNewsAuthor, $updateOwnNews);
        $auth->addChild($roleNewsModerator, $updateNews);
        $auth->addChild($roleNewsModerator, $deleteNews);
    }
683131
def delete_user(self, user):
        
        name = utils.get_name(user)
        self._user_manager.delete(name)
1183498
def manage_admins():
    """"""
    build = g.build

    # Do not show cached data
    db.session.add(build)
    db.session.refresh(build)

    add_form = forms.AddAdminForm()
    if add_form.validate_on_submit():

        invitation_user_id = '%s:%s' % (
            models.User.EMAIL_INVITATION, add_form.email_address.data)

        invitation_user = models.User.query.get(invitation_user_id)
        if not invitation_user:
            invitation_user = models.User(
                id=invitation_user_id,
                email_address=add_form.email_address.data)
            db.session.add(invitation_user)

        db.session.add(build)
        db.session.add(invitation_user)
        db.session.refresh(build, lockmode='update')

        build.owners.append(invitation_user)
        save_admin_log(build, invited_new_admin=True,
                       message=invitation_user.email_address)

        db.session.commit()

        logging.info('Added user=%r as owner to build_id=%r',
                     invitation_user.id, build.id)
        return redirect(url_for('manage_admins', build_id=build.id))

    add_form.build_id.data = build.id

    revoke_form_list = []
    for user in build.owners:
        form = forms.RemoveAdminForm()
        form.user_id.data = user.id
        form.build_id.data = build.id
        form.revoke.data = True
        revoke_form_list.append((user, form))

    return render_template(
        'view_admins.html',
        build=build,
        add_form=add_form,
        revoke_form_list=revoke_form_list)
1226392
public function delete()
    {
        if ($this->id == 0 || $this->id == ADMIN_ID) return FALSE;
		$conn = self::getDbConnection();
		$str = 'DELETE [LOGIN='.$this->login.'][ID='.$this->id.']';
        $conn->executeQuery('DELETE FROM users_groups_membership WHERE user_id='.$this->id);
        $conn->executeQuery('DELETE FROM users_auth WHERE user_id='.$this->id);
        parent::delete();
			
	    Event::trigger(EVENT_CORE_USER_PROP,['message' => $str]);
    }
257059
def deny_user(user):
    """"""
    def processor(action, argument):
        db.session.add(
            ActionUsers.deny(action, argument=argument, user_id=user.id)
        )
    return processor
1334962
function canEdit(item, user) {
        user = user || {};

        if (user.role === 'admin') { return true; }

        var username = user.username || user.name;
        return item && user && (!item.createUsername || item.createUsername === username);
    }
1322338
public boolean canDelete() {
        final IdStrategy strategy = idStrategy();
        return hasPermission(Jenkins.ADMINISTER) && !strategy.equals(id, Jenkins.getAuthentication().getName())
                && UserIdMapper.getInstance().isMapped(id);
    }
1042150
protected function neverObsolete($value)
    {
        // Remove any keys that can never be obsolete
        foreach ($this->config('never_obsolete_keys', []) as $remove) {
            $remove = "{$remove}.";

            if (substr($value, 0, strlen($remove)) === $remove
                || strpos($value, ".{$remove}") !== false
            ) {
                return true;
            }
        }

        return false;
    }
665593
def revoke_admin():
    """"""
    build = g.build
    form = forms.RemoveAdminForm()
    if form.validate_on_submit():
        user = models.User.query.get(form.user_id.data)
        if not user:
            logging.debug('User being revoked admin access does not exist.'
                          'id=%r, build_id=%r', form.user_id.data, build.id)
            abort(400)

        if user == current_user:
            logging.debug('User trying to remove themself as admin. '
                          'id=%r, build_id=%r', user.id, build.id)
            abort(400)

        db.session.add(build)
        db.session.add(user)
        db.session.refresh(build, lockmode='update')
        db.session.refresh(user, lockmode='update')

        user_is_owner = build.owners.filter_by(id=user.id)
        if not user_is_owner:
            logging.debug('User being revoked admin access is not owner. '
                          'id=%r, build_id=%r.', user.id, build.id)
            abort(400)

        build.owners.remove(user)
        save_admin_log(build, revoked_admin=True, message=user.email_address)

        db.session.commit()

        operations.UserOps(user.get_id()).evict()

    return redirect(url_for('manage_admins', build_id=build.id))