38 lines
976 B
PHP
38 lines
976 B
PHP
<?php
|
|
|
|
namespace Pterodactyl\Services\Users;
|
|
|
|
use Pterodactyl\Models\User;
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
use Illuminate\Contracts\Translation\Translator;
|
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
|
|
|
class UserDeletionService
|
|
{
|
|
/**
|
|
* UserDeletionService constructor.
|
|
*/
|
|
public function __construct(
|
|
protected UserRepositoryInterface $repository,
|
|
protected Translator $translator
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Delete a user from the panel only if they have no servers attached to their account.
|
|
*
|
|
* @throws DisplayException
|
|
*/
|
|
public function handle(int|User $user): ?bool
|
|
{
|
|
if (is_int($user)) {
|
|
$user = User::query()->findOrFail($user);
|
|
}
|
|
|
|
if ($user->servers()->count() > 0) {
|
|
throw new DisplayException($this->translator->get('admin/user.exceptions.user_has_servers'));
|
|
}
|
|
|
|
return $this->repository->delete($user);
|
|
}
|
|
}
|