public function deleteAction()
{
$user = User\AbstractUser::getById(intval($this->getParam("id")));
// only admins are allowed to delete admins and folders
// because a folder might contain an admin user, so it is simply not allowed for users with the "users" permission
if ($user instanceof User\Folder && !$this->getUser()->isAdmin() || $user instanceof User && $user->isAdmin() && !$this->getUser()->isAdmin()) {
throw new \Exception("You are not allowed to delete this user");
} else {
if ($user instanceof User\Role\Folder) {
$list = [$user];
$this->populateChildNodes($user, $list, $user instanceof User\Role\Folder);
$listCount = count($list);
for ($i = $listCount - 1; $i >= 0; $i--) {
// iterate over the list from the so that nothing can get "lost"
$user = $list[$i];
$user->delete();
}
} else {
if ($user->getId()) {
$user->delete();
}
}
}
$this->_helper->json(["success" => true]);
}