Temporary patch to get user management pages displaying correctly

This commit is contained in:
Dane Everitt 2019-12-08 11:02:59 -08:00
parent 06e5a05f22
commit c087f6429f
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 32 additions and 119 deletions

View file

@ -3,11 +3,9 @@
namespace Pterodactyl\Services\Users;
use Pterodactyl\Models\User;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Hashing\Hasher;
use Pterodactyl\Traits\Services\HasUserLevels;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Services\DaemonKeys\RevokeMultipleDaemonKeysService;
use Pterodactyl\Repositories\Eloquent\UserRepository;
class UserUpdateService
{
@ -19,44 +17,33 @@ class UserUpdateService
private $hasher;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
* @var \Pterodactyl\Repositories\Eloquent\UserRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\DaemonKeys\RevokeMultipleDaemonKeysService
*/
private $revocationService;
/**
* UpdateService constructor.
*
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
* @param \Pterodactyl\Services\DaemonKeys\RevokeMultipleDaemonKeysService $revocationService
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
* @param \Pterodactyl\Repositories\Eloquent\UserRepository $repository
*/
public function __construct(
Hasher $hasher,
RevokeMultipleDaemonKeysService $revocationService,
UserRepositoryInterface $repository
) {
public function __construct(Hasher $hasher, UserRepository $repository)
{
$this->hasher = $hasher;
$this->repository = $repository;
$this->revocationService = $revocationService;
}
/**
* Update the user model instance. If the user has been removed as an administrator
* revoke all of the authentication tokens that have been assigned to their account.
* Update the user model instance.
*
* @param \Pterodactyl\Models\User $user
* @param array $data
* @return \Illuminate\Support\Collection
* @return \Pterodactyl\Models\User
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle(User $user, array $data): Collection
public function handle(User $user, array $data)
{
if (! empty(array_get($data, 'password'))) {
$data['password'] = $this->hasher->make($data['password']);
@ -64,17 +51,9 @@ class UserUpdateService
unset($data['password']);
}
if ($this->isUserLevel(User::USER_LEVEL_ADMIN)) {
if (array_get($data, 'root_admin', 0) == 0 && $user->root_admin) {
$this->revocationService->handle($user, array_get($data, 'ignore_connection_error', false));
}
} else {
unset($data['root_admin']);
}
/** @var \Pterodactyl\Models\User $response */
$response = $this->repository->update($user->id, $data);
return collect([
'model' => $this->repository->update($user->id, $data),
'exceptions' => $this->revocationService->getExceptions(),
]);
return $response;
}
}